Skip to content

Commit

Permalink
Merge 2f128b7 into 51f2c8b
Browse files Browse the repository at this point in the history
  • Loading branch information
akm committed Mar 13, 2013
2 parents 51f2c8b + 2f128b7 commit 8bee982
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rails_admin/adapters/active_record.rb
Expand Up @@ -107,6 +107,10 @@ def embedded?
false
end

def cyclic?
false
end

def adapter_supports_joins?
true
end
Expand Down
4 changes: 4 additions & 0 deletions lib/rails_admin/adapters/mongoid.rb
Expand Up @@ -105,6 +105,10 @@ def embedded?
@embedded ||= !!model.associations.values.find{|a| a.macro.to_sym == :embedded_in }
end

def cyclic?
@cyclic ||= !!model.cyclic?
end

def object_id_from_string(str)
ObjectId.from_string(str)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config.rb
Expand Up @@ -315,7 +315,7 @@ def reset_model(model)
# @see RailsAdmin::Config::Hideable

def visible_models(bindings)
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model) && !m.abstract_model.embedded?}.sort do |a, b|
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model) && (!m.abstract_model.embedded? || m.abstract_model.cyclic?)}.sort do |a, b|
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy_app/app/mongoid/recursively_embeds_many.rb
@@ -0,0 +1,5 @@
class RecursivelyEmbedsMany
include Mongoid::Document

recursively_embeds_many
end
5 changes: 5 additions & 0 deletions spec/dummy_app/app/mongoid/recursively_embeds_one.rb
@@ -0,0 +1,5 @@
class RecursivelyEmbedsOne
include Mongoid::Document

recursively_embeds_many
end
7 changes: 7 additions & 0 deletions spec/rails_admin/config_spec.rb
Expand Up @@ -267,6 +267,13 @@

expect(RailsAdmin.config.visible_models(:controller => double(:_current_user => double(:role => :admin), :authorized? => true)).map(&:abstract_model).map(&:model)).to match_array [FieldTest, Comment]
end

it "basically does not contain embedded model except model using recursively_embeds_many or recursively_embeds_one", :mongoid => true do
RailsAdmin.config do |config|
config.included_models = [FieldTest, Comment, Embed, RecursivelyEmbedsMany, RecursivelyEmbedsOne]
end
expect(RailsAdmin.config.visible_models(:controller => double(:_current_user => double(:role => :admin), :authorized? => true)).map(&:abstract_model).map(&:model)).to match_array [FieldTest, Comment, RecursivelyEmbedsMany, RecursivelyEmbedsOne]
end
end
end

Expand Down

0 comments on commit 8bee982

Please sign in to comment.