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.

Files changed (55) hide show
  1. data/README.md +8 -57
  2. data/app/assets/stylesheets/rails_admin/base/{README → README.txt} +1 -1
  3. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +4 -2
  4. data/app/assets/stylesheets/rails_admin/themes/cerulean/theming.css.scss +2 -2
  5. data/app/helpers/rails_admin/application_helper.rb +22 -28
  6. data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +1 -1
  7. data/app/views/rails_admin/main/_form_filtering_select.html.haml +1 -1
  8. data/lib/generators/rails_admin/install_generator.rb +4 -3
  9. data/lib/rails_admin/adapters/mongoid.rb +2 -1
  10. data/lib/rails_admin/engine.rb +1 -0
  11. data/lib/rails_admin/version.rb +1 -1
  12. data/spec/controllers/application_controller_spec.rb +4 -4
  13. data/spec/controllers/main_controller_spec.rb +26 -26
  14. data/spec/dummy_app/config/routes.rb +1 -1
  15. data/spec/dummy_app/db/test.sqlite3 +0 -0
  16. data/spec/dummy_app/log/test.log +161818 -0
  17. data/spec/helpers/application_helper_spec.rb +46 -46
  18. data/spec/helpers/form_builder_spec.rb +2 -2
  19. data/spec/integration/authorization/cancan_spec.rb +22 -22
  20. data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +6 -6
  21. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +16 -16
  22. data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +1 -1
  23. data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +6 -6
  24. data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +8 -8
  25. data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +10 -10
  26. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +16 -16
  27. data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +3 -3
  28. data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +2 -2
  29. data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +1 -2
  30. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +27 -27
  31. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +45 -45
  32. data/spec/integration/config/list/rails_admin_config_list_spec.rb +35 -38
  33. data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
  34. data/spec/integration/history/rails_admin_history_spec.rb +9 -9
  35. data/spec/integration/rails_admin_spec.rb +4 -4
  36. data/spec/integration/relation_spec.rb +3 -3
  37. data/spec/spec_helper.rb +3 -1
  38. data/spec/unit/abstract_model_spec.rb +10 -10
  39. data/spec/unit/active_record_extension_spec.rb +1 -1
  40. data/spec/unit/adapters/active_record/abstract_object_spec.rb +24 -24
  41. data/spec/unit/adapters/active_record_spec.rb +131 -132
  42. data/spec/unit/adapters/mongoid/abstract_object_spec.rb +5 -5
  43. data/spec/unit/adapters/mongoid_spec.rb +180 -180
  44. data/spec/unit/config/actions/base_spec.rb +6 -6
  45. data/spec/unit/config/actions_spec.rb +31 -32
  46. data/spec/unit/config/fields/base_spec.rb +69 -70
  47. data/spec/unit/config/fields/date_spec.rb +5 -5
  48. data/spec/unit/config/fields/datetime_spec.rb +4 -4
  49. data/spec/unit/config/fields/time_spec.rb +3 -3
  50. data/spec/unit/config/fields/timestamp_spec.rb +1 -1
  51. data/spec/unit/config/model_spec.rb +12 -12
  52. data/spec/unit/config/sections_spec.rb +17 -17
  53. data/spec/unit/config_spec.rb +23 -24
  54. data/spec/unit/support/csv_converter_spec.rb +2 -2
  55. 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]}.should =~ [:mongo_blog, :mongo_categories, :mongo_comments, :mongo_note]
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.should =~ ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
94
- param[:model_proc].call.should == MongoBlog
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
113
- param[:model_proc].call.should == MongoPost
114
- @post.properties.find{|f| f[:name] == :mongo_blog_id}[:type].should == :bson_object_id
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].should == :string
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
137
- param[:model_proc].call.should == MongoCategory
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
157
- param[:model_proc].call.should == [MongoBlog, MongoPost]
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
177
- param[:model_proc].call.should == MongoComment
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
196
- param[:model_proc].call.should == MongoNote
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 }.should == {
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
- param[:primary_key_proc].call.should == :_id
215
- param[:model_proc].call.should == MongoNote
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 }.should raise_error(RuntimeError,
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 }.should raise_error(RuntimeError,
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 }.should_not raise_error
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}.should =~ [
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).should == 50
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) }.should_not raise_error
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.should be_instance_of(Player)
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.should == @players.first
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').should be_nil
438
+ expect(@abstract_model.get('4f4f0824dcf2315093000000')).to be_nil
439
439
  end
440
440
 
441
441
  it "#first returns a player" do
442
- @players.should include @abstract_model.first
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.should == @players.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.should == @players[2..2]
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.should == [@players.first]
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.should =~ @players
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}.should == ["Team"]
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.should have(2).items
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.should =~ @players[0..1]
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.should == @players[1..1]
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.should == @players.sort
484
- @abstract_model.all(:sort => 'players._id', :sort_reverse => false).to_a.should == @players.sort.reverse
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).should == @players[1..1]
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=>@players[1].name}}}).should == @players[1..1]
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=>@players[1].name}}}) }.should_not raise_error
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.should == @players[1..1]
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.should == @players[1..1]
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.should == @teams[1..1]
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.should == @teams[1..1]
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.should == @teams[1..1]
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.should == @teams[1..1]
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.should == @field_tests[1..1]
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.should == @field_tests[1..1]
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.should =~ @players[1..2]
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=>@team}, {:name=>'Many foos', :team=>@team}, {:name=>'Great foo'}].
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
- ).should == [@players[2]]
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).should be_nil
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).should == {:name=>{"$in"=>[nil, ""]}}
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).should == {:name=>{"$nin"=>[nil, ""]}}
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).should == {:name=>nil}
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).should == {:name=>{"$ne"=>nil}}
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).should == {:name=>""}
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).should == {:name=>{"$ne"=>""}}
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).should == {:field => false}
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).should == {:field => true}
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).should be_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).should == {:field => 1}
683
- @abstract_model.send(:build_statement, :field, :integer, 'word', nil).should be_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).should be_nil
688
- @abstract_model.send(:build_statement, :field, :string, "foo", "was").should be_nil
689
- @abstract_model.send(:build_statement, :field, :string, "foo", "default").should == {:field=>/foo/i}
690
- @abstract_model.send(:build_statement, :field, :string, "foo", "like").should == {:field=>/foo/i}
691
- @abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == {:field=>/^foo/i}
692
- @abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == {:field=>/foo$/i}
693
- @abstract_model.send(:build_statement, :field, :string, "foo", "is").should == {:field=>'foo'}
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' } } }).should == {"$and"=>[{"date_field"=>{"$gte"=>Date.new(2012,1,2), "$lte"=>Date.new(2012,1,3)}}]}
698
- @abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).should == {"$and"=>[{"date_field"=>{"$gte"=>Date.new(2012,1,3)}}]}
699
- @abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).should == {"$and"=>[{"date_field"=>{"$lte"=>Date.new(2012,1,2)}}]}
700
- @abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).should == {"$and"=>[{"date_field"=>{"$gte"=>Date.new(2012,1,2), "$lte"=>Date.new(2012,1,2)}}]}
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' } } } ).should == {"$and"=>[{"datetime_field"=>{"$gte"=>Time.local(2012,1,2), "$lte"=>Time.local(2012,1,3).end_of_day}}]}
705
- @abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).should == {"$and"=>[{"datetime_field"=>{"$gte"=>Time.local(2012,1,3)}}]}
706
- @abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).should == {"$and"=>[{"datetime_field"=>{"$lte"=>Time.local(2012,1,2).end_of_day}}]}
707
- @abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).should == {"$and"=>[{"datetime_field"=>{"$gte"=>Time.local(2012,1,2), "$lte"=>Time.local(2012,1,2).end_of_day}}]}
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).should == {:field => {"$in" => ["1"]}}
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.should be_instance_of(Mongoid::Criteria)
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.should == 'players'
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].should == [1, 3]
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].should == {"a"=>1, "b"=>3}
744
+ expect(params[:hash_field]).to eq({"a" => 1, "b" => 3})
745
745
  end
746
746
  end
747
747
  end