Skip to content

Commit

Permalink
Merge pull request #1696 from resolve/issue_1673
Browse files Browse the repository at this point in the history
Fixes #1673
  • Loading branch information
ugisozols committed May 25, 2012
2 parents d3dcb33 + 806601b commit cef6aa9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
23 changes: 17 additions & 6 deletions core/lib/refinery/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/helpers/refinery/admin/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions dashboard/spec/requests/refinery/admin/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion pages/lib/refinery/pages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cef6aa9

Please sign in to comment.