Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all uses of wiki.slug in favor of wiki.path, fixes #736 #1101

Merged
merged 5 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def mark_spam_revision
@revision.spam
@revision.author.ban
flash[:notice] = "Item marked as spam and author banned. You can undo this on the <a href='/spam/revisions'>spam moderation page</a>."
redirect_to "/wiki/revisions/<%= @node.slug %>" + '?_=' + Time.now.to_i.to_s
redirect_to "/wiki/revisions/" + @revision.drupal_node.slug_from_path + '?_=' + Time.now.to_i.to_s
else
flash[:notice] = "Item already marked as spam and author banned. You can undo this on the <a href='/spam/revisions'>spam moderation page</a>."
redirect_to "/dashboard"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/talk_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TalkController < ApplicationController
def show
@node = DrupalNode.find_by_slug params[:id]
@node = DrupalNode.find_by_path params[:id]
end
end
4 changes: 2 additions & 2 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def show
end
@tagnames = @tags.collect(&:name)
set_sidebar :tags, @tagnames, {:videos => true}
@wikis = DrupalTag.find_pages(@node.slug,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')
@wikis = DrupalTag.find_pages(@revision.drupal_node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')

@node.view
@revision = @node.latest
Expand Down Expand Up @@ -206,7 +206,7 @@ def revert

# wiki pages which have a root URL, like /about
def root
@node = DrupalNode.find_root_by_slug(params[:id])
@node = DrupalNode.find_by_path(params[:id])
return if check_and_redirect_node(@node)
if @node
@revision = @node.latest
Expand Down
8 changes: 6 additions & 2 deletions app/models/drupal_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def self.inheritance_column
"rails_type"
end

def slug_from_path
self.path.split('/').last
end

before_save :set_changed_and_created
after_create :setup
before_validation :set_path, on: :create
Expand Down Expand Up @@ -320,7 +324,7 @@ def gallery
# base this on a tag!
def is_place?
# self.has_tag('chapter')
self.slug[0..5] == 'place/'
self.path[0..6] == '/wiki/place'
end

# ============================================
Expand Down Expand Up @@ -497,7 +501,7 @@ def edit_path
path
end

def self.find_root_by_slug(title)
def self.find_by_path(title)
DrupalNode.where(path: ["/#{title}"]).first
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/talk/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div><p class="help-text" style="margin-top: 10px;font-family: 'Junction Light';clear:left;"><%= raw t('talk.show.welcome', :page => @node.latest.title, :url1 => @node.path, :url2 => '/wiki/talk-pages') %></p></div>
<div><iframe src="https://pad.publiclab.org/p/<%= @node.slug[0,50] %>" style="width: 100%; height:800px;"><p><%= t('talk.show.try_direct_link', :url1 => 'https://pad.publiclab.org/p/'+@node.slug[0,50]) %></p></iframe></div>
<div><iframe src="https://pad.publiclab.org/p/<%= @revision.drupal_node.slug_from_path[0,50] %>" style="width: 100%; height:800px;"><p><%= t('talk.show.try_direct_link', :url1 => 'https://pad.publiclab.org/p/'+@revision.drupal_node.slug_from_path[0,50]) %></p></iframe></div>
4 changes: 2 additions & 2 deletions app/views/wiki/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h3><%= t('wiki.edit.did_you_mean') %>:</h3>
<ul class="nav bullet">
<% @related[0..5].each do |wiki| %>
<li><a href="/wiki/<%= wiki.slug %>"><i class="fa fa-book"></i> <%= wiki.title %></a></li>
<li><a href="/wiki/<%= wiki.path %>"><i class="fa fa-book"></i> <%= wiki.title %></a></li>
<% end %>
</ul>
<p><i class="fa fa-search"></i> <%= raw t('wiki.edit.try_searching_for', :url1 => "/search/"+params[:id], :wiki => params[:id]) %></p>
Expand All @@ -17,7 +17,7 @@
<ul class="nav nav-list">
<li class="nav-header"><%= t('wiki.edit.more') %></li>
<li><a href="/wiki/getting-started"><%= t('wiki.edit.getting_started') %></a></li>
<% if @node.path %><li><a href="/wiki/revisions/<%= @node.slug %>"><%= t('wiki.edit.revisions_for_this_page') %></a></li><% end %>
<% if @node.path %><li><a href="/wiki/revisions/<%= @revision.drupal_node.slug_from_path %>"><%= t('wiki.edit.revisions_for_this_page') %></a></li><% end %>
<li><a href="/wiki/posting-research"><%= t('wiki.edit.about_posting_research') %></a></li>
<li><a href="/wiki/authoring-help#Advanced+formatting"><%= t('wiki.edit.advanced_formatting') %></a></li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions app/views/wiki/revisions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<h3 id="wiki-title" style="margin-top:0;"><%= raw t('wiki.revisions.revisions_for', :wiki => @node.title) %></h3>

<ul class="nav nav-tabs">
<li><a href="/wiki/<%= @node.slug %>"><%= t('wiki.revisions.view') %></a></li>
<li><a href="/wiki/edit/<%= @node.slug %>"><%= t('wiki.revisions.edit') %></a></li>
<li class="active"><a href="/wiki/revisions/<%= @node.slug %>">Revisions (<%= @node.revisions.length %>)</a></li>
<li><a href="/wiki/<%= @revision.drupal_node.slug_from_path %>"><%= t('wiki.revisions.view') %></a></li>
<li><a href="/wiki/edit/<%= @revision.drupal_node.slug_from_path %>"><%= t('wiki.revisions.edit') %></a></li>
<li class="active"><a href="/wiki/revisions/<%= @revision.drupal_node.slug_from_path %>">Revisions (<%= @node.revisions.length %>)</a></li>
<!--<li class="pull-right"><%= render :partial => "home/social" %></li>-->
</ul>

Expand Down
11 changes: 5 additions & 6 deletions app/views/wiki/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h1 style="font-family: 'Junction Light';"><i class="fa fa-book"></i> <%= @revision.title %> <a onClick="$('#wiki-toolbar').toggle()" class="btn btn-link"><b class="caret"></b></a></h1>

<% if @is_revision %>
<div class="alert alert-warning"><%= raw t('wiki.show.revision_from', :time => @revision.created_at.to_s(:long)) %> <a href="/wiki/revisions/<%= @node.slug %>"><%= t('wiki.show.view_all_revisions') %></a></div>
<div class="alert alert-warning"><%= raw t('wiki.show.revision_from', :time => @revision.created_at.to_s(:long)) %> <a href="/wiki/revisions/<%= @revision.drupal_node.slug_from_path %>"><%= t('wiki.show.view_all_revisions') %></a></div>

<% end %>

Expand All @@ -44,17 +44,16 @@
<li class="active"><a href="#"><span class="hidden-xs"><%= t('wiki.show.view') %></span><span class="visible-xs"><i class="fa fa-file-o"></i></span></a></li>
<li><a href="<%= @node.edit_path %>?t=<%= Time.now.to_i %>"><i class="fa fa-pencil"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.edit') %></span></a></li>
<% if current_user && current_user.role == "admin" %><li><%= link_to "/wiki/delete/"+@node.id.to_s, :confirm => I18n.t('wiki.show.are_you_sure_delete', :path => @node.path) do %><i class="fa fa-trash"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.delete') %></span><% end %></li><% end %>
<li><a href="/talk/<%= @node.slug %>"><i class="fa fa-comments-o"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.talk') %></span></a></li>
<li><a href="/wiki/revisions/<%= @node.slug %>"><span class="hidden-xs"><%= @node.revisions.length %> </span><i class="fa fa-list"></i></a></li>
<li><a href="/talk/<%= @revision.drupal_node.slug_from_path %>"><i class="fa fa-comments-o"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.talk') %></span></a></li>
<li><a href="/wiki/revisions/<%= @revision.drupal_node.slug_from_path %>"><span class="hidden-xs"><%= @node.revisions.length %> </span><i class="fa fa-list"></i></a></li>
</ul>
</div>
</div>

<br />

<% if @node.has_power_tag('parent') %>
<% slug = @node.power_tag('parent') %>
<% parent = DrupalNode.find_by_slug(slug) %>
<% parent = DrupalNode.find_by_path("/wiki/" + @node.power_tag('parent')) %>
<% if parent %>
<div class="alert alert-success" style="border-color:#eee;background:#f8f8f8;color:#aaa;">&laquo; <%= raw t('wiki.show.back_to_wiki', :url1 => parent.path, :title => parent.latest.title) %></a></div>
<% end %>
Expand All @@ -77,7 +76,7 @@
<% if @node.power_tags('tabbed').include?("notes") %>
<div class="tab-pane" id="tab-notes">
<%= render :partial => "notes/notes" %>
<p><a href="/tag/<%= @node.slug %>"><%= raw t('wiki.show.more_research', :tag => @node.slug) %> &raquo;</a></p>
<p><a href="/tag/<%= @revision.drupal_node.slug_from_path %>"><%= raw t('wiki.show.more_research', :tag => @revision.drupal_node.slug_from_path) %> &raquo;</a></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- see how here, we can indeed use @node -- it was only in some contexts where @revision was required, not all. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the errors. @node is fine for all except admin_controller.rb and admin_controller_test.rb.
What should I use in admin_controller.rb and admin_controller_test.rb??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way of testing a part of code and not the whole code locally? Some command instead of rake test:all .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this line in the admin controller test, revision.drupal_node:

https://github.com/publiclab/plots2/blob/master/test/functional/admin_controller_test.rb#L324

And on this line, @revision.drupal_node:

https://github.com/publiclab/plots2/blob/master/app/controllers/admin_controller.rb#L150

Yes, you can run just functional tests with rake test:functionals, units with rake test:units, integration with rake test:integration, and you can even run just one test file with:

ruby -I test test/functional/notes_controller_test.rb (for example)

I know it's time consuming to run them all!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will work on it now!

<br />
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion test/functional/admin_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def teardown
assert_equal 0, revision.status
assert_equal 0, revision.author.status
assert_not_equal node(:spam_targeted_page).latest.vid, revision.vid
assert_redirected_to "/wiki/revisions/<%= @node.slug %>" + '?_=' + Time.now.to_i.to_s
assert_redirected_to "/wiki/revisions/" + @revision.drupal_node.slug_from_path + '?_=' + Time.now.to_i.to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK -- while in the controller, we used an instance variable (starting with @) in the test, we are just using a local variable, so no @ required. Check each changed line to ensure we're using what's available there -- either @node or @revision or node or revision -- and match the usage in that context.

end

test "admin user should be able to republish a revision" do
Expand Down