Permalink
Browse files

Merge pull request #1696 from resolve/issue_1673

Fixes #1673
  • Loading branch information...
2 parents d3dcb33 + 806601b commit cef6aa983f08c114aba7f5f41a1e1ad566a6ddc1 @ugisozols ugisozols committed May 25, 2012
@@ -9,6 +9,7 @@ class Activity
# Total number of activies to show for a given class of activity
attr_accessor :limit
+ # Other objects, like parents, to include in the nesting structure
attr_accessor :nested_with
# SQL order by string to specify how to order the activities in the activity feed for
@@ -21,6 +22,10 @@ class Activity
# Image asset to use to represent updated instance of the class thisa activity represents
attr_accessor :updated_image
+ # Boolean; whether or not to use the record itself when constructing the nesting
+ # Default true
+ attr_accessor :use_record_in_nesting
+
# Creates a new instance of Activity for a registered Refinery Plugin. An optional
# hash of options can be specified to customize the values of each attribute
# accessor defined on this class. Each key specified in the options hash should be a
@@ -31,7 +36,8 @@ class Activity
# Activity.new(:limit => 10, :title => "Newest Activity!")
#
# Warning:
- # for the nested_with option, pass in the reverse order of ancestry e.g. [parent.parent_of_parent, parent]
+ # for the nested_with option, pass in the reverse order of ancestry
+ # e.g. [parent.parent_of_parent, parent]
def initialize(options = {})
{
:class_name => nil,
@@ -43,7 +49,8 @@ def initialize(options = {})
:title => "title",
:updated_image => "edit.png",
:url => nil,
- :url_prefix => "edit"
+ :url_prefix => "edit",
+ :use_record_in_nesting => true
}.merge(options).each { |key, value| self.send(:"#{key}=", value) }
end
@@ -80,11 +87,15 @@ def klass
end
# to use in a URL like edit_refinery_admin_group_individuals_path(record.group, record)
- # which will help you if you're using nested routed.
+ # which will help you if you're using nested routes.
def nesting(record_string = "record")
- self.nested_with.inject("") { |nest_chain, nesting|
- nest_chain << "#{record_string}.#{nesting},"
- }
+ @nesting ||= begin
+ chain = self.nested_with.inject([]) { |nest_chain, nesting|
+ nest_chain << "#{record_string}.#{nesting}"
+ }
+ chain << record_string if self.use_record_in_nesting
+ chain.join(',')
+ end
end
attr_writer :url_prefix
@@ -16,7 +16,7 @@ def activity_message_for(record)
:what => record.send(activity.title),
:kind => record.class.model_name.human,
:action => t("with_article \"#{article}\"", :scope => "refinery.#{action}")
- ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")}record)")
+ ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")})")
end
end
@@ -46,5 +46,17 @@
3.times { |n| page.should have_content("Ugisozols#{n} user was added") }
3.times { |n| page.should have_content("Refinery cms #{n} page was added") }
end
+
+ # see https://github.com/resolve/refinerycms/issues/1673
+ it "uses proper link for nested pages" do
+ # we need to increase updated_at because dashboard entries are sorted by
+ # updated_at column and we need this page to be at the top of the list
+ nested = FactoryGirl.create(:page, :parent_id => Refinery::Page.last.id,
+ :updated_at => Time.now + 10.seconds)
+
+ visit refinery.admin_dashboard_path
+
+ page.should have_selector("a[href='#{refinery.edit_admin_page_path(nested.uncached_nested_url)}']")
+ end
end
end
@@ -24,7 +24,11 @@ class Engine < ::Rails::Engine
plugin.name = 'refinery_pages'
plugin.version = %q{2.0.0}
plugin.menu_match = %r{refinery/page(_part|s_dialog)?s$}
- plugin.activity = { :class_name => :'refinery/page' }
+ plugin.activity = {
+ :class_name => :'refinery/page',
+ :nested_with => [:uncached_nested_url],
+ :use_record_in_nesting => false
+ }
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_pages_path }
end
end

0 comments on commit cef6aa9

Please sign in to comment.