autoforme 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/Rakefile +15 -43
- data/lib/autoforme/action.rb +28 -2
- data/lib/autoforme/frameworks/rails.rb +7 -1
- data/lib/autoforme/frameworks/roda.rb +9 -3
- data/lib/autoforme/frameworks/sinatra.rb +10 -3
- data/lib/autoforme/model.rb +2 -2
- data/lib/autoforme/models/sequel.rb +9 -8
- data/lib/autoforme/version.rb +1 -1
- data/spec/associations_spec.rb +63 -63
- data/spec/basic_spec.rb +156 -146
- data/spec/mtm_spec.rb +67 -67
- data/spec/rails_spec_helper.rb +0 -9
- data/spec/roda_spec_helper.rb +6 -0
- data/spec/sequel_spec_helper.rb +0 -16
- data/spec/spec_helper.rb +12 -4
- data/spec/unit_spec.rb +178 -177
- metadata +59 -2
data/spec/unit_spec.rb
CHANGED
@@ -14,297 +14,297 @@ describe AutoForme do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should handle table class lookup" do
|
17
|
-
model.table_class_for(:browse, nil).
|
17
|
+
model.table_class_for(:browse, nil).must_equal 'table table-bordered table-striped'
|
18
18
|
framework.table_class 'foo'
|
19
|
-
model.table_class_for(:browse, nil).
|
19
|
+
model.table_class_for(:browse, nil).must_equal 'foo'
|
20
20
|
framework.table_class{|mod, type, req| "#{mod.name} #{type} #{req}"}
|
21
|
-
model.table_class_for(:browse, 1).
|
21
|
+
model.table_class_for(:browse, 1).must_equal 'Artist browse 1'
|
22
22
|
model.table_class 'baz'
|
23
|
-
model.table_class_for(:browse, nil).
|
23
|
+
model.table_class_for(:browse, nil).must_equal 'baz'
|
24
24
|
model.table_class{|type, req| "#{type} #{req}"}
|
25
|
-
model.table_class_for(:browse, :foo).
|
25
|
+
model.table_class_for(:browse, :foo).must_equal 'browse foo'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should handle per page lookup" do
|
29
|
-
model.limit_for(:browse, nil).
|
29
|
+
model.limit_for(:browse, nil).must_equal 25
|
30
30
|
framework.per_page 1
|
31
|
-
model.limit_for(:browse, nil).
|
31
|
+
model.limit_for(:browse, nil).must_equal 1
|
32
32
|
framework.per_page{|mod, type, req| mod.name.length + type.to_s.length + req}
|
33
|
-
model.limit_for(:browse, 3).
|
33
|
+
model.limit_for(:browse, 3).must_equal 15
|
34
34
|
model.per_page 3
|
35
|
-
model.limit_for(:browse, nil).
|
35
|
+
model.limit_for(:browse, nil).must_equal 3
|
36
36
|
model.per_page{|type, req| type.to_s.length + req}
|
37
|
-
model.limit_for(:browse, -1).
|
37
|
+
model.limit_for(:browse, -1).must_equal 5
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should handle columns lookup" do
|
41
|
-
model.columns_for(:browse, nil).
|
41
|
+
model.columns_for(:browse, nil).must_equal [:name]
|
42
42
|
framework.columns{|mod, type, req| [mod.name.to_sym, type, req]}
|
43
|
-
model.columns_for(:browse, :foo).
|
43
|
+
model.columns_for(:browse, :foo).must_equal [:Artist, :browse, :foo]
|
44
44
|
model.columns [:foo]
|
45
|
-
model.columns_for(:browse, nil).
|
45
|
+
model.columns_for(:browse, nil).must_equal [:foo]
|
46
46
|
model.columns{|type, req| req ? [type] : [:foo]}
|
47
|
-
model.columns_for(:browse, true).
|
48
|
-
model.columns_for(:browse, nil).
|
47
|
+
model.columns_for(:browse, true).must_equal [:browse]
|
48
|
+
model.columns_for(:browse, nil).must_equal [:foo]
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should handle column options lookup" do
|
52
|
-
model.column_options_for(:show, nil, :foo).
|
53
|
-
model.column_options_for(:browse, nil, :foo).
|
52
|
+
model.column_options_for(:show, nil, :foo).must_equal(:required=>false)
|
53
|
+
model.column_options_for(:browse, nil, :foo).must_equal({})
|
54
54
|
framework.column_options :foo=>{:as=>:textarea}
|
55
|
-
model.column_options_for(:browse, :bar, :foo).
|
56
|
-
model.column_options_for(:search_form, nil, :foo).
|
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
57
|
framework.column_options :foo=>proc{|type, req| {:type=>type, :req=>req}}
|
58
|
-
model.column_options_for(:browse, :bar, :foo).
|
58
|
+
model.column_options_for(:browse, :bar, :foo).must_equal(:type=>:browse, :req=>:bar)
|
59
59
|
framework.column_options{|mod, column, type, req| {mod.name.to_sym=>[type, req, column]}}
|
60
|
-
model.column_options_for(:browse, :bar, :foo).
|
60
|
+
model.column_options_for(:browse, :bar, :foo).must_equal(:Artist=>[:browse, :bar, :foo])
|
61
61
|
framework.column_options{|mod, column, type, req| {5=>6}}
|
62
62
|
model.column_options :foo=>{1=>2}
|
63
|
-
model.column_options_for(:browse, nil, :foo).
|
63
|
+
model.column_options_for(:browse, nil, :foo).must_equal(1=>2, 5=>6)
|
64
64
|
model.column_options :foo=>proc{|type, req| {:type=>type, :req=>req}}
|
65
|
-
model.column_options_for(:browse, nil, :foo).
|
65
|
+
model.column_options_for(:browse, nil, :foo).must_equal(:type=>:browse, :req=>nil, 5=>6)
|
66
66
|
model.column_options{|col, type, req| {:type=>type, :req=>req, :col=>col}}
|
67
|
-
model.column_options_for(:browse, nil, :foo).
|
67
|
+
model.column_options_for(:browse, nil, :foo).must_equal(:type=>:browse, :req=>nil, :col=>:foo, 5=>6)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should handle order lookup" do
|
71
|
-
model.order_for(:browse, nil).
|
71
|
+
model.order_for(:browse, nil).must_equal nil
|
72
72
|
framework.order :bar
|
73
|
-
model.order_for(:browse, nil).
|
73
|
+
model.order_for(:browse, nil).must_equal :bar
|
74
74
|
framework.order{|mod, type, req| [mod.name.to_sym, type, req]}
|
75
|
-
model.order_for(:browse, :foo).
|
75
|
+
model.order_for(:browse, :foo).must_equal [:Artist, :browse, :foo]
|
76
76
|
model.order [:foo]
|
77
|
-
model.order_for(:browse, nil).
|
77
|
+
model.order_for(:browse, nil).must_equal [:foo]
|
78
78
|
model.order{|type, req| [type, req]}
|
79
|
-
model.order_for(:browse, :foo).
|
79
|
+
model.order_for(:browse, :foo).must_equal [:browse, :foo]
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should handle eager lookup" do
|
83
|
-
model.eager_for(:browse, nil).
|
83
|
+
model.eager_for(:browse, nil).must_equal nil
|
84
84
|
model.eager [:foo]
|
85
|
-
model.eager_for(:browse, nil).
|
85
|
+
model.eager_for(:browse, nil).must_equal [:foo]
|
86
86
|
model.eager{|type, req| [type, req]}
|
87
|
-
model.eager_for(:browse, 1).
|
87
|
+
model.eager_for(:browse, 1).must_equal [:browse, 1]
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should handle eager_graph lookup" do
|
91
|
-
model.eager_graph_for(:browse, nil).
|
91
|
+
model.eager_graph_for(:browse, nil).must_equal nil
|
92
92
|
model.eager_graph [:foo]
|
93
|
-
model.eager_graph_for(:browse, nil).
|
93
|
+
model.eager_graph_for(:browse, nil).must_equal [:foo]
|
94
94
|
model.eager_graph{|type, req| [type, req]}
|
95
|
-
model.eager_graph_for(:browse, 1).
|
95
|
+
model.eager_graph_for(:browse, 1).must_equal [:browse, 1]
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should handle filter lookup" do
|
99
|
-
model.filter_for.
|
99
|
+
model.filter_for.must_equal nil
|
100
100
|
framework.filter{|mod| lambda{|ds, type, req| [ds, mod.name.to_sym, type, req]}}
|
101
|
-
model.filter_for.call(1, :browse, 2).
|
101
|
+
model.filter_for.call(1, :browse, 2).must_equal [1, :Artist, :browse, 2]
|
102
102
|
model.filter{|ds, type, req| [ds, type, req]}
|
103
|
-
model.filter_for.call(1, :browse, 2).
|
103
|
+
model.filter_for.call(1, :browse, 2).must_equal [1, :browse, 2]
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should handle redirect lookup" do
|
107
|
-
model.redirect_for.
|
107
|
+
model.redirect_for.must_equal nil
|
108
108
|
framework.redirect{|mod| lambda{|obj, type, req| [obj, mod.name.to_sym, type, req]}}
|
109
|
-
model.redirect_for.call(1, :new, 2).
|
109
|
+
model.redirect_for.call(1, :new, 2).must_equal [1, :Artist, :new, 2]
|
110
110
|
model.redirect{|obj, type, req| [obj, type, req]}
|
111
|
-
model.redirect_for.call(1, :new, 2).
|
111
|
+
model.redirect_for.call(1, :new, 2).must_equal [1, :new, 2]
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should handle display_name lookup" do
|
115
|
-
model.display_name_for.
|
115
|
+
model.display_name_for.must_equal nil
|
116
116
|
framework.display_name :foo
|
117
|
-
model.display_name_for.
|
117
|
+
model.display_name_for.must_equal :foo
|
118
118
|
framework.display_name{|mod| mod.name.to_sym}
|
119
|
-
model.display_name_for.
|
119
|
+
model.display_name_for.must_equal :Artist
|
120
120
|
|
121
121
|
framework.display_name{|mod| proc{|obj, type, req| "#{obj} #{type} #{req}"}}
|
122
|
-
model.object_display_name(:show, 1, :foo).
|
122
|
+
model.object_display_name(:show, 1, :foo).must_equal 'foo show 1'
|
123
123
|
|
124
124
|
model.display_name :foo
|
125
|
-
model.display_name_for.
|
125
|
+
model.display_name_for.must_equal :foo
|
126
126
|
model.display_name{|obj| obj.to_s}
|
127
|
-
model.object_display_name(:show, nil, :foo).
|
127
|
+
model.object_display_name(:show, nil, :foo).must_equal 'foo'
|
128
128
|
model.display_name{|obj, type| "#{obj} #{type}"}
|
129
|
-
model.object_display_name(:show, nil, :foo).
|
129
|
+
model.object_display_name(:show, nil, :foo).must_equal 'foo show'
|
130
130
|
model.display_name{|obj, type, req| "#{obj} #{type} #{req}"}
|
131
|
-
model.object_display_name(:show, 1, :foo).
|
131
|
+
model.object_display_name(:show, 1, :foo).must_equal 'foo show 1'
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should handle supported_actions lookup" do
|
135
|
-
model.supported_action?(:new, nil).
|
136
|
-
model.supported_action?(:edit, nil).
|
137
|
-
model.supported_action?(:search, nil).
|
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
138
|
framework.supported_actions [:new, :search]
|
139
|
-
model.supported_action?(:new, nil).
|
140
|
-
model.supported_action?(:edit, nil).
|
141
|
-
model.supported_action?(:search, nil).
|
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
142
|
framework.supported_actions{|mod, req| req ? [:new] : []}
|
143
|
-
model.supported_action?(:new, nil).
|
144
|
-
model.supported_action?(:new, true).
|
143
|
+
model.supported_action?(:new, nil).must_equal false
|
144
|
+
model.supported_action?(:new, true).must_equal true
|
145
145
|
model.supported_actions [:edit, :search]
|
146
|
-
model.supported_action?(:new, nil).
|
147
|
-
model.supported_action?(:edit, nil).
|
148
|
-
model.supported_action?(:search, nil).
|
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
149
|
model.supported_actions{|req| req ? [:new] : []}
|
150
|
-
model.supported_action?(:new, nil).
|
151
|
-
model.supported_action?(:new, true).
|
150
|
+
model.supported_action?(:new, nil).must_equal false
|
151
|
+
model.supported_action?(:new, true).must_equal true
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should handle mtm_associations lookup" do
|
155
|
-
model.supported_mtm_edit?('foos', nil).
|
156
|
-
model.supported_mtm_edit?('bars', nil).
|
155
|
+
model.supported_mtm_edit?('foos', nil).must_equal false
|
156
|
+
model.supported_mtm_edit?('bars', nil).must_equal false
|
157
157
|
framework.mtm_associations [:foos]
|
158
|
-
model.supported_mtm_edit?('foos', nil).
|
159
|
-
model.supported_mtm_edit?('bars', nil).
|
158
|
+
model.supported_mtm_edit?('foos', nil).must_equal true
|
159
|
+
model.supported_mtm_edit?('bars', nil).must_equal false
|
160
160
|
framework.mtm_associations{|mod, req| req ? [:foos] : [:bars]}
|
161
|
-
model.supported_mtm_edit?('foos', nil).
|
162
|
-
model.supported_mtm_edit?('bars', nil).
|
163
|
-
model.supported_mtm_edit?('foos', true).
|
164
|
-
model.supported_mtm_edit?('bars', true).
|
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
165
|
model.mtm_associations ['bars']
|
166
|
-
model.supported_mtm_edit?('foos', nil).
|
167
|
-
model.supported_mtm_edit?('bars', nil).
|
166
|
+
model.supported_mtm_edit?('foos', nil).must_equal false
|
167
|
+
model.supported_mtm_edit?('bars', nil).must_equal true
|
168
168
|
model.mtm_associations{|req| req ? ['foos'] : ['bars']}
|
169
|
-
model.supported_mtm_edit?('foos', nil).
|
170
|
-
model.supported_mtm_edit?('bars', nil).
|
171
|
-
model.supported_mtm_edit?('foos', true).
|
172
|
-
model.supported_mtm_edit?('bars', true).
|
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
173
|
end
|
174
174
|
|
175
175
|
it "should handle inline_mtm_associations lookup" do
|
176
|
-
model.supported_mtm_update?('foos', nil).
|
177
|
-
model.supported_mtm_update?('bars', nil).
|
176
|
+
model.supported_mtm_update?('foos', nil).must_equal false
|
177
|
+
model.supported_mtm_update?('bars', nil).must_equal false
|
178
178
|
framework.inline_mtm_associations [:foos]
|
179
|
-
model.supported_mtm_update?('foos', nil).
|
180
|
-
model.supported_mtm_update?('bars', nil).
|
179
|
+
model.supported_mtm_update?('foos', nil).must_equal true
|
180
|
+
model.supported_mtm_update?('bars', nil).must_equal false
|
181
181
|
framework.inline_mtm_associations{|mod, req| req ? [:foos] : [:bars]}
|
182
|
-
model.supported_mtm_update?('foos', nil).
|
183
|
-
model.supported_mtm_update?('bars', nil).
|
184
|
-
model.supported_mtm_update?('foos', true).
|
185
|
-
model.supported_mtm_update?('bars', true).
|
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
186
|
model.inline_mtm_associations ['bars']
|
187
|
-
model.supported_mtm_update?('foos', nil).
|
188
|
-
model.supported_mtm_update?('bars', nil).
|
187
|
+
model.supported_mtm_update?('foos', nil).must_equal false
|
188
|
+
model.supported_mtm_update?('bars', nil).must_equal true
|
189
189
|
model.inline_mtm_associations{|req| req ? ['foos'] : ['bars']}
|
190
|
-
model.supported_mtm_update?('foos', nil).
|
191
|
-
model.supported_mtm_update?('bars', nil).
|
192
|
-
model.supported_mtm_update?('foos', true).
|
193
|
-
model.supported_mtm_update?('bars', true).
|
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
194
|
end
|
195
195
|
|
196
196
|
it "should handle association_links lookup" do
|
197
|
-
model.association_links_for(:show, nil).
|
197
|
+
model.association_links_for(:show, nil).must_equal []
|
198
198
|
framework.association_links :foo
|
199
|
-
model.association_links_for(:show, nil).
|
199
|
+
model.association_links_for(:show, nil).must_equal [:foo]
|
200
200
|
framework.association_links{|mod, type, req| [mod.name.to_sym, type, req]}
|
201
|
-
model.association_links_for(:show, :foo).
|
201
|
+
model.association_links_for(:show, :foo).must_equal [:Artist, :show, :foo]
|
202
202
|
model.association_links [:bar]
|
203
|
-
model.association_links_for(:show, nil).
|
203
|
+
model.association_links_for(:show, nil).must_equal [:bar]
|
204
204
|
model.association_links{|type, req| [type, req]}
|
205
|
-
model.association_links_for(:show, :foo).
|
205
|
+
model.association_links_for(:show, :foo).must_equal [:show, :foo]
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should handle lazy_load_association_links lookup" do
|
209
|
-
model.lazy_load_association_links?(:show, nil).
|
209
|
+
model.lazy_load_association_links?(:show, nil).must_equal false
|
210
210
|
framework.lazy_load_association_links true
|
211
|
-
model.lazy_load_association_links?(:show, nil).
|
211
|
+
model.lazy_load_association_links?(:show, nil).must_equal true
|
212
212
|
framework.lazy_load_association_links{|mod, type, req| req > 2}
|
213
|
-
model.lazy_load_association_links?(:show, 1).
|
214
|
-
model.lazy_load_association_links?(:show, 3).
|
213
|
+
model.lazy_load_association_links?(:show, 1).must_equal false
|
214
|
+
model.lazy_load_association_links?(:show, 3).must_equal true
|
215
215
|
model.lazy_load_association_links false
|
216
|
-
model.lazy_load_association_links?(:show, nil).
|
216
|
+
model.lazy_load_association_links?(:show, nil).must_equal false
|
217
217
|
model.lazy_load_association_links{|type, req| req > 2}
|
218
|
-
model.lazy_load_association_links?(:show, 1).
|
219
|
-
model.lazy_load_association_links?(:show, 3).
|
218
|
+
model.lazy_load_association_links?(:show, 1).must_equal false
|
219
|
+
model.lazy_load_association_links?(:show, 3).must_equal true
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should handle form_attributes lookup" do
|
223
|
-
model.form_attributes_for(:show, nil).
|
223
|
+
model.form_attributes_for(:show, nil).must_equal({})
|
224
224
|
framework.form_attributes :class=>'foo'
|
225
|
-
model.form_attributes_for(:show, nil).
|
225
|
+
model.form_attributes_for(:show, nil).must_equal(:class=>'foo')
|
226
226
|
framework.form_attributes{|mod, type, req| {:class=>"#{mod} #{type} #{req}"}}
|
227
|
-
model.form_attributes_for(:show, 1).
|
227
|
+
model.form_attributes_for(:show, 1).must_equal(:class=>'Artist show 1')
|
228
228
|
|
229
229
|
framework.form_attributes :class=>'foo'
|
230
230
|
model.form_attributes :data=>"bar"
|
231
|
-
model.form_attributes_for(:show, nil).
|
231
|
+
model.form_attributes_for(:show, nil).must_equal(:class=>'foo', :data=>'bar')
|
232
232
|
model.form_attributes{|type, req| {:data=>"#{type} #{req}"}}
|
233
|
-
model.form_attributes_for(:show, 1).
|
233
|
+
model.form_attributes_for(:show, 1).must_equal(:class=>'foo', :data=>'show 1')
|
234
234
|
end
|
235
235
|
|
236
236
|
it "should handle form_options lookup" do
|
237
|
-
model.form_options_for(:show, nil).
|
237
|
+
model.form_options_for(:show, nil).must_equal({})
|
238
238
|
framework.form_options :class=>'foo'
|
239
|
-
model.form_options_for(:show, nil).
|
239
|
+
model.form_options_for(:show, nil).must_equal(:class=>'foo')
|
240
240
|
framework.form_options{|mod, type, req| {:class=>"#{mod} #{type} #{req}"}}
|
241
|
-
model.form_options_for(:show, 1).
|
241
|
+
model.form_options_for(:show, 1).must_equal(:class=>'Artist show 1')
|
242
242
|
|
243
243
|
framework.form_options :class=>'foo'
|
244
244
|
model.form_options :data=>"bar"
|
245
|
-
model.form_options_for(:show, nil).
|
245
|
+
model.form_options_for(:show, nil).must_equal(:class=>'foo', :data=>'bar')
|
246
246
|
model.form_options{|type, req| {:data=>"#{type} #{req}"}}
|
247
|
-
model.form_options_for(:show, 1).
|
247
|
+
model.form_options_for(:show, 1).must_equal(:class=>'foo', :data=>'show 1')
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should handle page_header lookup" do
|
251
|
-
model.page_header_for(:show, nil).
|
251
|
+
model.page_header_for(:show, nil).must_equal nil
|
252
252
|
framework.page_header "foo"
|
253
|
-
model.page_header_for(:show, nil).
|
253
|
+
model.page_header_for(:show, nil).must_equal 'foo'
|
254
254
|
framework.page_header{|mod, type, req| "#{mod} #{type} #{req}"}
|
255
|
-
model.page_header_for(:show, 1).
|
255
|
+
model.page_header_for(:show, 1).must_equal 'Artist show 1'
|
256
256
|
model.page_header "bar"
|
257
|
-
model.page_header_for(:show, nil).
|
257
|
+
model.page_header_for(:show, nil).must_equal 'bar'
|
258
258
|
model.page_header{|type, req| "#{type} #{req}"}
|
259
|
-
model.page_header_for(:show, 1).
|
259
|
+
model.page_header_for(:show, 1).must_equal 'show 1'
|
260
260
|
end
|
261
261
|
|
262
262
|
it "should handle page_footer lookup" do
|
263
|
-
model.page_footer_for(:show, nil).
|
263
|
+
model.page_footer_for(:show, nil).must_equal nil
|
264
264
|
framework.page_footer "foo"
|
265
|
-
model.page_footer_for(:show, nil).
|
265
|
+
model.page_footer_for(:show, nil).must_equal 'foo'
|
266
266
|
framework.page_footer{|mod, type, req| "#{mod} #{type} #{req}"}
|
267
|
-
model.page_footer_for(:show, 1).
|
267
|
+
model.page_footer_for(:show, 1).must_equal 'Artist show 1'
|
268
268
|
model.page_footer "bar"
|
269
|
-
model.page_footer_for(:show, nil).
|
269
|
+
model.page_footer_for(:show, nil).must_equal 'bar'
|
270
270
|
model.page_footer{|type, req| "#{type} #{req}"}
|
271
|
-
model.page_footer_for(:show, 1).
|
271
|
+
model.page_footer_for(:show, 1).must_equal 'show 1'
|
272
272
|
end
|
273
273
|
|
274
274
|
it "should handle autocompletion options" do
|
275
275
|
model.autocomplete_options({})
|
276
|
-
model.autocomplete(:type=>:show, :query=>'foo').
|
276
|
+
model.autocomplete(:type=>:show, :query=>'foo').must_equal []
|
277
277
|
a = Artist.create(:name=>'FooBar')
|
278
|
-
model.autocomplete(:type=>:show, :query=>'foo').
|
279
|
-
model.autocomplete(:type=>:show, :query=>'boo').
|
278
|
+
model.autocomplete(:type=>:show, :query=>'foo').must_equal ["#{a.id} - FooBar"]
|
279
|
+
model.autocomplete(:type=>:show, :query=>'boo').must_equal []
|
280
280
|
b = Artist.create(:name=>'BooFar')
|
281
|
-
model.autocomplete(:type=>:show, :query=>'boo').
|
282
|
-
model.autocomplete(:type=>:show, :query=>'oo').sort.
|
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
283
|
|
284
284
|
framework.autocomplete_options :display=>:id
|
285
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).
|
285
|
+
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
286
286
|
framework.autocomplete_options{|mod, type, req| {:limit=>req}}
|
287
|
-
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).
|
287
|
+
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).must_equal ["#{a.id} - FooBar"]
|
288
288
|
model.autocomplete_options :display=>:id
|
289
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).
|
289
|
+
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
290
290
|
|
291
291
|
framework.autocomplete_options({})
|
292
|
-
model.autocomplete(:type=>:show, :query=>a.id.to_s).
|
292
|
+
model.autocomplete(:type=>:show, :query=>a.id.to_s).must_equal ["#{a.id} - #{a.id}"]
|
293
293
|
model.autocomplete_options :display=>proc{:id}
|
294
|
-
model.autocomplete(:type=>:show, :query=>b.id.to_s).
|
294
|
+
model.autocomplete(:type=>:show, :query=>b.id.to_s).must_equal ["#{b.id} - #{b.id}"]
|
295
295
|
model.autocomplete_options :limit=>1
|
296
|
-
model.autocomplete(:type=>:show, :query=>'oo').
|
296
|
+
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{a.id} - FooBar"]
|
297
297
|
model.autocomplete_options :limit=>proc{1}
|
298
|
-
model.autocomplete(:type=>:show, :query=>'oo').
|
298
|
+
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{a.id} - FooBar"]
|
299
299
|
model.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
300
|
-
model.autocomplete(:type=>:show, :query=>'oo').
|
300
|
+
model.autocomplete(:type=>:show, :query=>'oo').must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
301
301
|
|
302
302
|
model.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
303
|
-
model.autocomplete(:type=>:show, :query=>'foo').
|
304
|
-
model.autocomplete(:type=>:show, :query=>'FooBar').
|
303
|
+
model.autocomplete(:type=>:show, :query=>'foo').must_equal []
|
304
|
+
model.autocomplete(:type=>:show, :query=>'FooBar').must_equal ["#{a.id} - FooBar"]
|
305
305
|
|
306
306
|
model.autocomplete_options{|type, req| {:limit=>req}}
|
307
|
-
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).
|
307
|
+
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).must_equal ["#{a.id} - FooBar"]
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
@@ -332,27 +332,27 @@ describe AutoForme do
|
|
332
332
|
end
|
333
333
|
|
334
334
|
artist.autocomplete_options({})
|
335
|
-
model.autocomplete(:query=>'foo', :association=>:artist).
|
335
|
+
model.autocomplete(:query=>'foo', :association=>:artist).must_equal []
|
336
336
|
a = Artist.create(:name=>'FooBar')
|
337
|
-
model.autocomplete(:query=>'foo', :association=>:artist).
|
338
|
-
model.autocomplete(:query=>'boo', :association=>:artist).
|
337
|
+
model.autocomplete(:query=>'foo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
338
|
+
model.autocomplete(:query=>'boo', :association=>:artist).must_equal []
|
339
339
|
b = Artist.create(:name=>'BooFar')
|
340
|
-
model.autocomplete(:query=>'boo', :association=>:artist).
|
341
|
-
model.autocomplete(:query=>'oo', :association=>:artist).sort.
|
340
|
+
model.autocomplete(:query=>'boo', :association=>:artist).must_equal ["#{b.id} - BooFar"]
|
341
|
+
model.autocomplete(:query=>'oo', :association=>:artist).sort.must_equal ["#{a.id} - FooBar", "#{b.id} - BooFar"]
|
342
342
|
artist.autocomplete_options :display=>:id
|
343
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artist).
|
343
|
+
model.autocomplete(:query=>a.id.to_s, :association=>:artist).must_equal ["#{a.id} - #{a.id}"]
|
344
344
|
artist.autocomplete_options :display=>proc{:id}
|
345
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artist).
|
345
|
+
model.autocomplete(:query=>b.id.to_s, :association=>:artist).must_equal ["#{b.id} - #{b.id}"]
|
346
346
|
artist.autocomplete_options :limit=>1
|
347
|
-
model.autocomplete(:query=>'oo', :association=>:artist).
|
347
|
+
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
348
348
|
artist.autocomplete_options :limit=>proc{1}
|
349
|
-
model.autocomplete(:query=>'oo', :association=>:artist).
|
349
|
+
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
350
350
|
artist.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
351
|
-
model.autocomplete(:query=>'oo', :association=>:artist).
|
351
|
+
model.autocomplete(:query=>'oo', :association=>:artist).must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
352
352
|
|
353
353
|
artist.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
354
|
-
model.autocomplete(:query=>'foo', :association=>:artist).
|
355
|
-
model.autocomplete(:query=>'FooBar', :association=>:artist).
|
354
|
+
model.autocomplete(:query=>'foo', :association=>:artist).must_equal []
|
355
|
+
model.autocomplete(:query=>'FooBar', :association=>:artist).must_equal ["#{a.id} - FooBar"]
|
356
356
|
end
|
357
357
|
end
|
358
358
|
|
@@ -379,36 +379,36 @@ describe AutoForme do
|
|
379
379
|
end
|
380
380
|
|
381
381
|
artist.autocomplete_options({})
|
382
|
-
model.autocomplete(:query=>'foo', :association=>:artists).
|
382
|
+
model.autocomplete(:query=>'foo', :association=>:artists).must_equal []
|
383
383
|
a = Artist.create(:name=>'FooBar')
|
384
|
-
model.autocomplete(:query=>'foo', :association=>:artists).
|
385
|
-
model.autocomplete(:query=>'boo', :association=>:artists).
|
384
|
+
model.autocomplete(:query=>'foo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
385
|
+
model.autocomplete(:query=>'boo', :association=>:artists).must_equal []
|
386
386
|
b = Artist.create(:name=>'BooFar')
|
387
|
-
model.autocomplete(:query=>'boo', :association=>:artists).
|
388
|
-
model.autocomplete(:query=>'oo', :association=>:artists).sort.
|
387
|
+
model.autocomplete(:query=>'boo', :association=>:artists).must_equal ["#{b.id} - BooFar"]
|
388
|
+
model.autocomplete(:query=>'oo', :association=>:artists).sort.must_equal ["#{a.id} - FooBar", "#{b.id} - BooFar"]
|
389
389
|
c = Album.create(:name=>'Quux')
|
390
390
|
c.add_artist(a)
|
391
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).sort.
|
391
|
+
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).sort.must_equal ["#{b.id} - BooFar"]
|
392
392
|
artist.autocomplete_options :display=>:id
|
393
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artists).
|
394
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artists, :exclude=>c.id).
|
393
|
+
model.autocomplete(:query=>a.id.to_s, :association=>:artists).must_equal ["#{a.id} - #{a.id}"]
|
394
|
+
model.autocomplete(:query=>b.id.to_s, :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - #{b.id}"]
|
395
395
|
artist.autocomplete_options :display=>proc{:id}
|
396
|
-
model.autocomplete(:query=>b.id.to_s, :association=>:artists).
|
397
|
-
model.autocomplete(:query=>a.id.to_s, :association=>:artists, :exclude=>c.id).
|
396
|
+
model.autocomplete(:query=>b.id.to_s, :association=>:artists).must_equal ["#{b.id} - #{b.id}"]
|
397
|
+
model.autocomplete(:query=>a.id.to_s, :association=>:artists, :exclude=>c.id).must_equal []
|
398
398
|
artist.autocomplete_options :limit=>1
|
399
|
-
model.autocomplete(:query=>'oo', :association=>:artists).
|
400
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).
|
399
|
+
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
400
|
+
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
401
401
|
artist.autocomplete_options :limit=>proc{1}
|
402
|
-
model.autocomplete(:query=>'oo', :association=>:artists).
|
403
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).
|
402
|
+
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
403
|
+
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
404
404
|
artist.autocomplete_options :callback=>proc{|ds, opts| ds.reverse_order(:id)}
|
405
|
-
model.autocomplete(:query=>'oo', :association=>:artists).
|
406
|
-
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).
|
405
|
+
model.autocomplete(:query=>'oo', :association=>:artists).must_equal ["#{b.id} - BooFar", "#{a.id} - FooBar"]
|
406
|
+
model.autocomplete(:query=>'oo', :association=>:artists, :exclude=>c.id).must_equal ["#{b.id} - BooFar"]
|
407
407
|
|
408
408
|
artist.autocomplete_options :filter=>proc{|ds, opts| ds.where(:name=>opts[:query])}
|
409
|
-
model.autocomplete(:query=>'foo', :association=>:artists).
|
410
|
-
model.autocomplete(:query=>'FooBar', :association=>:artists).
|
411
|
-
model.autocomplete(:query=>'FooBar', :association=>:artists, :exclude=>c.id).
|
409
|
+
model.autocomplete(:query=>'foo', :association=>:artists).must_equal []
|
410
|
+
model.autocomplete(:query=>'FooBar', :association=>:artists).must_equal ["#{a.id} - FooBar"]
|
411
|
+
model.autocomplete(:query=>'FooBar', :association=>:artists, :exclude=>c.id).must_equal []
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
@@ -425,25 +425,26 @@ describe AutoForme::OptsAttributes do
|
|
425
425
|
end
|
426
426
|
|
427
427
|
it "should act as a getter if given no arguments, and setter if given arguments or a block" do
|
428
|
-
@o.foo.
|
429
|
-
@o.foo(1).
|
430
|
-
@o.foo.
|
428
|
+
@o.foo.must_equal nil
|
429
|
+
@o.foo(1).must_equal 1
|
430
|
+
@o.foo.must_equal 1
|
431
431
|
p = proc{}
|
432
|
-
|
433
|
-
@o.foo
|
432
|
+
# Work around minitest bug
|
433
|
+
assert_equal @o.foo(&p), p
|
434
|
+
assert_equal @o.foo, p
|
434
435
|
end
|
435
436
|
|
436
437
|
it "should should raise an error if given more than one argument" do
|
437
|
-
proc{@o.foo(1, 2)}.
|
438
|
+
proc{@o.foo(1, 2)}.must_raise(ArgumentError)
|
438
439
|
end
|
439
440
|
|
440
441
|
it "should should raise an error if given block and argument" do
|
441
|
-
proc{@o.foo(1){}}.
|
442
|
+
proc{@o.foo(1){}}.must_raise(ArgumentError)
|
442
443
|
end
|
443
444
|
end
|
444
445
|
|
445
446
|
describe AutoForme do
|
446
447
|
it ".version should return a typical version string" do
|
447
|
-
AutoForme.version.
|
448
|
+
AutoForme.version.must_match /\A\d+\.\d+\.\d+\z/
|
448
449
|
end
|
449
450
|
end
|