rails_admin 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rails_admin might be problematic. Click here for more details.
- data/README.md +8 -57
- data/app/assets/stylesheets/rails_admin/base/{README → README.txt} +1 -1
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +4 -2
- data/app/assets/stylesheets/rails_admin/themes/cerulean/theming.css.scss +2 -2
- data/app/helpers/rails_admin/application_helper.rb +22 -28
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +1 -1
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +1 -1
- data/lib/generators/rails_admin/install_generator.rb +4 -3
- data/lib/rails_admin/adapters/mongoid.rb +2 -1
- data/lib/rails_admin/engine.rb +1 -0
- data/lib/rails_admin/version.rb +1 -1
- data/spec/controllers/application_controller_spec.rb +4 -4
- data/spec/controllers/main_controller_spec.rb +26 -26
- data/spec/dummy_app/config/routes.rb +1 -1
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +161818 -0
- data/spec/helpers/application_helper_spec.rb +46 -46
- data/spec/helpers/form_builder_spec.rb +2 -2
- data/spec/integration/authorization/cancan_spec.rb +22 -22
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +6 -6
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +16 -16
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +1 -1
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +6 -6
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +8 -8
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +10 -10
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +16 -16
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +3 -3
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +2 -2
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +1 -2
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +27 -27
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +45 -45
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +35 -38
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
- data/spec/integration/history/rails_admin_history_spec.rb +9 -9
- data/spec/integration/rails_admin_spec.rb +4 -4
- data/spec/integration/relation_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/abstract_model_spec.rb +10 -10
- data/spec/unit/active_record_extension_spec.rb +1 -1
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +24 -24
- data/spec/unit/adapters/active_record_spec.rb +131 -132
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +5 -5
- data/spec/unit/adapters/mongoid_spec.rb +180 -180
- data/spec/unit/config/actions/base_spec.rb +6 -6
- data/spec/unit/config/actions_spec.rb +31 -32
- data/spec/unit/config/fields/base_spec.rb +69 -70
- data/spec/unit/config/fields/date_spec.rb +5 -5
- data/spec/unit/config/fields/datetime_spec.rb +4 -4
- data/spec/unit/config/fields/time_spec.rb +3 -3
- data/spec/unit/config/fields/timestamp_spec.rb +1 -1
- data/spec/unit/config/model_spec.rb +12 -12
- data/spec/unit/config/sections_spec.rb +17 -17
- data/spec/unit/config_spec.rb +23 -24
- data/spec/unit/support/csv_converter_spec.rb +2 -2
- metadata +19 -3
@@ -68,151 +68,151 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'lists associations' do
|
71
|
-
@post.associations.map{|a| a[:name]}.
|
71
|
+
expect(@post.associations.map{|a| a[:name]}).to match_array [:mongo_blog, :mongo_categories, :mongo_comments, :mongo_note]
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'reads correct and know types in [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do
|
75
|
-
(@post.associations + @blog.associations + @user.associations).map{|a|a[:type].to_s}.uniq.
|
75
|
+
expect((@post.associations + @blog.associations + @user.associations).map{|a|a[:type].to_s}.uniq).to match_array ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
|
76
76
|
end
|
77
77
|
|
78
78
|
it "has correct parameter of belongs_to association" do
|
79
79
|
param = @post.associations.find{|a| a[:name] == :mongo_blog}
|
80
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
81
|
-
:name
|
82
|
-
:pretty_name=>"Mongo blog",
|
83
|
-
:type
|
84
|
-
:foreign_key
|
85
|
-
:foreign_type=>nil,
|
86
|
-
:foreign_inverse_of=>nil,
|
87
|
-
:as=>nil,
|
88
|
-
:polymorphic=>false,
|
89
|
-
:inverse_of=>nil,
|
90
|
-
:read_only=>nil,
|
91
|
-
:nested_form=>nil
|
92
|
-
}
|
93
|
-
param[:primary_key_proc].call.
|
94
|
-
param[:model_proc].call.
|
80
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
81
|
+
:name => :mongo_blog,
|
82
|
+
:pretty_name => "Mongo blog",
|
83
|
+
:type => :belongs_to,
|
84
|
+
:foreign_key => :mongo_blog_id,
|
85
|
+
:foreign_type => nil,
|
86
|
+
:foreign_inverse_of => nil,
|
87
|
+
:as => nil,
|
88
|
+
:polymorphic => false,
|
89
|
+
:inverse_of => nil,
|
90
|
+
:read_only => nil,
|
91
|
+
:nested_form => nil
|
92
|
+
})
|
93
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
94
|
+
expect(param[:model_proc].call).to eq(MongoBlog)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "has correct parameter of has_many association" do
|
98
98
|
param = @blog.associations.find{|a| a[:name] == :mongo_posts}
|
99
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
100
|
-
:name
|
101
|
-
:pretty_name=>"Mongo posts",
|
102
|
-
:type
|
103
|
-
:foreign_key
|
104
|
-
:foreign_type=>nil,
|
105
|
-
:foreign_inverse_of=>nil,
|
106
|
-
:as=>nil,
|
107
|
-
:polymorphic=>false,
|
108
|
-
:inverse_of=>nil,
|
109
|
-
:read_only=>nil,
|
110
|
-
:nested_form=>nil
|
111
|
-
}
|
112
|
-
param[:primary_key_proc].call.
|
113
|
-
param[:model_proc].call.
|
114
|
-
@post.properties.find{|f| f[:name] == :mongo_blog_id}[:type].
|
99
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
100
|
+
:name => :mongo_posts,
|
101
|
+
:pretty_name => "Mongo posts",
|
102
|
+
:type => :has_many,
|
103
|
+
:foreign_key => :mongo_blog_id,
|
104
|
+
:foreign_type => nil,
|
105
|
+
:foreign_inverse_of => nil,
|
106
|
+
:as => nil,
|
107
|
+
:polymorphic => false,
|
108
|
+
:inverse_of => nil,
|
109
|
+
:read_only => nil,
|
110
|
+
:nested_form => nil
|
111
|
+
})
|
112
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
113
|
+
expect(param[:model_proc].call).to eq(MongoPost)
|
114
|
+
expect(@post.properties.find{|f| f[:name] == :mongo_blog_id}[:type]).to eq(:bson_object_id)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should not confuse foreign_key column which belongs to associated model" do
|
118
|
-
@blog.properties.find{|f| f[:name] == :mongo_blog_id}[:type].
|
118
|
+
expect(@blog.properties.find{|f| f[:name] == :mongo_blog_id}[:type]).to eq(:string)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "has correct parameter of has_and_belongs_to_many association" do
|
122
122
|
param = @post.associations.find{|a| a[:name] == :mongo_categories}
|
123
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
124
|
-
:name
|
125
|
-
:pretty_name=>"Mongo categories",
|
126
|
-
:type
|
127
|
-
:foreign_key
|
128
|
-
:foreign_type=>nil,
|
129
|
-
:foreign_inverse_of=>nil,
|
130
|
-
:as=>nil,
|
131
|
-
:polymorphic=>false,
|
132
|
-
:inverse_of=>nil,
|
133
|
-
:read_only=>nil,
|
134
|
-
:nested_form=>nil
|
135
|
-
}
|
136
|
-
param[:primary_key_proc].call.
|
137
|
-
param[:model_proc].call.
|
123
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
124
|
+
:name => :mongo_categories,
|
125
|
+
:pretty_name => "Mongo categories",
|
126
|
+
:type => :has_and_belongs_to_many,
|
127
|
+
:foreign_key => :mongo_category_ids,
|
128
|
+
:foreign_type => nil,
|
129
|
+
:foreign_inverse_of => nil,
|
130
|
+
:as => nil,
|
131
|
+
:polymorphic => false,
|
132
|
+
:inverse_of => nil,
|
133
|
+
:read_only => nil,
|
134
|
+
:nested_form => nil
|
135
|
+
})
|
136
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
137
|
+
expect(param[:model_proc].call).to eq(MongoCategory)
|
138
138
|
end
|
139
139
|
|
140
140
|
it "has correct parameter of polymorphic belongs_to association" do
|
141
141
|
RailsAdmin::Config.stub!(:models_pool).and_return(["MongoBlog", "MongoPost", "MongoCategory", "MongoUser", "MongoProfile", "MongoComment"])
|
142
142
|
param = @comment.associations.find{|a| a[:name] == :commentable}
|
143
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
144
|
-
:name
|
145
|
-
:pretty_name=>"Commentable",
|
146
|
-
:type
|
147
|
-
:foreign_key
|
148
|
-
:foreign_type
|
149
|
-
:foreign_inverse_of=>(Mongoid::VERSION >= '3.0.0' ? :commentable_field : nil),
|
150
|
-
:as=>nil,
|
151
|
-
:polymorphic=>true,
|
152
|
-
:inverse_of=>nil,
|
153
|
-
:read_only=>nil,
|
154
|
-
:nested_form=>nil
|
155
|
-
}
|
156
|
-
param[:primary_key_proc].call.
|
157
|
-
param[:model_proc].call.
|
143
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
144
|
+
:name => :commentable,
|
145
|
+
:pretty_name => "Commentable",
|
146
|
+
:type => :belongs_to,
|
147
|
+
:foreign_key => :commentable_id,
|
148
|
+
:foreign_type => :commentable_type,
|
149
|
+
:foreign_inverse_of => (Mongoid::VERSION >= '3.0.0' ? :commentable_field : nil),
|
150
|
+
:as => nil,
|
151
|
+
:polymorphic => true,
|
152
|
+
:inverse_of => nil,
|
153
|
+
:read_only => nil,
|
154
|
+
:nested_form => nil
|
155
|
+
})
|
156
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
157
|
+
expect(param[:model_proc].call).to eq([MongoBlog, MongoPost])
|
158
158
|
end
|
159
159
|
|
160
160
|
it "has correct parameter of polymorphic inverse has_many association" do
|
161
161
|
RailsAdmin::Config.stub!(:models_pool).and_return(["MongoBlog", "MongoPost", "MongoCategory", "MongoUser", "MongoProfile", "MongoComment"])
|
162
162
|
param = @blog.associations.find{|a| a[:name] == :mongo_comments}
|
163
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
164
|
-
:name
|
165
|
-
:pretty_name=>"Mongo comments",
|
166
|
-
:type
|
167
|
-
:foreign_key
|
168
|
-
:foreign_type=>nil,
|
169
|
-
:foreign_inverse_of=>nil,
|
170
|
-
:as
|
171
|
-
:polymorphic=>false,
|
172
|
-
:inverse_of=>nil,
|
173
|
-
:read_only=>nil,
|
174
|
-
:nested_form=>nil
|
175
|
-
}
|
176
|
-
param[:primary_key_proc].call.
|
177
|
-
param[:model_proc].call.
|
163
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
164
|
+
:name => :mongo_comments,
|
165
|
+
:pretty_name => "Mongo comments",
|
166
|
+
:type => :has_many,
|
167
|
+
:foreign_key => :commentable_id,
|
168
|
+
:foreign_type => nil,
|
169
|
+
:foreign_inverse_of => nil,
|
170
|
+
:as => :commentable,
|
171
|
+
:polymorphic => false,
|
172
|
+
:inverse_of => nil,
|
173
|
+
:read_only => nil,
|
174
|
+
:nested_form => nil
|
175
|
+
})
|
176
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
177
|
+
expect(param[:model_proc].call).to eq(MongoComment)
|
178
178
|
end
|
179
179
|
|
180
180
|
it "has correct parameter of embeds_one association" do
|
181
181
|
param = @post.associations.find{|a| a[:name] == :mongo_note}
|
182
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
183
|
-
:name
|
184
|
-
:pretty_name=>"Mongo note",
|
185
|
-
:type
|
186
|
-
:foreign_key=>nil,
|
187
|
-
:foreign_type=>nil,
|
188
|
-
:foreign_inverse_of=>nil,
|
189
|
-
:as=>nil,
|
190
|
-
:polymorphic=>false,
|
191
|
-
:inverse_of=>nil,
|
192
|
-
:read_only=>nil,
|
193
|
-
:nested_form=>{:allow_destroy=>false, :update_only=>false}
|
194
|
-
}
|
195
|
-
param[:primary_key_proc].call.
|
196
|
-
param[:model_proc].call.
|
182
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
183
|
+
:name => :mongo_note,
|
184
|
+
:pretty_name => "Mongo note",
|
185
|
+
:type => :has_one,
|
186
|
+
:foreign_key => nil,
|
187
|
+
:foreign_type => nil,
|
188
|
+
:foreign_inverse_of => nil,
|
189
|
+
:as => nil,
|
190
|
+
:polymorphic => false,
|
191
|
+
:inverse_of => nil,
|
192
|
+
:read_only => nil,
|
193
|
+
:nested_form => {:allow_destroy => false, :update_only => false}
|
194
|
+
})
|
195
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
196
|
+
expect(param[:model_proc].call).to eq(MongoNote)
|
197
197
|
end
|
198
198
|
|
199
199
|
it "has correct parameter of embeds_many association" do
|
200
200
|
param = @user.associations.find{|a| a[:name] == :mongo_notes}
|
201
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
202
|
-
:name
|
203
|
-
:pretty_name=>"Mongo notes",
|
204
|
-
:type
|
205
|
-
:foreign_key=>nil,
|
206
|
-
:foreign_type=>nil,
|
207
|
-
:foreign_inverse_of=>nil,
|
208
|
-
:as=>nil,
|
209
|
-
:polymorphic=>false,
|
210
|
-
:inverse_of=>nil,
|
211
|
-
:read_only=>nil,
|
212
|
-
:nested_form=>{:allow_destroy=>false, :update_only=>false}
|
213
|
-
}
|
214
|
-
param[:primary_key_proc].call.
|
215
|
-
param[:model_proc].call.
|
201
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
202
|
+
:name => :mongo_notes,
|
203
|
+
:pretty_name => "Mongo notes",
|
204
|
+
:type => :has_many,
|
205
|
+
:foreign_key => nil,
|
206
|
+
:foreign_type => nil,
|
207
|
+
:foreign_inverse_of => nil,
|
208
|
+
:as => nil,
|
209
|
+
:polymorphic => false,
|
210
|
+
:inverse_of => nil,
|
211
|
+
:read_only => nil,
|
212
|
+
:nested_form => {:allow_destroy => false, :update_only => false}
|
213
|
+
})
|
214
|
+
expect(param[:primary_key_proc].call).to eq(:_id)
|
215
|
+
expect(param[:model_proc].call).to eq(MongoNote)
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should raise error when embeds_* is used without accepts_nested_attributes_for" do
|
@@ -232,10 +232,10 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
232
232
|
embedded_in :mongo_embeds_many
|
233
233
|
end
|
234
234
|
|
235
|
-
lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsOne).associations }.
|
235
|
+
expect(lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsOne).associations }).to raise_error(RuntimeError,
|
236
236
|
"Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,\nbecause embedded model doesn't have top-level access.\nPlease add `accepts_nested_attributes_for :mongo_embedded' line to `MongoEmbedsOne' model.\n"
|
237
237
|
)
|
238
|
-
lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsMany).associations }.
|
238
|
+
expect(lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsMany).associations }).to raise_error(RuntimeError,
|
239
239
|
"Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,\nbecause embedded model doesn't have top-level access.\nPlease add `accepts_nested_attributes_for :mongo_embeddeds' line to `MongoEmbedsMany' model.\n"
|
240
240
|
)
|
241
241
|
end
|
@@ -254,7 +254,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
254
254
|
|
255
255
|
class MongoEmbedsChild < MongoEmbedsParent; end
|
256
256
|
|
257
|
-
lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsChild).associations }.
|
257
|
+
expect(lambda{ RailsAdmin::AbstractModel.new(MongoEmbedsChild).associations }).not_to raise_error
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
@@ -264,11 +264,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
264
264
|
end
|
265
265
|
|
266
266
|
it "maps Mongoid column types to RA types" do
|
267
|
-
@abstract_model.properties.select{|p| %w(_id _type array_field big_decimal_field
|
267
|
+
expect(@abstract_model.properties.select{|p| %w(_id _type array_field big_decimal_field
|
268
268
|
boolean_field bson_object_id_field date_field datetime_field default_field float_field
|
269
269
|
hash_field integer_field name object_field range_field short_text string_field subject
|
270
270
|
symbol_field text_field time_field title).
|
271
|
-
include? p[:name].to_s}.
|
271
|
+
include? p[:name].to_s}).to match_array [
|
272
272
|
{ :name => :_id,
|
273
273
|
:pretty_name => "Id",
|
274
274
|
:nullable? => true,
|
@@ -404,7 +404,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
404
404
|
field :text, :type => String
|
405
405
|
validates :text, :length => {:maximum => 50}
|
406
406
|
end
|
407
|
-
RailsAdmin::AbstractModel.new('LengthValiated').send(:length_validation_lookup, :text).
|
407
|
+
expect(RailsAdmin::AbstractModel.new('LengthValiated').send(:length_validation_lookup, :text)).to eq(50)
|
408
408
|
end
|
409
409
|
|
410
410
|
it "should not cause problem with custom validators" do
|
@@ -416,7 +416,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
416
416
|
field :text, :type => String
|
417
417
|
validates_with MyCustomValidator
|
418
418
|
end
|
419
|
-
lambda{ RailsAdmin::AbstractModel.new('CustomValiated').send(:length_validation_lookup, :text) }.
|
419
|
+
expect(lambda{ RailsAdmin::AbstractModel.new('CustomValiated').send(:length_validation_lookup, :text) }).not_to raise_error
|
420
420
|
end
|
421
421
|
end
|
422
422
|
|
@@ -427,73 +427,73 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
427
427
|
end
|
428
428
|
|
429
429
|
it "#new returns instance of AbstractObject" do
|
430
|
-
@abstract_model.new.object.
|
430
|
+
expect(@abstract_model.new.object).to be_instance_of(Player)
|
431
431
|
end
|
432
432
|
|
433
433
|
it "#get returns instance of AbstractObject" do
|
434
|
-
@abstract_model.get(@players.first.id.to_s).object.
|
434
|
+
expect(@abstract_model.get(@players.first.id.to_s).object).to eq(@players.first)
|
435
435
|
end
|
436
436
|
|
437
437
|
it "#get returns nil when id does not exist" do
|
438
|
-
@abstract_model.get('4f4f0824dcf2315093000000').
|
438
|
+
expect(@abstract_model.get('4f4f0824dcf2315093000000')).to be_nil
|
439
439
|
end
|
440
440
|
|
441
441
|
it "#first returns a player" do
|
442
|
-
@players.
|
442
|
+
expect(@players).to include @abstract_model.first
|
443
443
|
end
|
444
444
|
|
445
445
|
it "#count returns count of items" do
|
446
|
-
@abstract_model.count.
|
446
|
+
expect(@abstract_model.count).to eq(@players.count)
|
447
447
|
end
|
448
448
|
|
449
449
|
it "#destroy destroys multiple items" do
|
450
450
|
@abstract_model.destroy(@players[0..1])
|
451
|
-
Player.all.
|
451
|
+
expect(Player.all).to eq(@players[2..2])
|
452
452
|
end
|
453
453
|
|
454
454
|
it "#where returns filtered results" do
|
455
|
-
@abstract_model.where(:name => @players.first.name).to_a.
|
455
|
+
expect(@abstract_model.where(:name => @players.first.name).to_a).to eq([@players.first])
|
456
456
|
end
|
457
457
|
|
458
458
|
describe "#all" do
|
459
459
|
it "works without options" do
|
460
|
-
@abstract_model.all.to_a.
|
460
|
+
expect(@abstract_model.all.to_a).to match_array @players
|
461
461
|
end
|
462
462
|
|
463
463
|
it "supports eager loading" do
|
464
|
-
@abstract_model.all(:include => :team).inclusions.map{|i| i.class_name}.
|
464
|
+
expect(@abstract_model.all(:include => :team).inclusions.map{|i| i.class_name}).to eq(["Team"])
|
465
465
|
end
|
466
466
|
|
467
467
|
it "supports limiting" do
|
468
|
-
@abstract_model.all(:limit => 2).to_a.
|
468
|
+
expect(@abstract_model.all(:limit => 2).to_a).to have(2).items
|
469
469
|
end
|
470
470
|
|
471
471
|
it "supports retrieval by bulk_ids" do
|
472
|
-
@abstract_model.all(:bulk_ids => @players[0..1].map{|player| player.id.to_s }).to_a.
|
472
|
+
expect(@abstract_model.all(:bulk_ids => @players[0..1].map{|player| player.id.to_s }).to_a).to match_array @players[0..1]
|
473
473
|
end
|
474
474
|
|
475
475
|
it "supports pagination" do
|
476
|
-
@abstract_model.all(:sort => 'players._id', :page => 2, :per => 1).to_a.
|
476
|
+
expect(@abstract_model.all(:sort => 'players._id', :page => 2, :per => 1).to_a).to eq(@players[1..1])
|
477
477
|
# To prevent RSpec matcher to call Mongoid::Criteria#== method,
|
478
478
|
# (we want to test equality of query result, not of Mongoid criteria)
|
479
479
|
# to_a is added to invoke Mongoid query
|
480
480
|
end
|
481
481
|
|
482
482
|
it "supports ordering" do
|
483
|
-
@abstract_model.all(:sort => 'players._id', :sort_reverse => true).to_a.
|
484
|
-
@abstract_model.all(:sort => 'players._id', :sort_reverse => false).to_a.
|
483
|
+
expect(@abstract_model.all(:sort => 'players._id', :sort_reverse => true).to_a).to eq(@players.sort)
|
484
|
+
expect(@abstract_model.all(:sort => 'players._id', :sort_reverse => false).to_a).to eq(@players.sort.reverse)
|
485
485
|
end
|
486
486
|
|
487
487
|
it "supports querying" do
|
488
|
-
@abstract_model.all(:query => @players[1].name).
|
488
|
+
expect(@abstract_model.all(:query => @players[1].name)).to eq(@players[1..1])
|
489
489
|
end
|
490
490
|
|
491
491
|
it "supports filtering" do
|
492
|
-
@abstract_model.all(:filters => {"name" => {"0000" => {:o=>"is", :v
|
492
|
+
expect(@abstract_model.all(:filters => {"name" => {"0000" => {:o => "is", :v => @players[1].name}}})).to eq(@players[1..1])
|
493
493
|
end
|
494
494
|
|
495
495
|
it "ignores non-existent field name on filtering" do
|
496
|
-
lambda{ @abstract_model.all(:filters => {"dummy" => {"0000" => {:o=>"is", :v
|
496
|
+
expect(lambda{ @abstract_model.all(:filters => {"dummy" => {"0000" => {:o => "is", :v => @players[1].name}}}) }).not_to raise_error
|
497
497
|
end
|
498
498
|
end
|
499
499
|
end
|
@@ -513,11 +513,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
513
513
|
end
|
514
514
|
|
515
515
|
it "supports querying" do
|
516
|
-
@abstract_model.all(:query => 'foobar').to_a.
|
516
|
+
expect(@abstract_model.all(:query => 'foobar').to_a).to eq(@players[1..1])
|
517
517
|
end
|
518
518
|
|
519
519
|
it "supports filtering" do
|
520
|
-
@abstract_model.all(:filters => {"team" => {"0000" => {:o=>"is", :v=>'foobar'}}}).to_a.
|
520
|
+
expect(@abstract_model.all(:filters => {"team" => {"0000" => {:o => "is", :v => 'foobar'}}}).to_a).to eq(@players[1..1])
|
521
521
|
end
|
522
522
|
end
|
523
523
|
|
@@ -537,11 +537,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
537
537
|
end
|
538
538
|
|
539
539
|
it "supports querying" do
|
540
|
-
@abstract_model.all(:query => 'foobar').to_a.
|
540
|
+
expect(@abstract_model.all(:query => 'foobar').to_a).to eq(@teams[1..1])
|
541
541
|
end
|
542
542
|
|
543
543
|
it "supports filtering" do
|
544
|
-
@abstract_model.all(:filters => {"players" => {"0000" => {:o=>"is", :v=>'foobar'}}}).to_a.
|
544
|
+
expect(@abstract_model.all(:filters => {"players" => {"0000" => {:o => "is", :v => 'foobar'}}}).to_a).to eq(@teams[1..1])
|
545
545
|
end
|
546
546
|
end
|
547
547
|
|
@@ -561,11 +561,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
561
561
|
end
|
562
562
|
|
563
563
|
it "supports querying" do
|
564
|
-
@abstract_model.all(:query => 'foobar').to_a.
|
564
|
+
expect(@abstract_model.all(:query => 'foobar').to_a).to eq(@teams[1..1])
|
565
565
|
end
|
566
566
|
|
567
567
|
it "supports filtering" do
|
568
|
-
@abstract_model.all(:filters => {"fans" => {"0000" => {:o=>"is", :v=>'foobar'}}}).to_a.
|
568
|
+
expect(@abstract_model.all(:filters => {"fans" => {"0000" => {:o => "is", :v => 'foobar'}}}).to_a).to eq(@teams[1..1])
|
569
569
|
end
|
570
570
|
end
|
571
571
|
|
@@ -584,11 +584,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
584
584
|
end
|
585
585
|
|
586
586
|
it "supports querying" do
|
587
|
-
@abstract_model.all(:query => 'bar').to_a.
|
587
|
+
expect(@abstract_model.all(:query => 'bar').to_a).to eq(@field_tests[1..1])
|
588
588
|
end
|
589
589
|
|
590
590
|
it "supports filtering" do
|
591
|
-
@abstract_model.all(:filters => {"embeds" => {"0000" => {:o=>"is", :v=>'bar'}}}).to_a.
|
591
|
+
expect(@abstract_model.all(:filters => {"embeds" => {"0000" => {:o => "is", :v => 'bar'}}}).to_a).to eq(@field_tests[1..1])
|
592
592
|
end
|
593
593
|
end
|
594
594
|
end
|
@@ -596,12 +596,12 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
596
596
|
describe "#query_conditions" do
|
597
597
|
before do
|
598
598
|
@abstract_model = RailsAdmin::AbstractModel.new('Player')
|
599
|
-
@players = [{}, {:name=>'Many foos'}, {:position=>'foo shortage'}].
|
599
|
+
@players = [{}, {:name => 'Many foos'}, {:position => 'foo shortage'}].
|
600
600
|
map{|h| FactoryGirl.create :player, h}
|
601
601
|
end
|
602
602
|
|
603
603
|
it "makes conrrect query" do
|
604
|
-
@abstract_model.all(:query => "foo").to_a.
|
604
|
+
expect(@abstract_model.all(:query => "foo").to_a).to match_array @players[1..2]
|
605
605
|
end
|
606
606
|
end
|
607
607
|
|
@@ -609,15 +609,15 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
609
609
|
before do
|
610
610
|
@abstract_model = RailsAdmin::AbstractModel.new('Player')
|
611
611
|
@team = FactoryGirl.create :team, :name => 'king of bar'
|
612
|
-
@players = [{}, {:team
|
612
|
+
@players = [{}, {:team => @team}, {:name => 'Many foos', :team => @team}, {:name => 'Great foo'}].
|
613
613
|
map{|h| FactoryGirl.create :player, h}
|
614
614
|
end
|
615
615
|
|
616
616
|
it "makes conrrect query" do
|
617
|
-
@abstract_model.all(:filters
|
618
|
-
{"name" => {"0000" => {:o=>"like", :v=>"foo"}},
|
619
|
-
"team" => {"0001" => {:o=>"like", :v=>"bar"}}}
|
620
|
-
).
|
617
|
+
expect(@abstract_model.all(:filters =>
|
618
|
+
{"name" => {"0000" => {:o => "like", :v => "foo"}},
|
619
|
+
"team" => {"0001" => {:o => "like", :v => "bar"}}}
|
620
|
+
)).to eq([@players[2]])
|
621
621
|
end
|
622
622
|
end
|
623
623
|
|
@@ -628,87 +628,87 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
628
628
|
|
629
629
|
it "ignores '_discard' operator or value" do
|
630
630
|
[["_discard", ""], ["", "_discard"]].each do |value, operator|
|
631
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
631
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to be_nil
|
632
632
|
end
|
633
633
|
end
|
634
634
|
|
635
635
|
it "supports '_blank' operator" do
|
636
636
|
[["_blank", ""], ["", "_blank"]].each do |value, operator|
|
637
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
637
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => {"$in" => [nil, ""]}})
|
638
638
|
end
|
639
639
|
end
|
640
640
|
|
641
641
|
it "supports '_present' operator" do
|
642
642
|
[["_present", ""], ["", "_present"]].each do |value, operator|
|
643
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
643
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => {"$nin" => [nil, ""]}})
|
644
644
|
end
|
645
645
|
end
|
646
646
|
|
647
647
|
it "supports '_null' operator" do
|
648
648
|
[["_null", ""], ["", "_null"]].each do |value, operator|
|
649
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
649
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => nil})
|
650
650
|
end
|
651
651
|
end
|
652
652
|
|
653
653
|
it "supports '_not_null' operator" do
|
654
654
|
[["_not_null", ""], ["", "_not_null"]].each do |value, operator|
|
655
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
655
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => {"$ne" => nil}})
|
656
656
|
end
|
657
657
|
end
|
658
658
|
|
659
659
|
it "supports '_empty' operator" do
|
660
660
|
[["_empty", ""], ["", "_empty"]].each do |value, operator|
|
661
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
661
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => ""})
|
662
662
|
end
|
663
663
|
end
|
664
664
|
|
665
665
|
it "supports '_not_empty' operator" do
|
666
666
|
[["_not_empty", ""], ["", "_not_empty"]].each do |value, operator|
|
667
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
667
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq({:name => {"$ne" => ""}})
|
668
668
|
end
|
669
669
|
end
|
670
670
|
|
671
671
|
it "supports boolean type query" do
|
672
672
|
['false', 'f', '0'].each do |value|
|
673
|
-
@abstract_model.send(:build_statement, :field, :boolean, value, nil).
|
673
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, value, nil)).to eq({:field => false})
|
674
674
|
end
|
675
675
|
['true', 't', '1'].each do |value|
|
676
|
-
@abstract_model.send(:build_statement, :field, :boolean, value, nil).
|
676
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, value, nil)).to eq({:field => true})
|
677
677
|
end
|
678
|
-
@abstract_model.send(:build_statement, :field, :boolean, 'word', nil).
|
678
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, 'word', nil)).to be_nil
|
679
679
|
end
|
680
680
|
|
681
681
|
it "supports integer type query" do
|
682
|
-
@abstract_model.send(:build_statement, :field, :integer, "1", nil).
|
683
|
-
@abstract_model.send(:build_statement, :field, :integer, 'word', nil).
|
682
|
+
expect(@abstract_model.send(:build_statement, :field, :integer, "1", nil)).to eq({:field => 1})
|
683
|
+
expect(@abstract_model.send(:build_statement, :field, :integer, 'word', nil)).to be_nil
|
684
684
|
end
|
685
685
|
|
686
686
|
it "supports string type query" do
|
687
|
-
@abstract_model.send(:build_statement, :field, :string, "", nil).
|
688
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "was").
|
689
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "default").
|
690
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "like").
|
691
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").
|
692
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").
|
693
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "is").
|
687
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "", nil)).to be_nil
|
688
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "was")).to be_nil
|
689
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "default")).to eq({:field => /foo/i})
|
690
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "like")).to eq({:field => /foo/i})
|
691
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with")).to eq({:field => /^foo/i})
|
692
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with")).to eq({:field => /foo$/i})
|
693
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "is")).to eq({:field => 'foo'})
|
694
694
|
end
|
695
695
|
|
696
696
|
it 'supports date type query' do
|
697
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } }).
|
698
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).
|
699
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).
|
700
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).
|
697
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } })).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,2), "$lte" => Date.new(2012,1,3)}}]})
|
698
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,3)}}]})
|
699
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq({"$and" => [{"date_field" => {"$lte" => Date.new(2012,1,2)}}]})
|
700
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,2), "$lte" => Date.new(2012,1,2)}}]})
|
701
701
|
end
|
702
702
|
|
703
703
|
it 'supports datetime type query' do
|
704
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } ).
|
705
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).
|
706
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).
|
707
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).
|
704
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$gte" => Time.local(2012,1,2), "$lte" => Time.local(2012,1,3).end_of_day}}]})
|
705
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$gte" => Time.local(2012,1,3)}}]})
|
706
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$lte" => Time.local(2012,1,2).end_of_day}}]})
|
707
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq({"$and" => [{"datetime_field" => {"$gte" => Time.local(2012,1,2), "$lte" => Time.local(2012,1,2).end_of_day}}]})
|
708
708
|
end
|
709
709
|
|
710
710
|
it "supports enum type query" do
|
711
|
-
@abstract_model.send(:build_statement, :field, :enum, "1", nil).
|
711
|
+
expect(@abstract_model.send(:build_statement, :field, :enum, "1", nil)).to eq({:field => {"$in" => ["1"]}})
|
712
712
|
end
|
713
713
|
end
|
714
714
|
|
@@ -718,11 +718,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
718
718
|
end
|
719
719
|
|
720
720
|
it "#scoped returns relation object" do
|
721
|
-
@abstract_model.scoped.
|
721
|
+
expect(@abstract_model.scoped).to be_instance_of(Mongoid::Criteria)
|
722
722
|
end
|
723
723
|
|
724
724
|
it "#table_name works" do
|
725
|
-
@abstract_model.table_name.
|
725
|
+
expect(@abstract_model.table_name).to eq('players')
|
726
726
|
end
|
727
727
|
end
|
728
728
|
|
@@ -735,13 +735,13 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
735
735
|
it "accepts array value" do
|
736
736
|
params = {:array_field => '[1, 3]'}
|
737
737
|
@controller.send(:sanitize_params_for!, 'create', @abstract_model.config, params)
|
738
|
-
params[:array_field].
|
738
|
+
expect(params[:array_field]).to eq([1, 3])
|
739
739
|
end
|
740
740
|
|
741
741
|
it "accepts hash value" do
|
742
742
|
params = {:hash_field => '{a: 1, b: 3}'}
|
743
743
|
@controller.send(:sanitize_params_for!, 'create', @abstract_model.config, params)
|
744
|
-
params[:hash_field].
|
744
|
+
expect(params[:hash_field]).to eq({"a" => 1, "b" => 3})
|
745
745
|
end
|
746
746
|
end
|
747
747
|
end
|