obitum-rails_admin 0.0.3 → 0.0.4

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.
Files changed (43) hide show
  1. data/Gemfile +3 -0
  2. data/README.md +19 -69
  3. data/Rakefile +6 -1
  4. data/app/assets/javascripts/rails_admin/rails_admin.js.erb +10 -5
  5. data/app/controllers/rails_admin/main_controller.rb +9 -7
  6. data/config/initializers/mongoid_extensions.rb +4 -0
  7. data/lib/rails_admin/abstract_model.rb +55 -1
  8. data/lib/rails_admin/adapters/active_record.rb +20 -38
  9. data/lib/rails_admin/adapters/mongoid.rb +333 -0
  10. data/lib/rails_admin/adapters/mongoid/abstract_object.rb +32 -0
  11. data/lib/rails_admin/adapters/mongoid/extension.rb +27 -0
  12. data/lib/rails_admin/config/fields/base.rb +4 -4
  13. data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +5 -2
  14. data/lib/rails_admin/config/fields/factories/serialized.rb +1 -1
  15. data/lib/rails_admin/config/fields/types.rb +2 -1
  16. data/lib/rails_admin/config/fields/types/all.rb +2 -0
  17. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +1 -1
  18. data/lib/rails_admin/config/fields/types/bson_object_id.rb +42 -0
  19. data/lib/rails_admin/config/fields/types/enum.rb +2 -2
  20. data/lib/rails_admin/config/fields/types/mongoid_type.rb +25 -0
  21. data/lib/rails_admin/config/fields/types/polymorphic_association.rb +1 -1
  22. data/lib/rails_admin/config/fields/types/serialized.rb +1 -1
  23. data/lib/rails_admin/engine.rb +1 -0
  24. data/lib/rails_admin/version.rb +1 -1
  25. data/spec/dummy_app/Gemfile +2 -0
  26. data/spec/dummy_app/app/models/article.rb +9 -0
  27. data/spec/dummy_app/app/models/author.rb +6 -0
  28. data/spec/dummy_app/app/models/mongoid_field_test.rb +22 -0
  29. data/spec/dummy_app/app/models/tag.rb +7 -0
  30. data/spec/dummy_app/config/environments/development.rb +2 -2
  31. data/spec/dummy_app/config/mongoid.yml +17 -0
  32. data/spec/dummy_app/db/seeds.rb +7 -7
  33. data/spec/factories.rb +23 -0
  34. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +13 -0
  35. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +28 -0
  36. data/spec/spec_helper.rb +13 -0
  37. data/spec/support/tableless.rb +27 -0
  38. data/spec/unit/adapters/active_record_spec.rb +335 -37
  39. data/spec/unit/adapters/mongoid/abstract_object_spec.rb +30 -0
  40. data/spec/unit/adapters/mongoid_spec.rb +581 -0
  41. data/spec/unit/config/fields/base_spec.rb +9 -0
  42. metadata +280 -44
  43. data/app/assets/javascripts/rails_admin/jquery-ui-1.8.16.custom.js +0 -5271
@@ -154,6 +154,34 @@ describe "RailsAdmin Basic Update" do
154
154
  end
155
155
  end
156
156
 
157
+ describe "update with serialized objects of Mongoid" do
158
+ before(:each) do
159
+ @field_test = FactoryGirl.create :mongoid_field_test
160
+
161
+ visit edit_path(:model_name => "mongoid_field_test", :id => @field_test.id)
162
+ end
163
+
164
+ it "should save the serialized data" do
165
+ fill_in "mongoid_field_test[array_field]", :with => "[4, 2]"
166
+ fill_in "mongoid_field_test[hash_field]", :with => "{ a: 6, b: 2 }"
167
+ click_button "Save"
168
+
169
+ @field_test.reload
170
+ @field_test.array_field.should eql([4, 2])
171
+ @field_test.hash_field.should eql({ "a" => 6, "b" => 2 })
172
+ end
173
+
174
+ it "should clear data when empty string is passed" do
175
+ fill_in "mongoid_field_test[array_field]", :with => ""
176
+ fill_in "mongoid_field_test[hash_field]", :with => ""
177
+ click_button "Save"
178
+
179
+ @field_test.reload
180
+ @field_test.array_field.should eql(nil)
181
+ @field_test.hash_field.should eql(nil)
182
+ end
183
+ end
184
+
157
185
  describe "update with overridden to_param" do
158
186
  before(:each) do
159
187
  @ball = FactoryGirl.create :ball
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,19 @@
1
1
  # Configure Rails Envinronment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
  ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'true'
4
+
5
+ if ENV['INVOKE_SIMPLECOV']
6
+ require 'simplecov'
7
+ SimpleCov.start 'rails'
8
+ end
9
+
4
10
  require File.expand_path('../dummy_app/config/environment', __FILE__)
5
11
 
6
12
  require 'rspec/rails'
7
13
  require 'factory_girl'
8
14
  require 'factories'
9
15
  require 'database_helpers'
16
+ require 'support/tableless'
10
17
 
11
18
  ActionMailer::Base.delivery_method = :test
12
19
  ActionMailer::Base.perform_deliveries = true
@@ -61,6 +68,10 @@ RSpec.configure do |config|
61
68
  Team.delete_all
62
69
  User.delete_all
63
70
  FieldTest.delete_all
71
+ Author.delete_all
72
+ Article.delete_all
73
+ MongoidFieldTest.delete_all
74
+ Tag.delete_all
64
75
  login_as User.create(
65
76
  :email => "username@example.com",
66
77
  :password => "password"
@@ -70,4 +81,6 @@ RSpec.configure do |config|
70
81
  config.after(:each) do
71
82
  Warden.test_reset!
72
83
  end
84
+
85
+ config.seed = ENV['SEED'] if ENV['SEED']
73
86
  end
@@ -0,0 +1,27 @@
1
+ class Tableless < ActiveRecord::Base
2
+ def self.columns
3
+ @columns ||= [];
4
+ end
5
+
6
+ def self.column(name, sql_type = nil, default = nil, null = true)
7
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
8
+ sql_type.to_s, null)
9
+ end
10
+
11
+ def self.columns_hash
12
+ @columns_hash ||= Hash[columns.map { |column| [column.name, column] }]
13
+ end
14
+
15
+ def self.column_names
16
+ @column_names ||= columns.map { |column| column.name }
17
+ end
18
+
19
+ def self.column_defaults
20
+ @column_defaults ||= columns.map { |column| [column.name, nil] }.inject({}) { |m, e| m[e[0]] = e[1]; m }
21
+ end
22
+
23
+ # Override the save method to prevent exceptions.
24
+ def save(validate = true)
25
+ validate ? valid? : true
26
+ end
27
+ end
@@ -1,75 +1,373 @@
1
1
  require 'spec_helper'
2
+ require 'timecop'
2
3
  require 'rails_admin/adapters/active_record'
3
4
 
4
5
 
5
6
  describe RailsAdmin::Adapters::ActiveRecord do
7
+ before do
8
+ @like = ::ActiveRecord::Base.configurations[Rails.env]['adapter'] == "postgresql" ? 'ILIKE' : 'LIKE'
9
+ end
10
+
11
+ describe '#associations' do
12
+ before :all do
13
+ RailsAdmin::AbstractModel.reset_polymorphic_parents
14
+
15
+ class ARBlog < ActiveRecord::Base
16
+ has_many :a_r_posts
17
+ has_many :a_r_comments, :as => :commentable
18
+ end
19
+
20
+ class ARPost < ActiveRecord::Base
21
+ belongs_to :a_r_blog
22
+ has_and_belongs_to_many :a_r_categories
23
+ has_many :a_r_comments, :as => :commentable
24
+ end
6
25
 
7
- before :all do
26
+ class ARCategory < ActiveRecord::Base
27
+ has_and_belongs_to_many :a_r_posts
28
+ end
8
29
 
9
- class ARBlog < ActiveRecord::Base
10
- has_many :a_r_posts
11
- has_many :a_r_comments, :as => :commentable
30
+ class ARUser < ActiveRecord::Base
31
+ has_one :a_r_profile
32
+ end
33
+
34
+ class ARProfile < ActiveRecord::Base
35
+ belongs_to :a_r_user
36
+ end
37
+
38
+ class ARComment < ActiveRecord::Base
39
+ belongs_to :commentable, :polymorphic => true
40
+ end
41
+
42
+ @blog = RailsAdmin::AbstractModel.new(ARBlog)
43
+ @post = RailsAdmin::AbstractModel.new(ARPost)
44
+ @category = RailsAdmin::AbstractModel.new(ARCategory)
45
+ @user = RailsAdmin::AbstractModel.new(ARUser)
46
+ @profile = RailsAdmin::AbstractModel.new(ARProfile)
47
+ @comment = RailsAdmin::AbstractModel.new(ARComment)
12
48
  end
13
49
 
14
- class ARPost < ActiveRecord::Base
15
- belongs_to :a_r_blog
16
- has_and_belongs_to_many :a_r_categories
17
- has_many :a_r_comments, :as => :commentable
50
+ after :all do
51
+ RailsAdmin::AbstractModel.reset_polymorphic_parents
18
52
  end
19
53
 
20
- class ARCategory < ActiveRecord::Base
21
- has_and_belongs_to_many :a_r_posts
54
+ it 'lists associations' do
55
+ @post.associations.map{|a|a[:name].to_s}.sort.should == ['a_r_blog', 'a_r_categories', 'a_r_comments']
56
+ end
57
+
58
+ it 'list associations types in supported [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do
59
+ (@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.map(&:to_s).sort.should == ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
60
+ end
61
+
62
+ it "has correct parameter of belongs_to association" do
63
+ param = @post.associations.select{|a| a[:name] == :a_r_blog}.first
64
+ param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.should == {
65
+ :name=>:a_r_blog,
66
+ :pretty_name=>"A r blog",
67
+ :type=>:belongs_to,
68
+ :foreign_key=>:a_r_blog_id,
69
+ :foreign_type=>nil,
70
+ :as=>nil,
71
+ :polymorphic=>false,
72
+ :inverse_of=>nil,
73
+ :read_only=>nil,
74
+ :nested_form=>nil
75
+ }
76
+ param[:primary_key_proc].call.should == 'id'
77
+ param[:model_proc].call.should == ARBlog
22
78
  end
23
79
 
24
- class ARUser < ActiveRecord::Base
25
- has_one :a_r_profile
80
+ it "has correct parameter of has_many association" do
81
+ param = @blog.associations.select{|a| a[:name] == :a_r_posts}.first
82
+ param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.should == {
83
+ :name=>:a_r_posts,
84
+ :pretty_name=>"A r posts",
85
+ :type=>:has_many,
86
+ :foreign_key=>:ar_blog_id,
87
+ :foreign_type=>nil,
88
+ :as=>nil,
89
+ :polymorphic=>false,
90
+ :inverse_of=>nil,
91
+ :read_only=>nil,
92
+ :nested_form=>nil
93
+ }
94
+ param[:primary_key_proc].call.should == 'id'
95
+ param[:model_proc].call.should == ARPost
26
96
  end
27
97
 
28
- class ARProfile < ActiveRecord::Base
29
- belongs_to :a_r_user
98
+ it "has correct parameter of has_and_belongs_to_many association" do
99
+ param = @post.associations.select{|a| a[:name] == :a_r_categories}.first
100
+ param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.should == {
101
+ :name=>:a_r_categories,
102
+ :pretty_name=>"A r categories",
103
+ :type=>:has_and_belongs_to_many,
104
+ :foreign_key=>:ar_post_id,
105
+ :foreign_type=>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 == ARCategory
30
114
  end
31
115
 
32
- class ARComment < ActiveRecord::Base
33
- belongs_to :commentable, :polymorphic => true
116
+ it "has correct parameter of polymorphic belongs_to association" do
117
+ RailsAdmin::Config.stub!(:models_pool).and_return(["ARBlog", "ARPost", "ARCategory", "ARUser", "ARProfile", "ARComment"])
118
+ param = @comment.associations.select{|a| a[:name] == :commentable}.first
119
+ param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.should == {
120
+ :name=>:commentable,
121
+ :pretty_name=>"Commentable",
122
+ :type=>:belongs_to,
123
+ :foreign_key=>:commentable_id,
124
+ :foreign_type=>:commentable_type,
125
+ :as=>nil,
126
+ :polymorphic=>true,
127
+ :inverse_of=>nil,
128
+ :read_only=>nil,
129
+ :nested_form=>nil
130
+ }
131
+ # param[:primary_key_proc].call.should == 'id' Should not be called for polymorphic relations. Todo, Handle this niver
132
+ param[:model_proc].call.should == [ARBlog, ARPost]
34
133
  end
35
134
 
36
- @blog = RailsAdmin::AbstractModel.new(ARBlog)
37
- @post = RailsAdmin::AbstractModel.new(ARPost)
38
- @category = RailsAdmin::AbstractModel.new(ARCategory)
39
- @user = RailsAdmin::AbstractModel.new(ARUser)
40
- @profile = RailsAdmin::AbstractModel.new(ARProfile)
41
- @comment = RailsAdmin::AbstractModel.new(ARComment)
135
+ it "has correct parameter of polymorphic inverse has_many association" do
136
+ param = @blog.associations.select{|a| a[:name] == :a_r_comments}.first
137
+ param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.should == {
138
+ :name=>:a_r_comments,
139
+ :pretty_name=>"A r comments",
140
+ :type=>:has_many,
141
+ :foreign_key=>:commentable_id,
142
+ :foreign_type=>nil,
143
+ :as=>:commentable,
144
+ :polymorphic=>false,
145
+ :inverse_of=>nil,
146
+ :read_only=>nil,
147
+ :nested_form=>nil
148
+ }
149
+ param[:primary_key_proc].call.should == 'id'
150
+ param[:model_proc].call.should == ARComment
151
+ end
42
152
  end
43
153
 
44
154
 
45
- describe '#associations' do
46
- it 'lists associations' do
47
- @post.associations.map{|a|a[:name].to_s}.sort.should == ['a_r_blog', 'a_r_categories', 'a_r_comments']
155
+ describe "#properties" do
156
+ before do
157
+ @abstract_model = RailsAdmin::AbstractModel.new('Player')
48
158
  end
49
159
 
50
- it 'list associations types in supported [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do
51
- (@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.map(&:to_s).sort.should == ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
160
+ it "returns parameters of string-type field" do
161
+ @abstract_model.properties.select{|f| f[:name] == :name}.should ==
162
+ [{:name => :name, :pretty_name => "Name", :type => :string, :length => 100, :nullable? => false, :serial? => false}]
52
163
  end
53
164
  end
54
-
55
-
56
- describe '#all' do
165
+
166
+ describe "data access method" do
167
+ before do
168
+ @players = FactoryGirl.create_list(:player, 3)
169
+ @abstract_model = RailsAdmin::AbstractModel.new('Player')
170
+ end
171
+
172
+ it "#new returns instance of AbstractObject" do
173
+ @abstract_model.new.object.should be_instance_of(Player)
174
+ end
175
+
176
+ it "#get returns instance of AbstractObject" do
177
+ @abstract_model.get(@players.first.id).object.should == @players.first
178
+ end
179
+
180
+ it "#get returns nil when id does not exist" do
181
+ @abstract_model.get('abc').should be_nil
182
+ end
183
+
184
+ it "#first returns first item" do
185
+ @abstract_model.first.should == @players.first
186
+ end
187
+
188
+ it "#count returns count of items" do
189
+ @abstract_model.count.should == @players.count
190
+ end
191
+
192
+ it "#destroy destroys multiple items" do
193
+ @abstract_model.destroy(@players[0..1])
194
+ Player.all.should == @players[2..2]
195
+ end
196
+
197
+ describe "#all" do
198
+ it "works without options" do
199
+ @abstract_model.all.sort.should == @players.sort
200
+ end
201
+
202
+ it "supports eager loading" do
203
+ @abstract_model.all(:include => :team).includes_values.should == [:team]
204
+ end
205
+
206
+ it "supports limiting" do
207
+ @abstract_model.all(:limit => 2).count.should == 2
208
+ end
209
+
210
+ it "supports retrieval by bulk_ids" do
211
+ @abstract_model.all(:bulk_ids => @players[0..1].map{|player| player.id }).
212
+ sort.should == @players[0..1].sort
213
+ end
214
+
215
+ it "supports pagination" do
216
+ @abstract_model.all(:page => 2, :per => 1).should == @players[1..1]
217
+ end
218
+
219
+ it "supports ordering" do
220
+ @abstract_model.all(:sort => "id", :sort_reverse => true).should == @players.sort
221
+ end
222
+
223
+ it "supports querying" do
224
+ @abstract_model.all(:query => @players[1].name).should == @players[1..1]
225
+ end
226
+
227
+ it "supports filtering" do
228
+ @abstract_model.all(:filters => {"name" => {"0000" => {:o=>"is", :v=>@players[1].name}}}).should == @players[1..1]
229
+ end
230
+ end
231
+ end
232
+
233
+ describe "#query_conditions" do
234
+ before do
235
+ @abstract_model = RailsAdmin::AbstractModel.new('Team')
236
+ @teams = [{}, {:name=>'somewhere foos'}, {:manager=>'foo junior'}].
237
+ map{|h| FactoryGirl.create :team, h}
238
+ end
239
+
240
+ it "makes conrrect query" do
241
+ @abstract_model.all(:query => "foo").sort.should == @teams[1..2]
242
+ end
243
+ end
244
+
245
+ describe "#filter_conditions" do
246
+ before do
247
+ @abstract_model = RailsAdmin::AbstractModel.new('Team')
248
+ @division = FactoryGirl.create :division, :name => 'bar division'
249
+ @teams = [{}, {:division=>@division}, {:name=>'somewhere foos', :division=>@division}, {:name=>'nowhere foos'}].
250
+ map{|h| FactoryGirl.create :team, h}
251
+ end
252
+
253
+ it "makes conrrect query" do
254
+ @abstract_model.all(
255
+ :filters => {"name" => {"0000" => {:o=>"like", :v=>"foo"}},
256
+ "division" => {"0001" => {:o=>"like", :v=>"bar"}}},
257
+ :include => :division
258
+ ).should == [@teams[2]]
259
+ end
260
+ end
261
+
262
+ describe "#build_statement" do
263
+ before do
264
+ @abstract_model = RailsAdmin::AbstractModel.new('FieldTest')
265
+ end
266
+
267
+ it "ignores '_discard' operator or value" do
268
+ [["_discard", ""], ["", "_discard"]].each do |value, operator|
269
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should be_nil
270
+ end
271
+ end
272
+
273
+ it "supports '_blank' operator" do
274
+ [["_blank", ""], ["", "_blank"]].each do |value, operator|
275
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name IS NULL OR name = '')"]
276
+ end
277
+ end
278
+
279
+ it "supports '_present' operator" do
280
+ [["_present", ""], ["", "_present"]].each do |value, operator|
281
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name IS NOT NULL AND name != '')"]
282
+ end
283
+ end
284
+
285
+ it "supports '_null' operator" do
286
+ [["_null", ""], ["", "_null"]].each do |value, operator|
287
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name IS NULL)"]
288
+ end
289
+ end
290
+
291
+ it "supports '_not_null' operator" do
292
+ [["_not_null", ""], ["", "_not_null"]].each do |value, operator|
293
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name IS NOT NULL)"]
294
+ end
295
+ end
296
+
297
+ it "supports '_empty' operator" do
298
+ [["_empty", ""], ["", "_empty"]].each do |value, operator|
299
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name = '')"]
300
+ end
301
+ end
302
+
303
+ it "supports '_not_empty' operator" do
304
+ [["_not_empty", ""], ["", "_not_empty"]].each do |value, operator|
305
+ @abstract_model.send(:build_statement, :name, :string, value, operator).should == ["(name != '')"]
306
+ end
307
+ end
308
+
309
+ it "supports boolean type query" do
310
+ ['false', 'f', '0'].each do |value|
311
+ @abstract_model.send(:build_statement, :field, :boolean, value, nil).should == ["(field IS NULL OR field = ?)", false]
312
+ end
313
+ ['true', 't', '1'].each do |value|
314
+ @abstract_model.send(:build_statement, :field, :boolean, value, nil).should == ["(field = ?)", true]
315
+ end
316
+ @abstract_model.send(:build_statement, :field, :boolean, 'word', nil).should be_nil
317
+ end
318
+
319
+ it "supports integer type query" do
320
+ @abstract_model.send(:build_statement, :field, :integer, "1", nil).should == ["(field = ?)", 1]
321
+ @abstract_model.send(:build_statement, :field, :integer, 'word', nil).should be_nil
322
+ end
323
+
324
+ it "supports string type query" do
325
+ @abstract_model.send(:build_statement, :field, :string, "", nil).should be_nil
326
+ @abstract_model.send(:build_statement, :field, :string, "foo", "was").should be_nil
327
+ @abstract_model.send(:build_statement, :field, :string, "foo", "default").should == ["(field #{@like} ?)", "%foo%"]
328
+ @abstract_model.send(:build_statement, :field, :string, "foo", "like").should == ["(field #{@like} ?)", "%foo%"]
329
+ @abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").should == ["(field #{@like} ?)", "foo%"]
330
+ @abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").should == ["(field #{@like} ?)", "%foo"]
331
+ @abstract_model.send(:build_statement, :field, :string, "foo", "is").should == ["(field #{@like} ?)", "foo"]
332
+ end
333
+
57
334
  context 'filters on dates' do
58
335
  it 'lists elements within outbound limits' do
59
336
  date_format = I18n.t("admin.misc.filter_date_format", :default => I18n.t("admin.misc.filter_date_format", :locale => :en)).gsub('dd', '%d').gsub('mm', '%m').gsub('yy', '%Y')
60
-
337
+
61
338
  FieldTest.create!(:date_field => Date.strptime("01/01/2012", date_format))
62
339
  FieldTest.create!(:date_field => Date.strptime("01/02/2012", date_format))
63
340
  FieldTest.create!(:date_field => Date.strptime("01/03/2012", date_format))
64
341
  FieldTest.create!(:date_field => Date.strptime("01/04/2012", date_format))
65
- RailsAdmin.config(FieldTest).abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } ).count.should == 2
66
- RailsAdmin.config(FieldTest).abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/02/2012"], :o => 'between' } } } ).count.should == 1
67
- RailsAdmin.config(FieldTest).abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).count.should == 2
68
- RailsAdmin.config(FieldTest).abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).count.should == 2
69
- RailsAdmin.config(FieldTest).abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).count.should == 1
70
-
342
+ @abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } ).count.should == 2
343
+ @abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/02/2012"], :o => 'between' } } } ).count.should == 1
344
+ @abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).count.should == 2
345
+ @abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).count.should == 2
346
+ @abstract_model.all(:filters => { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).count.should == 1
347
+
71
348
  end
72
349
  end
350
+
351
+ it "supports enum type query" do
352
+ @abstract_model.send(:build_statement, :field, :enum, "1", nil).should == ["(field IN (?))", ["1"]]
353
+ end
73
354
  end
74
355
 
356
+ describe "model attribute method" do
357
+ before do
358
+ @abstract_model = RailsAdmin::AbstractModel.new('Player')
359
+ end
360
+
361
+ it "#scoped returns relation object" do
362
+ @abstract_model.scoped.should be_instance_of(ActiveRecord::Relation)
363
+ end
364
+
365
+ it "#table_name works" do
366
+ @abstract_model.table_name.should == 'players'
367
+ end
368
+
369
+ it "#serialized_attributes works" do
370
+ RailsAdmin::AbstractModel.new('User').serialized_attributes.should == ["roles"]
371
+ end
372
+ end
75
373
  end