extjs-mvc 0.2.8 → 0.3.0
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.
- data/README.rdoc +51 -5
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/lib/extjs-mvc.rb +0 -6
- data/lib/model/active_record.rb +38 -20
- data/lib/model/base.rb +181 -118
- data/lib/model/data_mapper.rb +2 -1
- data/lib/model/mongo_mapper.rb +2 -1
- data/test/debug.log +390 -0
- data/test/model_test.rb +342 -26
- data/test/{mongo_mapper.rb → mongo_mapper_test.rb} +0 -0
- data/test/test_helper.rb +45 -2
- metadata +15 -5
data/test/model_test.rb
CHANGED
@@ -1,27 +1,81 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class BogusModel
|
4
|
+
include ExtJS::Model
|
5
|
+
class << self
|
6
|
+
def extjs_allow_blank(col)
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def extjs_default(col)
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def extjs_type(col)
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def extjs_column_names
|
19
|
+
[:one, :two, :three_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
def extjs_columns_hash
|
23
|
+
{
|
24
|
+
:one => {},
|
25
|
+
:two => {},
|
26
|
+
:three_id => {}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def extjs_polymorphic_type(id_column_name)
|
31
|
+
id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
|
32
|
+
end
|
33
|
+
|
34
|
+
def extjs_primary_key
|
35
|
+
:id
|
36
|
+
end
|
37
|
+
|
38
|
+
def extjs_associations
|
39
|
+
{
|
40
|
+
:three => {
|
41
|
+
:name => :tree,
|
42
|
+
:type => :belongs_to,
|
43
|
+
:class => nil,
|
44
|
+
:foreign_key => :three_id,
|
45
|
+
:is_polymorphic => false
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
class BogusModelChild < BogusModel
|
54
|
+
end
|
55
|
+
|
3
56
|
class ModelTest < Test::Unit::TestCase
|
4
57
|
context "Rendering DataReader configuration for Person and User" do
|
5
58
|
|
6
59
|
setup do
|
7
|
-
|
60
|
+
clean_all
|
8
61
|
end
|
9
62
|
|
10
63
|
should "Person and User should render a valid Reader config" do
|
11
64
|
reader = Person.extjs_record
|
12
|
-
assert reader.kind_of?(Hash) && reader.has_key?(
|
65
|
+
assert reader.kind_of?(Hash) && reader.has_key?(:fields) && reader.has_key?(:idProperty)
|
13
66
|
end
|
14
67
|
should "Person instance should render with to_record, a Hash containing at least a primary_key" do
|
15
68
|
rec = Person.first.to_record
|
16
|
-
|
69
|
+
assert_kind_of(Hash, rec)
|
70
|
+
assert_array_has_item(rec.keys, 'has primary key') { |i| i.to_s == Person.extjs_primary_key.to_s }
|
17
71
|
end
|
18
72
|
should "User should render a Reader config" do
|
19
73
|
reader = User.extjs_record
|
20
|
-
assert reader.kind_of?(Hash) && reader.has_key?(
|
74
|
+
assert reader.kind_of?(Hash) && reader.has_key?(:fields) && reader.has_key?(:idProperty)
|
21
75
|
end
|
22
76
|
should "User instance should render with to_record, a Hash containing at least a primary_key" do
|
23
77
|
rec = User.first.to_record
|
24
|
-
assert rec.kind_of?(Hash) && rec.keys.include?(User.extjs_primary_key
|
78
|
+
assert rec.kind_of?(Hash) && rec.keys.include?(User.extjs_primary_key)
|
25
79
|
end
|
26
80
|
should "User instance should render to_record containing foreign_key of Person" do
|
27
81
|
rec = User.first.to_record
|
@@ -33,6 +87,7 @@ class ModelTest < Test::Unit::TestCase
|
|
33
87
|
|
34
88
|
context "A User with HABTM relationship with Group" do
|
35
89
|
setup do
|
90
|
+
clean_all
|
36
91
|
UserGroup.destroy_all
|
37
92
|
|
38
93
|
@user = User.first
|
@@ -42,75 +97,336 @@ class ModelTest < Test::Unit::TestCase
|
|
42
97
|
|
43
98
|
should "Render to_record should return 2 groups" do
|
44
99
|
User.extjs_fields(:groups)
|
45
|
-
assert @user.to_record[
|
100
|
+
assert @user.to_record[:groups].length == 2
|
46
101
|
end
|
47
102
|
end
|
48
103
|
|
49
104
|
context "A User with Person relationship: User.extjs_fields(:password, :person => [:first, {:last => {'sortDir' => 'ASC'}}])" do
|
50
105
|
setup do
|
51
|
-
|
52
|
-
|
106
|
+
clean_all
|
107
|
+
User.extjs_fields(:password, {:person => [:first, {:last => {:sortDir => "ASC"}}]})
|
108
|
+
@fields = User.extjs_record[:fields]
|
53
109
|
end
|
54
110
|
|
55
111
|
should "User should render a Reader with 4 total fields" do
|
56
112
|
assert @fields.count === 4
|
57
113
|
end
|
58
114
|
should "Reader fields should contain 'password' field" do
|
59
|
-
|
115
|
+
assert_array_has_item(@fields, 'has password field') {|f| f[:name] === "password"}
|
60
116
|
end
|
61
117
|
should "Reader fields should contain person_id" do
|
62
118
|
assns = User.extjs_associations
|
63
|
-
assn = assns[:person]
|
64
|
-
|
119
|
+
assn = assns[:person]
|
120
|
+
assert_array_has_item(@fields, 'has foreign key person_id') {|f| f[:name] === assns[:person][:foreign_key].to_s }
|
65
121
|
end
|
66
122
|
should "Reader fields should contain mapped field 'person.first'" do
|
67
|
-
|
123
|
+
assert_array_has_item(@fields, 'has person_first') {|f| f[:name] === "person_first" and f[:mapping] === "person.first"}
|
68
124
|
end
|
69
125
|
should "Reader fields should contain mapped field 'person.last'" do
|
70
|
-
|
126
|
+
assert_array_has_item(@fields, 'has person_last') {|f| f[:name] === "person_last" and f[:mapping] === "person.last"}
|
71
127
|
end
|
72
128
|
should "person.last should have additional configuration 'sortDir' => 'ASC'" do
|
73
|
-
|
129
|
+
assert_array_has_item(@fields, 'has person.last with sortDir') {|f| f[:name] === "person_last" and f[:sortDir] === 'ASC' }
|
130
|
+
end
|
131
|
+
|
132
|
+
should "produce a valid to_record record" do
|
133
|
+
person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
|
134
|
+
user = User.create!(:person_id => person.id, :password => 'password')
|
135
|
+
record = user.to_record
|
136
|
+
assert_equal(user.id, record[:id])
|
137
|
+
assert_equal(person.id, record[:person_id])
|
138
|
+
assert_equal('password', record[:password])
|
139
|
+
assert_equal('last', record[:person][:last])
|
140
|
+
assert_equal('first', record[:person][:first])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "User with standard Person association" do
|
145
|
+
setup do
|
146
|
+
clean_all
|
147
|
+
User.extjs_fields(:id, :password, :person)
|
148
|
+
end
|
149
|
+
should "produce a valid store config" do
|
150
|
+
fields = User.extjs_record[:fields]
|
151
|
+
assert_array_has_item(fields, 'has id') {|f| f[:name] === "id" }
|
152
|
+
assert_array_has_item(fields, 'has person_id') {|f| f[:name] === "person_id" }
|
153
|
+
assert_array_has_item(fields, 'has password') {|f| f[:name] === "password" }
|
154
|
+
assert_array_has_item(fields, 'has person_last') {|f| f[:name] === "person_last" and f[:mapping] == "person.last" }
|
155
|
+
assert_array_has_item(fields, 'has person_first') {|f| f[:name] === "person_first" and f[:mapping] == "person.first" }
|
156
|
+
end
|
157
|
+
should "produce a valid to_record record" do
|
158
|
+
person = Person.create!(:first => 'first', :last => 'last', :email => 'email')
|
159
|
+
user = User.create!(:person_id => person.id, :password => 'password')
|
160
|
+
record = user.to_record
|
161
|
+
assert_equal(user.id, record[:id])
|
162
|
+
assert_equal(person.id, record[:person_id])
|
163
|
+
assert_equal('password', record[:password])
|
164
|
+
assert_equal('last', record[:person][:last])
|
165
|
+
assert_equal('first', record[:person][:first])
|
74
166
|
end
|
75
167
|
end
|
76
168
|
|
77
169
|
context "Fields should render with correct, ExtJS-compatible data-types" do
|
78
170
|
setup do
|
79
|
-
|
171
|
+
clean_all
|
172
|
+
@fields = DataType.extjs_record[:fields]
|
80
173
|
end
|
81
174
|
|
82
175
|
should "Understand 'string'" do
|
83
|
-
|
176
|
+
assert_array_has_item(@fields, 'has string_column with string') {|f| f[:name] == 'string_column' and f[:type] == 'string'}
|
84
177
|
end
|
85
178
|
should "Understand 'integer' as 'int'" do
|
86
|
-
|
179
|
+
assert_array_has_item(@fields, 'has integer_column with int') {|f| f[:name] == 'integer_column' and f[:type] == 'int'}
|
87
180
|
end
|
88
181
|
should "Understand 'float'" do
|
89
|
-
|
182
|
+
assert_array_has_item(@fields, 'has float_column with float') {|f| f[:name] == 'float_column' and f[:type] == 'float'}
|
90
183
|
end
|
91
184
|
should "Understand 'decimal' as 'float'" do # Is this correct??
|
92
|
-
|
185
|
+
assert_array_has_item(@fields, 'has decimal_column with float') {|f| f[:name] == 'decimal_column' and f[:type] == 'float'}
|
93
186
|
end
|
94
187
|
should "Understand 'date'" do
|
95
|
-
|
188
|
+
assert_array_has_item(@fields, 'has date_column with date') {|f| f[:name] == 'date_column' and f[:type] == 'date'}
|
96
189
|
end
|
97
190
|
should "Understand 'datetime' as 'date'" do
|
98
|
-
|
191
|
+
assert_array_has_item(@fields, 'has datetime_column with date') {|f| f[:name] == 'datetime_column' and f[:type] == 'date'}
|
99
192
|
end
|
100
193
|
should "Understand 'time' as 'date'" do
|
101
|
-
|
194
|
+
assert_array_has_item(@fields, 'has time_column with date') {|f| f[:name] == 'time_column' and f[:type] == 'date'}
|
102
195
|
end
|
103
196
|
should "Understand 'boolean'" do
|
104
|
-
|
197
|
+
assert_array_has_item(@fields, 'has boolean_column with boolean') {|f| f[:name] == 'boolean_column' and f[:type] == 'boolean'}
|
105
198
|
end
|
106
199
|
should "Understand NOT NULL" do
|
107
|
-
|
200
|
+
assert_array_has_item(@fields, 'has notnull_column with allowBlank == false') {|f| f[:name] == 'notnull_column' and f[:allowBlank] === false}
|
201
|
+
end
|
202
|
+
should "Understand DEFAULT" do
|
203
|
+
assert_array_has_item(@fields, 'has default_column with defaultValue == true') {|f| f[:name] == 'default_column' and f[:defaultValue] === true}
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "polymorphic assosiations" do
|
208
|
+
setup do
|
209
|
+
clean_all
|
210
|
+
end
|
211
|
+
|
212
|
+
should "return nil as class for a polymorphic relation" do
|
213
|
+
assert_equal(nil, Address.extjs_associations[:addressable][:class])
|
108
214
|
end
|
109
|
-
|
110
|
-
|
215
|
+
|
216
|
+
should "create a proper default store config" do
|
217
|
+
Address.extjs_fields
|
218
|
+
fields = Address.extjs_record[:fields]
|
219
|
+
assert_array_has_item(fields, 'has addressable_id') {|f| f[:name] === 'addressable_id' && !f[:mapping] }
|
220
|
+
assert_array_has_item(fields, 'addressable_type') {|f| f[:name] === 'addressable_type' && !f[:mapping] }
|
221
|
+
end
|
222
|
+
|
223
|
+
should "create the right store config when including members of the polymorpic association" do
|
224
|
+
Address.extjs_fields :street, :addressable => [:name]
|
225
|
+
fields = Address.extjs_record[:fields]
|
226
|
+
assert_array_has_item(fields, "has addressable_name") {|f| f[:name] === 'addressable_name' && f[:mapping] === 'addressable.name'}
|
227
|
+
assert_array_has_item(fields, "has addressable_id") {|f| f[:name] === 'addressable_id' && !f[:mapping] }
|
228
|
+
assert_array_has_item(fields, "has addressable_type") {|f| f[:name] === 'addressable_type' && !f[:mapping] }
|
229
|
+
end
|
230
|
+
|
231
|
+
should "fill in the right values for to_record" do
|
232
|
+
Address.extjs_fields :street, :addressable => [:name]
|
233
|
+
location = Location.create!(:name => 'Home')
|
234
|
+
address = location.create_address(:street => 'Main Street 1')
|
235
|
+
record = address.to_record
|
236
|
+
assert_equal({:name => "Home", :id => location.id}, record[:addressable])
|
237
|
+
assert_equal("Location", record[:addressable_type])
|
238
|
+
assert_equal(location.id, record[:addressable_id])
|
239
|
+
assert_equal(address.id, record[:id])
|
240
|
+
assert_equal("Main Street 1", record[:street])
|
111
241
|
end
|
112
242
|
end
|
113
243
|
|
244
|
+
context "single table inheritance" do
|
245
|
+
setup do
|
246
|
+
clean_all
|
247
|
+
end
|
248
|
+
|
249
|
+
should "fieldsets should be accessible from decendants" do
|
250
|
+
Location.extjs_fieldset :on_location, [:street]
|
251
|
+
fields = House.extjs_record(:on_location)[:fields]
|
252
|
+
assert_array_has_item(fields, 'has street') {|f| f[:name] === 'street' }
|
253
|
+
assert_array_has_not_item(fields, 'has name') {|f| f[:name] === 'name' }
|
254
|
+
end
|
255
|
+
should "fieldsets should be overrideable from decendants" do
|
256
|
+
Location.extjs_fieldset :override, [:street]
|
257
|
+
House.extjs_fieldset :override, [:name]
|
258
|
+
fields = House.extjs_record(:override)[:fields]
|
259
|
+
assert_array_has_not_item(fields, 'has street') {|f| f[:name] === 'street' }
|
260
|
+
assert_array_has_item(fields, 'has name') {|f| f[:name] === 'name' }
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context "ExtJS::Model::ClassMethods" do
|
265
|
+
|
266
|
+
context "#extjs_extract_fieldset! default" do
|
267
|
+
setup do
|
268
|
+
@fieldset, @fields = BogusModel.extjs_extract_fieldset! [:one, :two, :three]
|
269
|
+
end
|
270
|
+
should "return :default when no fieldset provided" do
|
271
|
+
assert_equal(:'default', @fieldset)
|
272
|
+
end
|
273
|
+
should "not alter the fields array" do
|
274
|
+
assert_equal([:one, :two, :three], @fields)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "#extjs_extract_fieldset! with explicit fieldset definition" do
|
279
|
+
setup do
|
280
|
+
@fieldset, @fields = BogusModel.extjs_extract_fieldset! [:explicit, [:one, :two, :three]]
|
281
|
+
end
|
282
|
+
should "return :default when no fieldset provided" do
|
283
|
+
assert_equal(:'explicit', @fieldset)
|
284
|
+
end
|
285
|
+
should "not alter the fields array" do
|
286
|
+
assert_equal([:one, :two, :three], @fields)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context "#extjs_extract_fieldset! edge cases" do
|
291
|
+
should "called without arguments" do
|
292
|
+
@fieldset, @fields = BogusModel.extjs_extract_fieldset! []
|
293
|
+
assert_equal(:'default', @fieldset)
|
294
|
+
assert_equal([], @fields)
|
295
|
+
end
|
296
|
+
should "called with only the fieldset and no field arguments" do
|
297
|
+
@fieldset, @fields = BogusModel.extjs_extract_fieldset! [:explicit]
|
298
|
+
assert_equal(:'explicit', @fieldset)
|
299
|
+
assert_equal([], @fields)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context "#process_fields" do
|
304
|
+
should "handle a simple Array of Symbols" do
|
305
|
+
@fields = BogusModel.process_fields :one, :two, :three
|
306
|
+
assert_equal([{:name => :one}, {:name => :two}, {:name => :three}], @fields)
|
307
|
+
end
|
308
|
+
should "handle a mixed Array where the last item is a Hash" do
|
309
|
+
@fields = BogusModel.process_fields :one, :two, :three => [:three_one, :three_two]
|
310
|
+
assert_equal([{:name => :one}, {:name => :two}, {:name => :three, :fields => [{:name => :three_one}, {:name => :three_two}]}], @fields)
|
311
|
+
end
|
312
|
+
should "handle a mixed Array where a middle item is a Hash" do
|
313
|
+
@fields = BogusModel.process_fields :one, {:two => [:two_one, :two_two]}, :three
|
314
|
+
assert_equal([
|
315
|
+
{:name => :one},
|
316
|
+
{:name => :two, :fields => [{:name => :two_one}, {:name => :two_two}]},
|
317
|
+
{:name => :three}], @fields)
|
318
|
+
end
|
319
|
+
should "handle option :only" do
|
320
|
+
@fields = BogusModel.process_fields :only => [:one, :two, :three]
|
321
|
+
assert_equal([{:name => :one}, {:name => :two}, {:name => :three}], @fields)
|
322
|
+
end
|
323
|
+
should "handle option :exclude" do
|
324
|
+
@fields = BogusModel.process_fields :exclude => [:two]
|
325
|
+
assert_equal([{:name => :one}, {:name => :three_id}], @fields)
|
326
|
+
end
|
327
|
+
should "handle {:field => {:sortDir => 'ASC'}}" do
|
328
|
+
@fields = BogusModel.process_fields({:field => {:sortDir => 'ASC'}})
|
329
|
+
assert_equal([{:name => :field, :sortDir => 'ASC'}], @fields)
|
330
|
+
end
|
331
|
+
should "handle recursive definition" do
|
332
|
+
@fields = BogusModel.process_fields(:one, {:three => [{:one => [:one, :two]}, {:two => {:sortDir => "ASC"}}]})
|
333
|
+
assert_equal([{:name => :one}, {:name => :three, :fields => [{:name => :one, :fields => [{:name => :one}, {:name => :two}]}, {:name => :two, :sortDir => 'ASC'}]}], @fields)
|
334
|
+
end
|
335
|
+
should "not touch already correct fields" do
|
336
|
+
@fields = BogusModel.process_fields(:one, {:name => :field,:sortDir => 'ASC'})
|
337
|
+
assert_equal([{:name => :one},{:name => :field, :sortDir => 'ASC'}], @fields)
|
338
|
+
end
|
339
|
+
should "raise ArgumentError when pass in bogus hash" do
|
340
|
+
assert_raise(ArgumentError) { @fields = BogusModel.process_fields(:one, {:nme => :field,:sortDir => 'ASC'}) }
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context "#extjs_field" do
|
345
|
+
should "type gets set to 'auto' when not present" do
|
346
|
+
@field = BogusModel.extjs_field({:name => :test})
|
347
|
+
assert_equal('auto', @field[:type])
|
348
|
+
end
|
349
|
+
should "not touch type when alredy present" do
|
350
|
+
@field = BogusModel.extjs_field({:name => :test, :type => 'untouched'})
|
351
|
+
assert_equal('untouched', @field[:type])
|
352
|
+
end
|
353
|
+
should "raise exception when bogus field config passed" do
|
354
|
+
assert_raise(ArgumentError) { BogusModel.extjs_field({:name => :test, "type" => 'untouched'}) }
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
context "#extjs_field with ORM config" do
|
360
|
+
should "set allowBlank" do
|
361
|
+
BogusModel.expects(:extjs_allow_blank).returns(false)
|
362
|
+
@field = BogusModel.extjs_field({:name => :test}, stub())
|
363
|
+
assert_equal(false, @field[:allowBlank])
|
364
|
+
end
|
365
|
+
should "set type" do
|
366
|
+
BogusModel.expects(:extjs_type).returns('int')
|
367
|
+
@field = BogusModel.extjs_field({:name => :test}, stub())
|
368
|
+
assert_equal('int', @field[:type])
|
369
|
+
end
|
370
|
+
should "set defaultValue" do
|
371
|
+
BogusModel.expects(:extjs_default).returns(true)
|
372
|
+
@field = BogusModel.extjs_field({:name => :test}, stub())
|
373
|
+
assert_equal(true, @field[:defaultValue])
|
374
|
+
end
|
375
|
+
should "set dateFormat to c it's a date" do
|
376
|
+
BogusModel.expects(:extjs_type).returns('date')
|
377
|
+
@field = BogusModel.extjs_field({:name => :test}, stub())
|
378
|
+
assert_equal('c', @field[:dateFormat])
|
379
|
+
end
|
380
|
+
should "not touch dateFormat if it's already set" do
|
381
|
+
BogusModel.expects(:extjs_type).returns('date')
|
382
|
+
@field = BogusModel.extjs_field({:name => :test, :dateFormat => 'not-c'}, stub())
|
383
|
+
assert_equal('not-c', @field[:dateFormat])
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
context "#extjs_field with Hash config" do
|
388
|
+
should "set correct name and mapping" do
|
389
|
+
@field = BogusModel.extjs_field({:name => :son}, {:mapping => 'grandfather.father', :parent_trail => 'grandfather_father'})
|
390
|
+
assert_equal('grandfather_father_son', @field[:name])
|
391
|
+
assert_equal('grandfather.father.son', @field[:mapping])
|
392
|
+
end
|
393
|
+
should "apply config to field" do
|
394
|
+
@field = BogusModel.extjs_field({:name => :son}, {:sortDir => 'ASC'})
|
395
|
+
assert_equal('ASC', @field[:sortDir])
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
context "#extjs_get_fields_for_fieldset" do
|
400
|
+
should "return full list of columns for fieldset that was not defined, yet" do
|
401
|
+
@fields = BogusModel.extjs_get_fields_for_fieldset :not_there
|
402
|
+
assert_equal(BogusModel.process_fields(*BogusModel.extjs_column_names), @fields)
|
403
|
+
end
|
404
|
+
should "return the right fields for a fieldset that was defined before in the same class" do
|
405
|
+
BogusModel.extjs_fieldset :fieldset_was_defined, [:one]
|
406
|
+
@fields = BogusModel.extjs_get_fields_for_fieldset :fieldset_was_defined
|
407
|
+
assert_equal(BogusModel.process_fields(:one), @fields)
|
408
|
+
end
|
409
|
+
should "return the fieldset of the ancestor when it was only defined in the ancestor" do
|
410
|
+
BogusModel.extjs_fieldset :fieldset_was_defined_in_ancestor, [:one]
|
411
|
+
@fields = BogusModelChild.extjs_get_fields_for_fieldset :fieldset_was_defined_in_ancestor
|
412
|
+
assert_equal(BogusModel.process_fields(:one), @fields)
|
413
|
+
end
|
414
|
+
should "return the fieldset of the child when it was defined in the child and the ancestor" do
|
415
|
+
BogusModel.extjs_fieldset :fieldset_was_defined_in_both, [:one]
|
416
|
+
BogusModelChild.extjs_fieldset :fieldset_was_defined_in_both, [:two]
|
417
|
+
@fields = BogusModelChild.extjs_get_fields_for_fieldset :fieldset_was_defined_in_both
|
418
|
+
assert_equal(BogusModel.process_fields(:two), @fields)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
protected
|
424
|
+
def assert_array_has_item array, item_description, &blk
|
425
|
+
assert array.find {|i| blk.call(i) }, "The array #{array.inspect} should #{item_description} but it does not"
|
426
|
+
end
|
427
|
+
def assert_array_has_not_item array, item_description, &blk
|
428
|
+
assert !array.find {|i| blk.call(i) }, "The array #{array.inspect} should not #{item_description} but it does"
|
429
|
+
end
|
114
430
|
|
115
431
|
end
|
116
432
|
|
File without changes
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
|
+
require 'mocha'
|
4
5
|
|
5
6
|
require 'active_record'
|
6
7
|
require 'active_support'
|
@@ -24,9 +25,10 @@ RAILS_ENV = "test"
|
|
24
25
|
|
25
26
|
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
26
27
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
27
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
28
|
+
#ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
28
29
|
ActiveRecord::Base.establish_connection(config['test'])
|
29
30
|
|
31
|
+
|
30
32
|
##
|
31
33
|
# build User / Person models
|
32
34
|
# Move AR-specific stuff to AR test adapter
|
@@ -41,6 +43,7 @@ class User < ActiveRecord::Base
|
|
41
43
|
end
|
42
44
|
|
43
45
|
class Person < ActiveRecord::Base
|
46
|
+
has_one :user
|
44
47
|
include ExtJS::Model
|
45
48
|
end
|
46
49
|
|
@@ -58,6 +61,17 @@ class Group < ActiveRecord::Base
|
|
58
61
|
include ExtJS::Model
|
59
62
|
end
|
60
63
|
|
64
|
+
class Location < ActiveRecord::Base
|
65
|
+
has_one :address, :as => :addressable
|
66
|
+
include ExtJS::Model
|
67
|
+
end
|
68
|
+
class House < Location
|
69
|
+
end
|
70
|
+
class Address < ActiveRecord::Base
|
71
|
+
belongs_to :addressable, :polymorphic => true
|
72
|
+
include ExtJS::Model
|
73
|
+
end
|
74
|
+
|
61
75
|
class Test::Unit::TestCase
|
62
76
|
end
|
63
77
|
|
@@ -98,6 +112,26 @@ ActiveRecord::Base.connection.create_table :groups, :force => true do |table|
|
|
98
112
|
table.column :title, :string
|
99
113
|
end
|
100
114
|
|
115
|
+
##
|
116
|
+
# locations
|
117
|
+
#
|
118
|
+
ActiveRecord::Base.connection.create_table :locations, :force => true do |table|
|
119
|
+
table.column :id, :serial
|
120
|
+
table.column :name, :string
|
121
|
+
table.column :street, :string
|
122
|
+
table.column :type, :string
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# addresses
|
127
|
+
#
|
128
|
+
ActiveRecord::Base.connection.create_table :addresses, :force => true do |table|
|
129
|
+
table.column :id, :serial
|
130
|
+
table.column :addressable_type, :string
|
131
|
+
table.column :addressable_id, :integer
|
132
|
+
table.column :street, :string
|
133
|
+
end
|
134
|
+
|
101
135
|
##
|
102
136
|
# Mock a Model for testing data-types
|
103
137
|
#
|
@@ -122,4 +156,13 @@ end
|
|
122
156
|
p = Person.create(:first => "Chris", :last => "Scott", :email => "chris@scott.com")
|
123
157
|
u = User.create(:password => "1234", :person => p)
|
124
158
|
|
125
|
-
|
159
|
+
def clean klass
|
160
|
+
klass.instance_variables.each do |var_name|
|
161
|
+
if /\A@extjs_fieldsets__/ =~ var_name.to_s
|
162
|
+
klass.instance_variable_set( var_name.to_sym, nil )
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
def clean_all
|
167
|
+
[User, Person, DataType, UserGroup, Group, Location, House, Address].map { |klass| clean klass }
|
168
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extjs-mvc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Scott
|
@@ -9,11 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-15 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
17
27
|
type: :development
|
18
28
|
version_requirement:
|
19
29
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +67,7 @@ files:
|
|
57
67
|
- test/database.yml
|
58
68
|
- test/debug.log
|
59
69
|
- test/model_test.rb
|
60
|
-
- test/
|
70
|
+
- test/mongo_mapper_test.rb
|
61
71
|
- test/store_test.rb
|
62
72
|
- test/test_helper.rb
|
63
73
|
has_rdoc: true
|
@@ -87,6 +97,6 @@ rubyforge_project:
|
|
87
97
|
rubygems_version: 1.3.5
|
88
98
|
signing_key:
|
89
99
|
specification_version: 3
|
90
|
-
summary: Ruby tools
|
100
|
+
summary: Ruby ORM tools to assist with rendering Ext.data.Store
|
91
101
|
test_files: []
|
92
102
|
|