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
@@ -50,115 +50,114 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'lists associations' do
|
53
|
-
@post.associations.map{|a|a[:name].to_s}.
|
53
|
+
expect(@post.associations.map{|a|a[:name].to_s}).to match_array ['a_r_blog', 'a_r_categories', 'a_r_comments']
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'list associations types in supported [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do
|
57
|
-
(@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.map(&:to_s).
|
57
|
+
expect((@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.map(&:to_s)).to match_array ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
|
58
58
|
end
|
59
59
|
|
60
60
|
it "has correct parameter of belongs_to association" do
|
61
61
|
param = @post.associations.select{|a| a[:name] == :a_r_blog}.first
|
62
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
63
|
-
:name
|
64
|
-
:pretty_name=>"A r blog",
|
65
|
-
:type
|
66
|
-
:foreign_key
|
67
|
-
:foreign_type=>nil,
|
68
|
-
:as=>nil,
|
69
|
-
:polymorphic=>false,
|
70
|
-
:inverse_of=>nil,
|
71
|
-
:read_only=>nil,
|
72
|
-
:nested_form=>nil
|
73
|
-
}
|
74
|
-
param[:primary_key_proc].call.
|
75
|
-
param[:model_proc].call.
|
62
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
63
|
+
:name => :a_r_blog,
|
64
|
+
:pretty_name => "A r blog",
|
65
|
+
:type => :belongs_to,
|
66
|
+
:foreign_key => :a_r_blog_id,
|
67
|
+
:foreign_type => nil,
|
68
|
+
:as => nil,
|
69
|
+
:polymorphic => false,
|
70
|
+
:inverse_of => nil,
|
71
|
+
:read_only => nil,
|
72
|
+
:nested_form => nil,
|
73
|
+
})
|
74
|
+
expect(param[:primary_key_proc].call).to eq('id')
|
75
|
+
expect(param[:model_proc].call).to eq(ARBlog)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "has correct parameter of has_many association" do
|
79
79
|
param = @blog.associations.select{|a| a[:name] == :a_r_posts}.first
|
80
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
81
|
-
:name
|
82
|
-
:pretty_name=>"A r posts",
|
83
|
-
:type
|
84
|
-
:foreign_key
|
85
|
-
:foreign_type=>nil,
|
86
|
-
:as=>nil,
|
87
|
-
:polymorphic=>false,
|
88
|
-
:inverse_of=>nil,
|
89
|
-
:read_only=>nil,
|
90
|
-
:nested_form=>nil
|
91
|
-
}
|
92
|
-
param[:primary_key_proc].call.
|
93
|
-
param[:model_proc].call.
|
80
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
81
|
+
:name => :a_r_posts,
|
82
|
+
:pretty_name => "A r posts",
|
83
|
+
:type => :has_many,
|
84
|
+
:foreign_key => :ar_blog_id,
|
85
|
+
:foreign_type => nil,
|
86
|
+
:as => nil,
|
87
|
+
:polymorphic => false,
|
88
|
+
:inverse_of => nil,
|
89
|
+
:read_only => nil,
|
90
|
+
:nested_form => nil,
|
91
|
+
})
|
92
|
+
expect(param[:primary_key_proc].call).to eq('id')
|
93
|
+
expect(param[:model_proc].call).to eq(ARPost)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "has correct parameter of has_and_belongs_to_many association" do
|
97
97
|
param = @post.associations.select{|a| a[:name] == :a_r_categories}.first
|
98
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
99
|
-
:name
|
100
|
-
:pretty_name=>"A r categories",
|
101
|
-
:type
|
102
|
-
:foreign_key
|
103
|
-
:foreign_type=>nil,
|
104
|
-
:as=>nil,
|
105
|
-
:polymorphic=>false,
|
106
|
-
:inverse_of=>nil,
|
107
|
-
:read_only=>nil,
|
108
|
-
:nested_form=>nil
|
109
|
-
}
|
110
|
-
param[:primary_key_proc].call.
|
111
|
-
param[:model_proc].call.
|
98
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
99
|
+
:name => :a_r_categories,
|
100
|
+
:pretty_name => "A r categories",
|
101
|
+
:type => :has_and_belongs_to_many,
|
102
|
+
:foreign_key => :ar_post_id,
|
103
|
+
:foreign_type => nil,
|
104
|
+
:as => nil,
|
105
|
+
:polymorphic => false,
|
106
|
+
:inverse_of => nil,
|
107
|
+
:read_only => nil,
|
108
|
+
:nested_form => nil
|
109
|
+
})
|
110
|
+
expect(param[:primary_key_proc].call).to eq('id')
|
111
|
+
expect(param[:model_proc].call).to eq(ARCategory)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "has correct parameter of polymorphic belongs_to association" do
|
115
115
|
RailsAdmin::Config.stub!(:models_pool).and_return(["ARBlog", "ARPost", "ARCategory", "ARUser", "ARProfile", "ARComment"])
|
116
116
|
param = @comment.associations.select{|a| a[:name] == :commentable}.first
|
117
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
118
|
-
:name
|
119
|
-
:pretty_name=>"Commentable",
|
120
|
-
:type
|
121
|
-
:foreign_key
|
122
|
-
:foreign_type
|
123
|
-
:as=>nil,
|
124
|
-
:polymorphic=>true,
|
125
|
-
:inverse_of=>nil,
|
126
|
-
:read_only=>nil,
|
127
|
-
:nested_form=>nil
|
128
|
-
}
|
129
|
-
#
|
130
|
-
|
117
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
118
|
+
:name => :commentable,
|
119
|
+
:pretty_name => "Commentable",
|
120
|
+
:type => :belongs_to,
|
121
|
+
:foreign_key => :commentable_id,
|
122
|
+
:foreign_type => :commentable_type,
|
123
|
+
:as => nil,
|
124
|
+
:polymorphic => true,
|
125
|
+
:inverse_of => nil,
|
126
|
+
:read_only => nil,
|
127
|
+
:nested_form => nil
|
128
|
+
})
|
129
|
+
# Should not be called for polymorphic relations.
|
130
|
+
# TODO: Handle this case
|
131
|
+
# expect(param[:primary_key_proc].call).to eq('id')
|
132
|
+
expect(param[:model_proc].call).to eq([ARBlog, ARPost])
|
131
133
|
end
|
132
134
|
|
133
135
|
it "has correct parameter of polymorphic inverse has_many association" do
|
134
136
|
param = @blog.associations.select{|a| a[:name] == :a_r_comments}.first
|
135
|
-
param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }.
|
136
|
-
:name
|
137
|
-
:pretty_name=>"A r comments",
|
138
|
-
:type
|
139
|
-
:foreign_key
|
140
|
-
:foreign_type=>nil,
|
141
|
-
:as
|
142
|
-
:polymorphic=>false,
|
143
|
-
:inverse_of=>nil,
|
144
|
-
:read_only=>nil,
|
145
|
-
:nested_form=>nil
|
146
|
-
}
|
147
|
-
param[:primary_key_proc].call.
|
148
|
-
param[:model_proc].call.
|
137
|
+
expect(param.reject{|k, v| [:primary_key_proc, :model_proc].include? k }).to eq({
|
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
|
+
expect(param[:primary_key_proc].call).to eq('id')
|
150
|
+
expect(param[:model_proc].call).to eq(ARComment)
|
149
151
|
end
|
150
152
|
end
|
151
|
-
|
152
153
|
|
153
154
|
describe "#properties" do
|
154
155
|
it "returns parameters of string-type field" do
|
155
|
-
RailsAdmin::AbstractModel.new('Player').properties.select{|f| f[:name] == :name}.
|
156
|
-
[{:name => :name, :pretty_name => "Name", :type => :string, :length => 100, :nullable? => false, :serial? => false}]
|
156
|
+
expect(RailsAdmin::AbstractModel.new('Player').properties.select{|f| f[:name] == :name}).to eq([{:name => :name, :pretty_name => "Name", :type => :string, :length => 100, :nullable? => false, :serial? => false}])
|
157
157
|
end
|
158
158
|
|
159
159
|
it "maps serialized attribute to :serialized field type" do
|
160
|
-
RailsAdmin::AbstractModel.new('User').properties.find{|f| f[:name] == :roles}.
|
161
|
-
{:name => :roles, :pretty_name => "Roles", :length => 255, :nullable? => true, :serial? => false, :type => :serialized}
|
160
|
+
expect(RailsAdmin::AbstractModel.new('User').properties.find{|f| f[:name] == :roles}).to eq({:name => :roles, :pretty_name => "Roles", :length => 255, :nullable? => true, :serial? => false, :type => :serialized})
|
162
161
|
end
|
163
162
|
end
|
164
163
|
|
@@ -169,66 +168,66 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
169
168
|
end
|
170
169
|
|
171
170
|
it "#new returns instance of AbstractObject" do
|
172
|
-
@abstract_model.new.object.
|
171
|
+
expect(@abstract_model.new.object).to be_instance_of(Player)
|
173
172
|
end
|
174
173
|
|
175
174
|
it "#get returns instance of AbstractObject" do
|
176
|
-
@abstract_model.get(@players.first.id).object.
|
175
|
+
expect(@abstract_model.get(@players.first.id).object).to eq(@players.first)
|
177
176
|
end
|
178
177
|
|
179
178
|
it "#get returns nil when id does not exist" do
|
180
|
-
@abstract_model.get('abc').
|
179
|
+
expect(@abstract_model.get('abc')).to be_nil
|
181
180
|
end
|
182
181
|
|
183
182
|
it "#first returns a player" do
|
184
|
-
@players.
|
183
|
+
expect(@players).to include @abstract_model.first
|
185
184
|
end
|
186
185
|
|
187
186
|
it "#count returns count of items" do
|
188
|
-
@abstract_model.count.
|
187
|
+
expect(@abstract_model.count).to eq(@players.count)
|
189
188
|
end
|
190
189
|
|
191
190
|
it "#destroy destroys multiple items" do
|
192
191
|
@abstract_model.destroy(@players[0..1])
|
193
|
-
Player.all.
|
192
|
+
expect(Player.all).to eq(@players[2..2])
|
194
193
|
end
|
195
194
|
|
196
195
|
it "#where returns filtered results" do
|
197
|
-
@abstract_model.where(:name => @players.first.name).
|
196
|
+
expect(@abstract_model.where(:name => @players.first.name)).to eq([@players.first])
|
198
197
|
end
|
199
198
|
|
200
199
|
describe "#all" do
|
201
200
|
it "works without options" do
|
202
|
-
@abstract_model.all.
|
201
|
+
expect(@abstract_model.all).to match_array @players
|
203
202
|
end
|
204
203
|
|
205
204
|
it "supports eager loading" do
|
206
|
-
@abstract_model.all(:include => :team).includes_values.
|
205
|
+
expect(@abstract_model.all(:include => :team).includes_values).to eq([:team])
|
207
206
|
end
|
208
207
|
|
209
208
|
it "supports limiting" do
|
210
|
-
@abstract_model.all(:limit => 2).
|
209
|
+
expect(@abstract_model.all(:limit => 2)).to have(2).items
|
211
210
|
end
|
212
211
|
|
213
212
|
it "supports retrieval by bulk_ids" do
|
214
|
-
@abstract_model.all(:bulk_ids => @players[0..1].map(&:id)).
|
213
|
+
expect(@abstract_model.all(:bulk_ids => @players[0..1].map(&:id))).to match_array @players[0..1]
|
215
214
|
end
|
216
215
|
|
217
216
|
it "supports pagination" do
|
218
|
-
@abstract_model.all(:sort => "id", :page => 2, :per => 1).
|
219
|
-
@abstract_model.all(:sort => "id", :page => 1, :per => 2).
|
217
|
+
expect(@abstract_model.all(:sort => "id", :page => 2, :per => 1)).to eq(@players[1..1])
|
218
|
+
expect(@abstract_model.all(:sort => "id", :page => 1, :per => 2)).to eq(@players[1..2].reverse)
|
220
219
|
end
|
221
220
|
|
222
221
|
it "supports ordering" do
|
223
|
-
@abstract_model.all(:sort => "id", :sort_reverse => true).
|
222
|
+
expect(@abstract_model.all(:sort => "id", :sort_reverse => true)).to eq(@players.sort)
|
224
223
|
end
|
225
224
|
|
226
225
|
it "supports querying" do
|
227
|
-
@abstract_model.all(:query => @players[1].name).
|
226
|
+
expect(@abstract_model.all(:query => @players[1].name)).to eq(@players[1..1])
|
228
227
|
end
|
229
228
|
|
230
229
|
it "supports filtering" do
|
231
|
-
@abstract_model.all(:filters => {"name" => {"0000" => {:o=>"is", :v
|
230
|
+
expect(@abstract_model.all(:filters => {"name" => {"0000" => {:o => "is", :v => @players[1].name}}})).to eq(@players[1..1])
|
232
231
|
end
|
233
232
|
end
|
234
233
|
end
|
@@ -236,12 +235,12 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
236
235
|
describe "#query_conditions" do
|
237
236
|
before do
|
238
237
|
@abstract_model = RailsAdmin::AbstractModel.new('Team')
|
239
|
-
@teams = [{}, {:name=>'somewhere foos'}, {:manager=>'foo junior'}].
|
238
|
+
@teams = [{}, {:name => 'somewhere foos'}, {:manager => 'foo junior'}].
|
240
239
|
map{|h| FactoryGirl.create :team, h}
|
241
240
|
end
|
242
241
|
|
243
242
|
it "makes conrrect query" do
|
244
|
-
@abstract_model.all(:query => "foo").
|
243
|
+
expect(@abstract_model.all(:query => "foo")).to match_array @teams[1..2]
|
245
244
|
end
|
246
245
|
end
|
247
246
|
|
@@ -249,16 +248,16 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
249
248
|
before do
|
250
249
|
@abstract_model = RailsAdmin::AbstractModel.new('Team')
|
251
250
|
@division = FactoryGirl.create :division, :name => 'bar division'
|
252
|
-
@teams = [{}, {:division
|
251
|
+
@teams = [{}, {:division => @division}, {:name => 'somewhere foos', :division => @division}, {:name => 'nowhere foos'}].
|
253
252
|
map{|h| FactoryGirl.create :team, h}
|
254
253
|
end
|
255
254
|
|
256
255
|
it "makes conrrect query" do
|
257
|
-
@abstract_model.all(
|
258
|
-
:filters => {"name" => {"0000" => {:o=>"like", :v=>"foo"}},
|
259
|
-
"division" => {"0001" => {:o=>"like", :v=>"bar"}}},
|
256
|
+
expect(@abstract_model.all(
|
257
|
+
:filters => {"name" => {"0000" => {:o => "like", :v => "foo"}},
|
258
|
+
"division" => {"0001" => {:o => "like", :v => "bar"}}},
|
260
259
|
:include => :division
|
261
|
-
).
|
260
|
+
)).to eq([@teams[2]])
|
262
261
|
end
|
263
262
|
end
|
264
263
|
|
@@ -269,93 +268,93 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
269
268
|
|
270
269
|
it "ignores '_discard' operator or value" do
|
271
270
|
[["_discard", ""], ["", "_discard"]].each do |value, operator|
|
272
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
271
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to be_nil
|
273
272
|
end
|
274
273
|
end
|
275
274
|
|
276
275
|
it "supports '_blank' operator" do
|
277
276
|
[["_blank", ""], ["", "_blank"]].each do |value, operator|
|
278
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
277
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name IS NULL OR name = '')"])
|
279
278
|
end
|
280
279
|
end
|
281
280
|
|
282
281
|
it "supports '_present' operator" do
|
283
282
|
[["_present", ""], ["", "_present"]].each do |value, operator|
|
284
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
283
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name IS NOT NULL AND name != '')"])
|
285
284
|
end
|
286
285
|
end
|
287
286
|
|
288
287
|
it "supports '_null' operator" do
|
289
288
|
[["_null", ""], ["", "_null"]].each do |value, operator|
|
290
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
289
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name IS NULL)"])
|
291
290
|
end
|
292
291
|
end
|
293
292
|
|
294
293
|
it "supports '_not_null' operator" do
|
295
294
|
[["_not_null", ""], ["", "_not_null"]].each do |value, operator|
|
296
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
295
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name IS NOT NULL)"])
|
297
296
|
end
|
298
297
|
end
|
299
298
|
|
300
299
|
it "supports '_empty' operator" do
|
301
300
|
[["_empty", ""], ["", "_empty"]].each do |value, operator|
|
302
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
301
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name = '')"])
|
303
302
|
end
|
304
303
|
end
|
305
304
|
|
306
305
|
it "supports '_not_empty' operator" do
|
307
306
|
[["_not_empty", ""], ["", "_not_empty"]].each do |value, operator|
|
308
|
-
@abstract_model.send(:build_statement, :name, :string, value, operator).
|
307
|
+
expect(@abstract_model.send(:build_statement, :name, :string, value, operator)).to eq(["(name != '')"])
|
309
308
|
end
|
310
309
|
end
|
311
310
|
|
312
311
|
it "supports boolean type query" do
|
313
312
|
['false', 'f', '0'].each do |value|
|
314
|
-
@abstract_model.send(:build_statement, :field, :boolean, value, nil).
|
313
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, value, nil)).to eq(["(field IS NULL OR field = ?)", false])
|
315
314
|
end
|
316
315
|
['true', 't', '1'].each do |value|
|
317
|
-
@abstract_model.send(:build_statement, :field, :boolean, value, nil).
|
316
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, value, nil)).to eq(["(field = ?)", true])
|
318
317
|
end
|
319
|
-
@abstract_model.send(:build_statement, :field, :boolean, 'word', nil).
|
318
|
+
expect(@abstract_model.send(:build_statement, :field, :boolean, 'word', nil)).to be_nil
|
320
319
|
end
|
321
320
|
|
322
321
|
it "supports integer type query" do
|
323
|
-
@abstract_model.send(:build_statement, :field, :integer, "1", nil).
|
324
|
-
@abstract_model.send(:build_statement, :field, :integer, 'word', nil).
|
322
|
+
expect(@abstract_model.send(:build_statement, :field, :integer, "1", nil)).to eq(["(field = ?)", 1])
|
323
|
+
expect(@abstract_model.send(:build_statement, :field, :integer, 'word', nil)).to be_nil
|
325
324
|
end
|
326
325
|
|
327
326
|
it "supports decimal type query" do
|
328
|
-
@abstract_model.send(:build_statement, :field, :decimal, "1.1", nil).
|
329
|
-
@abstract_model.send(:build_statement, :field, :decimal, 'word', nil).
|
327
|
+
expect(@abstract_model.send(:build_statement, :field, :decimal, "1.1", nil)).to eq(["(field = ?)", 1.1])
|
328
|
+
expect(@abstract_model.send(:build_statement, :field, :decimal, 'word', nil)).to be_nil
|
330
329
|
end
|
331
330
|
|
332
331
|
it "supports string type query" do
|
333
|
-
@abstract_model.send(:build_statement, :field, :string, "", nil).
|
334
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "was").
|
335
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "default").
|
336
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "like").
|
337
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with").
|
338
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with").
|
339
|
-
@abstract_model.send(:build_statement, :field, :string, "foo", "is").
|
332
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "", nil)).to be_nil
|
333
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "was")).to be_nil
|
334
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "default")).to eq(["(field #{@like} ?)", "%foo%"])
|
335
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "like")).to eq(["(field #{@like} ?)", "%foo%"])
|
336
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "starts_with")).to eq(["(field #{@like} ?)", "foo%"])
|
337
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "ends_with")).to eq(["(field #{@like} ?)", "%foo"])
|
338
|
+
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "is")).to eq(["(field #{@like} ?)", "foo"])
|
340
339
|
end
|
341
340
|
|
342
341
|
|
343
342
|
it 'supports date type query' do
|
344
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } }).
|
345
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).
|
346
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).
|
347
|
-
@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).
|
343
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } })).to eq(["((field_tests.date_field BETWEEN ? AND ?))", Date.new(2012,1,2), Date.new(2012,1,3)])
|
344
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq(["((field_tests.date_field >= ?))", Date.new(2012,1,3)])
|
345
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq(["((field_tests.date_field <= ?))", Date.new(2012,1,2)])
|
346
|
+
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq(["((field_tests.date_field BETWEEN ? AND ?))", Date.new(2012,1,2), Date.new(2012,1,2)])
|
348
347
|
end
|
349
348
|
|
350
349
|
it 'supports datetime type query' do
|
351
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } ).
|
352
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } ).
|
353
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } ).
|
354
|
-
@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } ).
|
350
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } )).to eq(["((field_tests.datetime_field BETWEEN ? AND ?))", Time.local(2012,1,2), Time.local(2012,1,3).end_of_day])
|
351
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq(["((field_tests.datetime_field >= ?))", Time.local(2012,1,3)])
|
352
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq(["((field_tests.datetime_field <= ?))", Time.local(2012,1,2).end_of_day])
|
353
|
+
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq(["((field_tests.datetime_field BETWEEN ? AND ?))", Time.local(2012,1,2), Time.local(2012,1,2).end_of_day])
|
355
354
|
end
|
356
355
|
|
357
356
|
it "supports enum type query" do
|
358
|
-
@abstract_model.send(:build_statement, :field, :enum, "1", nil).
|
357
|
+
expect(@abstract_model.send(:build_statement, :field, :enum, "1", nil)).to eq(["(field IN (?))", ["1"]])
|
359
358
|
end
|
360
359
|
end
|
361
360
|
|
@@ -365,11 +364,11 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
365
364
|
end
|
366
365
|
|
367
366
|
it "#scoped returns relation object" do
|
368
|
-
@abstract_model.scoped.
|
367
|
+
expect(@abstract_model.scoped).to be_instance_of(ActiveRecord::Relation)
|
369
368
|
end
|
370
369
|
|
371
370
|
it "#table_name works" do
|
372
|
-
@abstract_model.table_name.
|
371
|
+
expect(@abstract_model.table_name).to eq('players')
|
373
372
|
end
|
374
373
|
end
|
375
374
|
end
|
@@ -9,23 +9,23 @@ describe "Mongoid::AbstractObject", :mongoid => true do
|
|
9
9
|
|
10
10
|
describe "references_many association" do
|
11
11
|
it "supports retrieval of ids through foo_ids" do
|
12
|
-
@team.player_ids.
|
12
|
+
expect(@team.player_ids).to eq([])
|
13
13
|
player = FactoryGirl.create :player, :team => @team
|
14
|
-
@team.player_ids.
|
14
|
+
expect(@team.player_ids).to eq([player.id])
|
15
15
|
end
|
16
16
|
|
17
17
|
it "supports assignment of items through foo_ids=" do
|
18
|
-
@team.players.
|
18
|
+
expect(@team.players).to eq([])
|
19
19
|
@team.player_ids = @players.map(&:id)
|
20
20
|
@team.reload
|
21
|
-
@team.players.map(&:id).
|
21
|
+
expect(@team.players.map(&:id)).to match_array @players.map(&:id)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "skips invalid id on assignment through foo_ids=" do
|
25
25
|
@team.player_ids = @players.map{|item| item.id.to_s }.unshift('4f431021dcf2310db7000006')
|
26
26
|
@team.reload
|
27
27
|
@players.each &:reload
|
28
|
-
@team.players.map(&:id).
|
28
|
+
expect(@team.players.map(&:id)).to match_array @players.map(&:id)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|