autoforme 1.11.0 → 1.13.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.
- checksums.yaml +4 -4
- data/CHANGELOG +16 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +8 -10
- data/autoforme.js +97 -56
- data/lib/autoforme/action.rb +21 -21
- data/lib/autoforme/frameworks/rails.rb +5 -1
- data/lib/autoforme/frameworks/roda.rb +10 -4
- data/lib/autoforme/frameworks/sinatra.rb +8 -3
- data/lib/autoforme/models/sequel.rb +12 -2
- data/lib/autoforme/version.rb +1 -1
- data/lib/roda/plugins/autoforme.rb +1 -1
- metadata +6 -18
- data/Rakefile +0 -69
- data/spec/all.rb +0 -2
- data/spec/associations_spec.rb +0 -802
- data/spec/basic_spec.rb +0 -1168
- data/spec/mtm_spec.rb +0 -621
- data/spec/rails_spec_helper.rb +0 -108
- data/spec/roda_spec.rb +0 -72
- data/spec/roda_spec_helper.rb +0 -86
- data/spec/sequel_spec_helper.rb +0 -42
- data/spec/sinatra_spec_helper.rb +0 -54
- data/spec/spec_helper.rb +0 -78
- data/spec/unit_spec.rb +0 -511
data/spec/unit_spec.rb
DELETED
@@ -1,511 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe AutoForme do
|
4
|
-
before(:all) do
|
5
|
-
db_setup(:artists=>[[:name, :string]])
|
6
|
-
model_setup(:Artist=>[:artists])
|
7
|
-
end
|
8
|
-
after(:all) do
|
9
|
-
Object.send(:remove_const, :Artist)
|
10
|
-
end
|
11
|
-
|
12
|
-
before do
|
13
|
-
app_setup(Artist)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should handle table class lookup" do
|
17
|
-
model.table_class_for(:browse, nil).must_equal 'table table-bordered table-striped'
|
18
|
-
framework.table_class 'foo'
|
19
|
-
model.table_class_for(:browse, nil).must_equal 'foo'
|
20
|
-
framework.table_class{|mod, type, req| "#{mod.name} #{type} #{req}"}
|
21
|
-
model.table_class_for(:browse, 1).must_equal 'Artist browse 1'
|
22
|
-
model.table_class 'baz'
|
23
|
-
model.table_class_for(:browse, nil).must_equal 'baz'
|
24
|
-
model.table_class{|type, req| "#{type} #{req}"}
|
25
|
-
model.table_class_for(:browse, :foo).must_equal 'browse foo'
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should handle per page lookup" do
|
29
|
-
model.limit_for(:browse, nil).must_equal 25
|
30
|
-
framework.per_page 1
|
31
|
-
model.limit_for(:browse, nil).must_equal 1
|
32
|
-
framework.per_page{|mod, type, req| mod.name.length + type.to_s.length + req}
|
33
|
-
model.limit_for(:browse, 3).must_equal 15
|
34
|
-
model.per_page 3
|
35
|
-
model.limit_for(:browse, nil).must_equal 3
|
36
|
-
model.per_page{|type, req| type.to_s.length + req}
|
37
|
-
model.limit_for(:browse, -1).must_equal 5
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should handle columns lookup" do
|
41
|
-
model.columns_for(:browse, nil).must_equal [:name]
|
42
|
-
framework.columns{|mod, type, req| [mod.name.to_sym, type, req]}
|
43
|
-
model.columns_for(:browse, :foo).must_equal [:Artist, :browse, :foo]
|
44
|
-
model.columns [:foo]
|
45
|
-
model.columns_for(:browse, nil).must_equal [:foo]
|
46
|
-
model.columns{|type, req| req ? [type] : [:foo]}
|
47
|
-
model.columns_for(:browse, true).must_equal [:browse]
|
48
|
-
model.columns_for(:browse, nil).must_equal [:foo]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should handle column options lookup" do
|
52
|
-
model.column_options_for(:show, nil, :foo).must_equal(:required=>false)
|
53
|
-
model.column_options_for(:browse, nil, :foo).must_equal({})
|
54
|
-
framework.column_options :foo=>{:as=>:textarea}
|
55
|
-
model.column_options_for(:browse, :bar, :foo).must_equal(:as=>:textarea)
|
56
|
-
model.column_options_for(:search_form, nil, :foo).must_equal(:required=>false)
|
57
|
-
framework.column_options :foo=>proc{|type, req| {:type=>type, :req=>req}}
|
58
|
-
model.column_options_for(:browse, :bar, :foo).must_equal(:type=>:browse, :req=>:bar)
|
59
|
-
framework.column_options{|mod, column, type, req| {mod.name.to_sym=>[type, req, column]}}
|
60
|
-
model.column_options_for(:browse, :bar, :foo).must_equal(:Artist=>[:browse, :bar, :foo])
|
61
|
-
framework.column_options{|mod, column, type, req| {5=>6}}
|
62
|
-
model.column_options :foo=>{1=>2}
|
63
|
-
model.column_options_for(:browse, nil, :foo).must_equal(1=>2, 5=>6)
|
64
|
-
model.column_options :foo=>proc{|type, req| {:type=>type, :req=>req}}
|
65
|
-
model.column_options_for(:browse, nil, :foo).must_equal(:type=>:browse, :req=>nil, 5=>6)
|
66
|
-
model.column_options{|col, type, req| {:type=>type, :req=>req, :col=>col}}
|
67
|
-
model.column_options_for(:browse, nil, :foo).must_equal(:type=>:browse, :req=>nil, :col=>:foo, 5=>6)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should handle order lookup" do
|
71
|
-
model.order_for(:browse, nil).must_be_nil
|
72
|
-
framework.order :bar
|
73
|
-
model.order_for(:browse, nil).must_equal :bar
|
74
|
-
framework.order{|mod, type, req| [mod.name.to_sym, type, req]}
|
75
|
-
model.order_for(:browse, :foo).must_equal [:Artist, :browse, :foo]
|
76
|
-
model.order [:foo]
|
77
|
-
model.order_for(:browse, nil).must_equal [:foo]
|
78
|
-
model.order{|type, req| [type, req]}
|
79
|
-
model.order_for(:browse, :foo).must_equal [:browse, :foo]
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should handle eager lookup" do
|
83
|
-
model.eager_for(:browse, nil).must_be_nil
|
84
|
-
model.eager [:foo]
|
85
|
-
model.eager_for(:browse, nil).must_equal [:foo]
|
86
|
-
model.eager{|type, req| [type, req]}
|
87
|
-
model.eager_for(:browse, 1).must_equal [:browse, 1]
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should handle eager_graph lookup" do
|
91
|
-
model.eager_graph_for(:browse, nil).must_be_nil
|
92
|
-
model.eager_graph [:foo]
|
93
|
-
model.eager_graph_for(:browse, nil).must_equal [:foo]
|
94
|
-
model.eager_graph{|type, req| [type, req]}
|
95
|
-
model.eager_graph_for(:browse, 1).must_equal [:browse, 1]
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should handle filter lookup" do
|
99
|
-
model.filter_for.must_be_nil
|
100
|
-
framework.filter{|mod| lambda{|ds, type, req| [ds, mod.name.to_sym, type, req]}}
|
101
|
-
model.filter_for.call(1, :browse, 2).must_equal [1, :Artist, :browse, 2]
|
102
|
-
model.filter{|ds, type, req| [ds, type, req]}
|
103
|
-
model.filter_for.call(1, :browse, 2).must_equal [1, :browse, 2]
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should handle redirect lookup" do
|
107
|
-
model.redirect_for.must_be_nil
|
108
|
-
framework.redirect{|mod| lambda{|obj, type, req| [obj, mod.name.to_sym, type, req]}}
|
109
|
-
model.redirect_for.call(1, :new, 2).must_equal [1, :Artist, :new, 2]
|
110
|
-
model.redirect{|obj, type, req| [obj, type, req]}
|
111
|
-
model.redirect_for.call(1, :new, 2).must_equal [1, :new, 2]
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should handle display_name lookup" do
|
115
|
-
model.display_name_for.must_be_nil
|
116
|
-
framework.display_name :foo
|
117
|
-
model.display_name_for.must_equal :foo
|
118
|
-
framework.display_name{|mod| mod.name.to_sym}
|
119
|
-
model.display_name_for.must_equal :Artist
|
120
|
-
|
121
|
-
framework.display_name{|mod| proc{|obj, type, req| "#{obj} #{type} #{req}"}}
|
122
|
-
model.object_display_name(:show, 1, :foo).must_equal 'foo show 1'
|
123
|
-
|
124
|
-
model.display_name :foo
|
125
|
-
model.display_name_for.must_equal :foo
|
126
|
-
model.display_name{|obj| obj.to_s}
|
127
|
-
model.object_display_name(:show, nil, :foo).must_equal 'foo'
|
128
|
-
model.display_name{|obj, type| "#{obj} #{type}"}
|
129
|
-
model.object_display_name(:show, nil, :foo).must_equal 'foo show'
|
130
|
-
model.display_name{|obj, type, req| "#{obj} #{type} #{req}"}
|
131
|
-
model.object_display_name(:show, 1, :foo).must_equal 'foo show 1'
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should handle supported_actions lookup" do
|
135
|
-
model.supported_action?(:new, nil).must_equal true
|
136
|
-
model.supported_action?(:edit, nil).must_equal true
|
137
|
-
model.supported_action?(:search, nil).must_equal true
|
138
|
-
framework.supported_actions [:new, :search]
|
139
|
-
model.supported_action?(:new, nil).must_equal true
|
140
|
-
model.supported_action?(:edit, nil).must_equal false
|
141
|
-
model.supported_action?(:search, nil).must_equal true
|
142
|
-
framework.supported_actions{|mod, req| req ? [:new] : []}
|
143
|
-
model.supported_action?(:new, nil).must_equal false
|
144
|
-
model.supported_action?(:new, true).must_equal true
|
145
|
-
model.supported_actions [:edit, :search]
|
146
|
-
model.supported_action?(:new, nil).must_equal false
|
147
|
-
model.supported_action?(:edit, nil).must_equal true
|
148
|
-
model.supported_action?(:search, nil).must_equal true
|
149
|
-
model.supported_actions{|req| req ? [:new] : []}
|
150
|
-
model.supported_action?(:new, nil).must_equal false
|
151
|
-
model.supported_action?(:new, true).must_equal true
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should handle mtm_associations lookup" do
|
155
|
-
model.supported_mtm_edit?('foos', nil).must_equal false
|
156
|
-
model.supported_mtm_edit?('bars', nil).must_equal false
|
157
|
-
framework.mtm_associations [:foos]
|
158
|
-
model.supported_mtm_edit?('foos', nil).must_equal true
|
159
|
-
model.supported_mtm_edit?('bars', nil).must_equal false
|
160
|
-
framework.mtm_associations{|mod, req| req ? [:foos] : [:bars]}
|
161
|
-
model.supported_mtm_edit?('foos', nil).must_equal false
|
162
|
-
model.supported_mtm_edit?('bars', nil).must_equal true
|
163
|
-
model.supported_mtm_edit?('foos', true).must_equal true
|
164
|
-
model.supported_mtm_edit?('bars', true).must_equal false
|
165
|
-
model.mtm_associations ['bars']
|
166
|
-
model.supported_mtm_edit?('foos', nil).must_equal false
|
167
|
-
model.supported_mtm_edit?('bars', nil).must_equal true
|
168
|
-
model.mtm_associations{|req| req ? ['foos'] : ['bars']}
|
169
|
-
model.supported_mtm_edit?('foos', nil).must_equal false
|
170
|
-
model.supported_mtm_edit?('bars', nil).must_equal true
|
171
|
-
model.supported_mtm_edit?('foos', true).must_equal true
|
172
|
-
model.supported_mtm_edit?('bars', true).must_equal false
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should handle inline_mtm_associations lookup" do
|
176
|
-
model.supported_mtm_update?('foos', nil).must_equal false
|
177
|
-
model.supported_mtm_update?('bars', nil).must_equal false
|
178
|
-
framework.inline_mtm_associations [:foos]
|
179
|
-
model.supported_mtm_update?('foos', nil).must_equal true
|
180
|
-
model.supported_mtm_update?('bars', nil).must_equal false
|
181
|
-
framework.inline_mtm_associations{|mod, req| req ? [:foos] : [:bars]}
|
182
|
-
model.supported_mtm_update?('foos', nil).must_equal false
|
183
|
-
model.supported_mtm_update?('bars', nil).must_equal true
|
184
|
-
model.supported_mtm_update?('foos', true).must_equal true
|
185
|
-
model.supported_mtm_update?('bars', true).must_equal false
|
186
|
-
model.inline_mtm_associations ['bars']
|
187
|
-
model.supported_mtm_update?('foos', nil).must_equal false
|
188
|
-
model.supported_mtm_update?('bars', nil).must_equal true
|
189
|
-
model.inline_mtm_associations{|req| req ? ['foos'] : ['bars']}
|
190
|
-
model.supported_mtm_update?('foos', nil).must_equal false
|
191
|
-
model.supported_mtm_update?('bars', nil).must_equal true
|
192
|
-
model.supported_mtm_update?('foos', true).must_equal true
|
193
|
-
model.supported_mtm_update?('bars', true).must_equal false
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should handle association_links lookup" do
|
197
|
-
model.association_links_for(:show, nil).must_equal []
|
198
|
-
framework.association_links :foo
|
199
|
-
model.association_links_for(:show, nil).must_equal [:foo]
|
200
|
-
framework.association_links{|mod, type, req| [mod.name.to_sym, type, req]}
|
201
|
-
model.association_links_for(:show, :foo).must_equal [:Artist, :show, :foo]
|
202
|
-
model.association_links [:bar]
|
203
|
-
model.association_links_for(:show, nil).must_equal [:bar]
|
204
|
-
model.association_links{|type, req| [type, req]}
|
205
|
-
model.association_links_for(:show, :foo).must_equal [:show, :foo]
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should handle lazy_load_association_links lookup" do
|
209
|
-
model.lazy_load_association_links?(:show, nil).must_equal false
|
210
|
-
framework.lazy_load_association_links true
|
211
|
-
model.lazy_load_association_links?(:show, nil).must_equal true
|
212
|
-
framework.lazy_load_association_links{|mod, type, req| req > 2}
|
213
|
-
model.lazy_load_association_links?(:show, 1).must_equal false
|
214
|
-
model.lazy_load_association_links?(:show, 3).must_equal true
|
215
|
-
model.lazy_load_association_links false
|
216
|
-
model.lazy_load_association_links?(:show, nil).must_equal false
|
217
|
-
model.lazy_load_association_links{|type, req| req > 2}
|
218
|
-
model.lazy_load_association_links?(:show, 1).must_equal false
|
219
|
-
model.lazy_load_association_links?(:show, 3).must_equal true
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should handle form_attributes lookup" do
|
223
|
-
model.form_attributes_for(:show, nil).must_equal({})
|
224
|
-
framework.form_attributes :class=>'foo'
|
225
|
-
model.form_attributes_for(:show, nil).must_equal(:class=>'foo')
|
226
|
-
framework.form_attributes{|mod, type, req| {:class=>"#{mod} #{type} #{req}"}}
|
227
|
-
model.form_attributes_for(:show, 1).must_equal(:class=>'Artist show 1')
|
228
|
-
|
229
|
-
framework.form_attributes :class=>'foo'
|
230
|
-
model.form_attributes :data=>"bar"
|
231
|
-
model.form_attributes_for(:show, nil).must_equal(:class=>'foo', :data=>'bar')
|
232
|
-
model.form_attributes{|type, req| {:data=>"#{type} #{req}"}}
|
233
|
-
model.form_attributes_for(:show, 1).must_equal(:class=>'foo', :data=>'show 1')
|
234
|
-
end
|
235
|
-
|
236
|
-
it "should handle form_options lookup" do
|
237
|
-
model.form_options_for(:show, nil).must_equal({})
|
238
|
-
framework.form_options :class=>'foo'
|
239
|
-
model.form_options_for(:show, nil).must_equal(:class=>'foo')
|
240
|
-
framework.form_options{|mod, type, req| {:class=>"#{mod} #{type} #{req}"}}
|
241
|
-
model.form_options_for(:show, 1).must_equal(:class=>'Artist show 1')
|
242
|
-
|
243
|
-
framework.form_options :class=>'foo'
|
244
|
-
model.form_options :data=>"bar"
|
245
|
-
model.form_options_for(:show, nil).must_equal(:class=>'foo', :data=>'bar')
|
246
|
-
model.form_options{|type, req| {:data=>"#{type} #{req}"}}
|
247
|
-
model.form_options_for(:show, 1).must_equal(:class=>'foo', :data=>'show 1')
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should handle page_header lookup" do
|
251
|
-
model.page_header_for(:show, nil).must_be_nil
|
252
|
-
framework.page_header "foo"
|
253
|
-
model.page_header_for(:show, nil).must_equal 'foo'
|
254
|
-
framework.page_header{|mod, type, req| "#{mod} #{type} #{req}"}
|
255
|
-
model.page_header_for(:show, 1).must_equal 'Artist show 1'
|
256
|
-
model.page_header "bar"
|
257
|
-
model.page_header_for(:show, nil).must_equal 'bar'
|
258
|
-
model.page_header{|type, req| "#{type} #{req}"}
|
259
|
-
model.page_header_for(:show, 1).must_equal 'show 1'
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should handle page_footer lookup" do
|
263
|
-
model.page_footer_for(:show, nil).must_be_nil
|
264
|
-
framework.page_footer "foo"
|
265
|
-
model.page_footer_for(:show, nil).must_equal 'foo'
|
266
|
-
framework.page_footer{|mod, type, req| "#{mod} #{type} #{req}"}
|
267
|
-
model.page_footer_for(:show, 1).must_equal 'Artist show 1'
|
268
|
-
model.page_footer "bar"
|
269
|
-
model.page_footer_for(:show, nil).must_equal 'bar'
|
270
|
-
model.page_footer{|type, req| "#{type} #{req}"}
|
271
|
-
model.page_footer_for(:show, 1).must_equal 'show 1'
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should handle autocompletion options" do
|
275
|
-
model.autocomplete_options({})
|
276
|
-
model.autocomplete(:type=>:show, :query=>'foo').must_equal []
|
277
|
-
a = Artist.create(:name=>'FooBar')
|
278
|
-
model.autocomplete(:type=>:show, :query=>'foo').must_equal ["#{a.id} - FooBar"]
|
279
|
-
model.autocomplete(:type=>:show, :query=>'boo').must_equal []
|
280
|
-
b = Artist.create(:name=>'BooFar')
|
281
|
-
model.autocomplete(:type=>:show, :query=>'boo').must_equal ["#{b.id} - BooFar"]
|
282
|
-
model.autocomplete(:type=>:show, :query=>'oo').sort.must_equal ["#{a.id} - FooBar", "#{b.id} - BooFar"]
|
283
|
-
|
284
|
-
framework.autocomplete_options :display=>:id
|
285
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
286
|
-
framework.autocomplete_options{|mod, type, req| {:limit=>req}}
|
287
|
-
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).must_equal ["#{a.id} - FooBar"]
|
288
|
-
model.autocomplete_options :display=>:id
|
289
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
290
|
-
|
291
|
-
framework.autocomplete_options({})
|
292
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
293
|
-
model.autocomplete_options :display=>proc{:id}
|
294
|
-
model.autocomplete(:type=>:show, :query=>b.id.to_s).must_equal ["#{b.id} - #{b.id}"]
|
295
|
-
model.autocomplete_options :limit=>1
|
296
|
-
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{a.id} - FooBar"]
|
297
|
-
model.autocomplete_options :limit=>proc{1}
|
298
|
-
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{a.id} - FooBar"]
|
299
|
-
model.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
300
|
-
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
301
|
-
|
302
|
-
model.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
303
|
-
model.autocomplete(:type=>:show, :query=>'foo').must_equal []
|
304
|
-
model.autocomplete(:type=>:show, :query=>'FooBar').must_equal ["#{a.id} - FooBar"]
|
305
|
-
|
306
|
-
model.autocomplete_options{|type, req| {:limit=>req}}
|
307
|
-
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).must_equal ["#{a.id} - FooBar"]
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should support looking up model classes when registering by name" do
|
311
|
-
framework.register_by_name
|
312
|
-
framework.model(Artist)
|
313
|
-
framework.model_class(Artist).link.must_equal 'Artist'
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
describe AutoForme do
|
318
|
-
before(:all) do
|
319
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string], [:artist_id, :integer, {:table=>:artists}]])
|
320
|
-
model_setup(:Artist=>[:artists, [[:one_to_many, :albums]]], :Album=>[:albums, [[:many_to_one, :artist]]])
|
321
|
-
end
|
322
|
-
after(:all) do
|
323
|
-
Object.send(:remove_const, :Album)
|
324
|
-
Object.send(:remove_const, :Artist)
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should handle autocompletion options with associations" do
|
328
|
-
artist = nil
|
329
|
-
model = nil
|
330
|
-
app_setup do
|
331
|
-
model Artist do
|
332
|
-
artist = self
|
333
|
-
end
|
334
|
-
model Album do
|
335
|
-
model = self
|
336
|
-
columns [:name, :artist]
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
model.association?('artist').must_equal true
|
341
|
-
artist.autocomplete_options({})
|
342
|
-
model.autocomplete(:query=>'foo', :association=>:artist).must_equal []
|
343
|
-
a = Artist.create(:name=>'FooBar')
|
344
|
-
model.autocomplete(:query=>'foo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
345
|
-
model.autocomplete(:query=>'boo', :association=>:artist).must_equal []
|
346
|
-
b = Artist.create(:name=>'BooFar')
|
347
|
-
model.autocomplete(:query=>'boo', :association=>:artist).must_equal ["#{b.id} - BooFar"]
|
348
|
-
model.autocomplete(:query=>'oo', :association=>:artist).sort.must_equal ["#{a.id} - FooBar", "#{b.id} - BooFar"]
|
349
|
-
artist.autocomplete_options :display=>:id
|
350
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artist).must_equal ["#{a.id} - #{a.id}"]
|
351
|
-
artist.autocomplete_options :display=>proc{:id}
|
352
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artist).must_equal ["#{b.id} - #{b.id}"]
|
353
|
-
artist.autocomplete_options :limit=>1
|
354
|
-
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
355
|
-
artist.autocomplete_options :limit=>proc{1}
|
356
|
-
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
357
|
-
artist.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
358
|
-
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
359
|
-
|
360
|
-
artist.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
361
|
-
model.autocomplete(:query=>'foo', :association=>:artist).must_equal []
|
362
|
-
model.autocomplete(:query=>'FooBar', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
describe AutoForme do
|
367
|
-
before(:all) do
|
368
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
369
|
-
model_setup(:Artist=>[:artists, [[:one_through_one, :album], [:many_to_many, :albums]]], :Album=>[:albums])
|
370
|
-
end
|
371
|
-
after(:all) do
|
372
|
-
Object.send(:remove_const, :Album)
|
373
|
-
Object.send(:remove_const, :Artist)
|
374
|
-
end
|
375
|
-
|
376
|
-
|
377
|
-
it "should handle not include unhandled association types in association links" do
|
378
|
-
app_setup do
|
379
|
-
model Artist do
|
380
|
-
association_links :album
|
381
|
-
end
|
382
|
-
model Album
|
383
|
-
end
|
384
|
-
|
385
|
-
artist = Artist.create(:name=>'Ar')
|
386
|
-
artist.add_album(:name=>'Album1')
|
387
|
-
visit "/Artist/association_links/#{artist.id}"
|
388
|
-
page.html.wont_include 'Album1'
|
389
|
-
click_link 'Album'
|
390
|
-
page.html.must_include 'Album1'
|
391
|
-
page.current_path.must_equal '/Album/browse'
|
392
|
-
end
|
393
|
-
end
|
394
|
-
|
395
|
-
describe AutoForme do
|
396
|
-
before(:all) do
|
397
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
398
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
399
|
-
end
|
400
|
-
after(:all) do
|
401
|
-
Object.send(:remove_const, :Album)
|
402
|
-
Object.send(:remove_const, :Artist)
|
403
|
-
end
|
404
|
-
|
405
|
-
it "should handle autocompletion options with many to many exclusions" do
|
406
|
-
artist = nil
|
407
|
-
model = nil
|
408
|
-
app_setup do
|
409
|
-
model Artist do
|
410
|
-
artist = self
|
411
|
-
end
|
412
|
-
model Album do
|
413
|
-
model = self
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
artist.autocomplete_options({})
|
418
|
-
model.autocomplete(:query=>'foo', :association=>:artists).must_equal []
|
419
|
-
a = Artist.create(:name=>'FooBar')
|
420
|
-
model.autocomplete(:query=>'foo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
421
|
-
model.autocomplete(:query=>'boo', :association=>:artists).must_equal []
|
422
|
-
b = Artist.create(:name=>'BooFar')
|
423
|
-
model.autocomplete(:query=>'boo', :association=>:artists).must_equal ["#{b.id} - BooFar"]
|
424
|
-
model.autocomplete(:query=>'oo', :association=>:artists).sort.must_equal ["#{a.id} - FooBar", "#{b.id} - BooFar"]
|
425
|
-
c = Album.create(:name=>'Quux')
|
426
|
-
c.add_artist(a)
|
427
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).sort.must_equal ["#{b.id} - BooFar"]
|
428
|
-
artist.autocomplete_options :display=>:id
|
429
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artists).must_equal ["#{a.id} - #{a.id}"]
|
430
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - #{b.id}"]
|
431
|
-
artist.autocomplete_options :display=>proc{:id}
|
432
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artists).must_equal ["#{b.id} - #{b.id}"]
|
433
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artists, :exclude=>c.id).must_equal []
|
434
|
-
artist.autocomplete_options :limit=>1
|
435
|
-
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
436
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
437
|
-
artist.autocomplete_options :limit=>proc{1}
|
438
|
-
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
439
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
440
|
-
artist.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
441
|
-
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
442
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
443
|
-
|
444
|
-
artist.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
445
|
-
model.autocomplete(:query=>'foo', :association=>:artists).must_equal []
|
446
|
-
model.autocomplete(:query=>'FooBar', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
447
|
-
model.autocomplete(:query=>'FooBar', :association=>:artists, :exclude=>c.id).must_equal []
|
448
|
-
end
|
449
|
-
end
|
450
|
-
|
451
|
-
|
452
|
-
describe AutoForme::OptsAttributes do
|
453
|
-
before do
|
454
|
-
@c = Class.new do
|
455
|
-
extend AutoForme::OptsAttributes
|
456
|
-
opts_attribute :foo
|
457
|
-
attr_accessor :opts
|
458
|
-
end
|
459
|
-
@o = @c.new
|
460
|
-
@o.opts = {}
|
461
|
-
end
|
462
|
-
|
463
|
-
it "should act as a getter if given no arguments, and setter if given arguments or a block" do
|
464
|
-
@o.foo.must_be_nil
|
465
|
-
@o.foo(1).must_equal 1
|
466
|
-
@o.foo.must_equal 1
|
467
|
-
p = proc{}
|
468
|
-
# Work around minitest bug
|
469
|
-
assert_equal @o.foo(&p), p
|
470
|
-
assert_equal @o.foo, p
|
471
|
-
end
|
472
|
-
|
473
|
-
it "should should raise an error if given more than one argument" do
|
474
|
-
proc{@o.foo(1, 2)}.must_raise(ArgumentError)
|
475
|
-
end
|
476
|
-
|
477
|
-
it "should should raise an error if given block and argument" do
|
478
|
-
proc{@o.foo(1){}}.must_raise(ArgumentError)
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
describe AutoForme do
|
483
|
-
it ".version should return a typical version string" do
|
484
|
-
AutoForme.version.must_match(/\A\d+\.\d+\.\d+\z/)
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
describe AutoForme::Model do
|
489
|
-
it "#model should raise error if underlying model is not a valid class string" do
|
490
|
-
mod = AutoForme::Model.new('artist', nil)
|
491
|
-
proc{mod.model}.must_raise AutoForme::Error
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
describe AutoForme do
|
496
|
-
before do
|
497
|
-
class << AutoForme
|
498
|
-
def require(f); end
|
499
|
-
end
|
500
|
-
end
|
501
|
-
after do
|
502
|
-
class << AutoForme
|
503
|
-
remove_method :require
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
it "should raise error when trying to use unsupported framework or model" do
|
508
|
-
proc{AutoForme.framework_class_for(:foo)}.must_raise AutoForme::Error
|
509
|
-
proc{AutoForme.model_class_for(:foo)}.must_raise AutoForme::Error
|
510
|
-
end
|
511
|
-
end
|