autoforme 1.1.0 → 1.2.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 +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/mtm_spec.rb
CHANGED
@@ -17,9 +17,9 @@ describe AutoForme do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
visit("/Artist/browse")
|
20
|
-
page.html.
|
20
|
+
page.html.wont_match /MTM/
|
21
21
|
visit("/Artist/mtm_edit")
|
22
|
-
page.html.
|
22
|
+
page.html.must_match /Unhandled Request/
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should have basic many to many association editing working" do
|
@@ -36,28 +36,28 @@ describe AutoForme do
|
|
36
36
|
Album.create(:name=>'Album3')
|
37
37
|
|
38
38
|
visit("/Artist/mtm_edit")
|
39
|
-
page.title.
|
39
|
+
page.title.must_equal 'Artist - Many To Many Edit'
|
40
40
|
select("Artist1")
|
41
41
|
click_button "Edit"
|
42
42
|
|
43
|
-
find('h2').text.
|
44
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
45
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
43
|
+
find('h2').text.must_equal 'Edit Albums for Artist1'
|
44
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
45
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
46
46
|
select("Album1", :from=>"Associate With")
|
47
47
|
click_button "Update"
|
48
|
-
page.html.
|
49
|
-
Artist.first.albums.map{|x| x.name}.
|
48
|
+
page.html.must_match /Updated albums association for Artist/
|
49
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
50
50
|
|
51
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
52
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
51
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
52
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
53
53
|
select("Album2", :from=>"Associate With")
|
54
54
|
select("Album3", :from=>"Associate With")
|
55
55
|
select("Album1", :from=>"Disassociate From")
|
56
56
|
click_button "Update"
|
57
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
57
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
58
58
|
|
59
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
60
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
59
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
60
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should have many to many association editing working with autocompletion" do
|
@@ -79,23 +79,23 @@ describe AutoForme do
|
|
79
79
|
select("Artist1")
|
80
80
|
click_button "Edit"
|
81
81
|
|
82
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
82
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
83
83
|
fill_in "Associate With", :with=>a1.id
|
84
84
|
click_button "Update"
|
85
|
-
page.html.
|
86
|
-
Artist.first.albums.map{|x| x.name}.
|
85
|
+
page.html.must_match /Updated albums association for Artist/
|
86
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
87
87
|
|
88
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
88
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
89
89
|
fill_in "Associate With", :with=>a2.id
|
90
90
|
select("Album1", :from=>"Disassociate From")
|
91
91
|
click_button "Update"
|
92
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
92
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
93
93
|
|
94
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
94
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2"]
|
95
95
|
select("Album2", :from=>"Disassociate From")
|
96
96
|
click_button "Update"
|
97
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
98
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
97
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal []
|
98
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should have inline many to many association editing working" do
|
@@ -116,19 +116,19 @@ describe AutoForme do
|
|
116
116
|
click_button "Edit"
|
117
117
|
select 'Album1'
|
118
118
|
click_button 'Add'
|
119
|
-
page.html.
|
120
|
-
Artist.first.albums.map{|x| x.name}.
|
119
|
+
page.html.must_match /Updated albums association for Artist/
|
120
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
121
121
|
|
122
122
|
select 'Album2'
|
123
123
|
click_button 'Add'
|
124
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.
|
124
|
+
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album1 Album2'
|
125
125
|
|
126
126
|
click_button 'Remove', :match=>:first
|
127
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
127
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
128
128
|
|
129
129
|
select 'Album3'
|
130
130
|
click_button 'Add'
|
131
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.
|
131
|
+
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album2 Album3'
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should have inline many to many association editing working with autocompletion" do
|
@@ -151,19 +151,19 @@ describe AutoForme do
|
|
151
151
|
click_button "Edit"
|
152
152
|
fill_in 'Albums', :with=>a1.id.to_s
|
153
153
|
click_button 'Add'
|
154
|
-
page.html.
|
155
|
-
Artist.first.albums.map{|x| x.name}.
|
154
|
+
page.html.must_match /Updated albums association for Artist/
|
155
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
156
156
|
|
157
157
|
fill_in 'Albums', :with=>a2.id.to_s
|
158
158
|
click_button 'Add'
|
159
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.
|
159
|
+
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album1 Album2'
|
160
160
|
|
161
161
|
click_button 'Remove', :match=>:first
|
162
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
162
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
163
163
|
|
164
164
|
fill_in 'Albums', :with=>a3.id.to_s
|
165
165
|
click_button 'Add'
|
166
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.
|
166
|
+
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album2 Album3'
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should have working many to many association links on show and edit pages" do
|
@@ -184,7 +184,7 @@ describe AutoForme do
|
|
184
184
|
click_link 'Edit'
|
185
185
|
select 'Artist1'
|
186
186
|
click_button 'Edit'
|
187
|
-
page.html.
|
187
|
+
page.html.wont_match /Albums/
|
188
188
|
|
189
189
|
visit("/Album/new")
|
190
190
|
fill_in 'Name', :with=>'Album1'
|
@@ -199,8 +199,8 @@ describe AutoForme do
|
|
199
199
|
select 'Album1'
|
200
200
|
click_button 'Show'
|
201
201
|
click_link 'Artist1'
|
202
|
-
page.current_path.
|
203
|
-
page.html.
|
202
|
+
page.current_path.must_match %r{Artist/show/\d+}
|
203
|
+
page.html.wont_match /Albums/
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should have many to many association editing working when associated class is not using autoforme" do
|
@@ -219,22 +219,22 @@ describe AutoForme do
|
|
219
219
|
select("Artist1")
|
220
220
|
click_button "Edit"
|
221
221
|
|
222
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
223
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
222
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
223
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
224
224
|
select("Album1", :from=>"Associate With")
|
225
225
|
click_button "Update"
|
226
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
226
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album1'
|
227
227
|
|
228
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
229
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
228
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
229
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
230
230
|
select("Album2", :from=>"Associate With")
|
231
231
|
select("Album3", :from=>"Associate With")
|
232
232
|
select("Album1", :from=>"Disassociate From")
|
233
233
|
click_button "Update"
|
234
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
234
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
235
235
|
|
236
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
237
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
236
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
237
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should use filter/order from associated class" do
|
@@ -257,38 +257,38 @@ describe AutoForme do
|
|
257
257
|
select("Artist1")
|
258
258
|
click_button "Edit"
|
259
259
|
|
260
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
261
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
260
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["B1", "E1"]
|
261
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
262
262
|
select("E1", :from=>"Associate With")
|
263
263
|
click_button "Update"
|
264
|
-
Artist.first.albums.map{|x| x.name}.
|
264
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'E1'
|
265
265
|
|
266
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
267
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
266
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["B1"]
|
267
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["E1"]
|
268
268
|
select("B1", :from=>"Associate With")
|
269
269
|
select("E1", :from=>"Disassociate From")
|
270
270
|
click_button "Update"
|
271
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
271
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'B1'
|
272
272
|
|
273
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
274
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
273
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["E1"]
|
274
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["B1"]
|
275
275
|
|
276
276
|
select("B1", :from=>"Disassociate From")
|
277
277
|
Album.where(:name=>'B1').update(:name=>'Z1')
|
278
|
-
proc{click_button "Update"}.
|
278
|
+
proc{click_button "Update"}.must_raise(Sequel::NoMatchingRow)
|
279
279
|
|
280
280
|
visit('/Artist/mtm_edit')
|
281
281
|
select("Artist1")
|
282
282
|
click_button "Edit"
|
283
283
|
select("E1", :from=>"Associate With")
|
284
284
|
Album.where(:name=>'E1').update(:name=>'Y1')
|
285
|
-
proc{click_button "Update"}.
|
285
|
+
proc{click_button "Update"}.must_raise(Sequel::NoMatchingRow)
|
286
286
|
|
287
287
|
visit('/Artist/mtm_edit')
|
288
288
|
select("Artist1")
|
289
289
|
click_button "Edit"
|
290
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
291
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
290
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
291
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
292
292
|
end
|
293
293
|
|
294
294
|
it "should support column options on mtm_edit page" do
|
@@ -313,13 +313,13 @@ describe AutoForme do
|
|
313
313
|
|
314
314
|
check "Album12"
|
315
315
|
click_button "Update"
|
316
|
-
Artist.first.albums.map{|x| x.name}.
|
316
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
317
317
|
|
318
318
|
check "Album1Album1"
|
319
319
|
check "Album22"
|
320
320
|
check "Album32"
|
321
321
|
click_button "Update"
|
322
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
322
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
323
323
|
|
324
324
|
check "Album12"
|
325
325
|
check "Album2Album2"
|
@@ -351,30 +351,30 @@ describe AutoForme do
|
|
351
351
|
Album.create(:name=>'Album3')
|
352
352
|
|
353
353
|
visit("/Artist/mtm_edit")
|
354
|
-
page.title.
|
354
|
+
page.title.must_equal 'Artist - Many To Many Edit'
|
355
355
|
select("Artist1")
|
356
356
|
click_button "Edit"
|
357
357
|
|
358
358
|
select('albums')
|
359
359
|
click_button "Edit"
|
360
360
|
|
361
|
-
find('h2').text.
|
362
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
363
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
361
|
+
find('h2').text.must_equal 'Edit Albums for Artist1'
|
362
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
363
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
364
364
|
select("Album1", :from=>"Associate With")
|
365
365
|
click_button "Update"
|
366
|
-
page.html.
|
367
|
-
Artist.first.albums.map{|x| x.name}.
|
366
|
+
page.html.must_match /Updated albums association for Artist/
|
367
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
368
368
|
|
369
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
370
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
369
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
370
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
371
371
|
select("Album2", :from=>"Associate With")
|
372
372
|
select("Album3", :from=>"Associate With")
|
373
373
|
select("Album1", :from=>"Disassociate From")
|
374
374
|
click_button "Update"
|
375
|
-
Artist.first.refresh.albums.map{|x| x.name}.
|
375
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
376
376
|
|
377
|
-
page.all('select')[0].all('option').map{|s| s.text}.
|
378
|
-
page.all('select')[1].all('option').map{|s| s.text}.
|
377
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
378
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
379
379
|
end
|
380
380
|
end
|
data/spec/rails_spec_helper.rb
CHANGED
@@ -2,15 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'action_controller/railtie'
|
3
3
|
require 'autoforme'
|
4
4
|
|
5
|
-
RSpec.configure do |c|
|
6
|
-
c.after(:each) do |example|
|
7
|
-
if Object.const_defined?(:AutoformeController)
|
8
|
-
Object.send(:remove_const, :AutoformeController)
|
9
|
-
Rails.application = nil
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
5
|
class AutoFormeSpec::App
|
15
6
|
def self.autoforme(klass=nil, opts={}, &block)
|
16
7
|
sc = Class.new(Rails::Application)
|
data/spec/roda_spec_helper.rb
CHANGED
data/spec/sequel_spec_helper.rb
CHANGED
@@ -1,22 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'sequel'
|
3
3
|
require 'logger'
|
4
|
-
require 'rspec/version'
|
5
|
-
|
6
|
-
RSpec.configure do |c|
|
7
|
-
if RSpec::Version::STRING >= '2.11.0'
|
8
|
-
c.expect_with :rspec do |c1|
|
9
|
-
c1.syntax = :should
|
10
|
-
end
|
11
|
-
end
|
12
|
-
c.around(:each) do |example|
|
13
|
-
if db
|
14
|
-
db.transaction(:rollback=>:always){example.run}
|
15
|
-
else
|
16
|
-
example.run
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
4
|
|
21
5
|
module AutoFormeSpec
|
22
6
|
TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric}
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'capybara'
|
3
3
|
require 'capybara/dsl'
|
4
|
-
require 'capybara/rspec/matchers'
|
5
4
|
require 'rack/test'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'minitest/hooks/default'
|
6
7
|
|
7
8
|
module AutoFormeSpec
|
8
9
|
end
|
9
10
|
|
10
11
|
require './spec/sequel_spec_helper'
|
11
|
-
require "./spec/#{ENV['FRAMEWORK'] || '
|
12
|
+
require "./spec/#{ENV['FRAMEWORK'] || 'roda'}_spec_helper"
|
12
13
|
|
13
|
-
|
14
|
+
class Minitest::HooksSpec
|
14
15
|
include Rack::Test::Methods
|
15
16
|
include Capybara::DSL
|
16
|
-
include Capybara::RSpecMatchers
|
17
17
|
|
18
18
|
attr_reader :app
|
19
19
|
attr_reader :db
|
@@ -37,9 +37,17 @@ RSpec::Core::ExampleGroup.class_eval do
|
|
37
37
|
self.app = app
|
38
38
|
@model = @framework.models[klass.name] if klass
|
39
39
|
end
|
40
|
+
|
41
|
+
around do |&block|
|
42
|
+
db ? db.transaction(:rollback=>:always){super(&block)} : super(&block)
|
43
|
+
end
|
40
44
|
|
41
45
|
after do
|
42
46
|
Capybara.reset_sessions!
|
43
47
|
Capybara.use_default_driver
|
48
|
+
if Object.const_defined?(:AutoformeController)
|
49
|
+
Object.send(:remove_const, :AutoformeController)
|
50
|
+
Rails.application = nil
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|