Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix to show cyclic embedded models #1565

Merged
merged 1 commit into from

3 participants

@akm

fix to show cyclic embedded models in navigation.

@coveralls

Coverage Status

Coverage remained the same when pulling 2f128b7 on akm:cyclic_embeded_model into 51f2c8b on sferik:master.

@mshibuya mshibuya merged commit b3f081f into sferik:master
@mshibuya mshibuya referenced this pull request from a commit
@mshibuya mshibuya Fix tests broken by #1565 de2b949
@mshibuya
Collaborator

This caused some spec failures, though I could easily fix them.
Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2013
  1. @akm
This page is out of date. Refresh to see the latest.
View
4 lib/rails_admin/adapters/active_record.rb
@@ -107,6 +107,10 @@ def embedded?
false
end
+ def cyclic?
+ false
+ end
+
def adapter_supports_joins?
true
end
View
4 lib/rails_admin/adapters/mongoid.rb
@@ -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
View
2  lib/rails_admin/config.rb
@@ -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
View
5 spec/dummy_app/app/mongoid/recursively_embeds_many.rb
@@ -0,0 +1,5 @@
+class RecursivelyEmbedsMany
+ include Mongoid::Document
+
+ recursively_embeds_many
+end
View
5 spec/dummy_app/app/mongoid/recursively_embeds_one.rb
@@ -0,0 +1,5 @@
+class RecursivelyEmbedsOne
+ include Mongoid::Document
+
+ recursively_embeds_many
+end
View
7 spec/rails_admin/config_spec.rb
@@ -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
Something went wrong with that request. Please try again.