autoforme 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/Rakefile +7 -2
- data/lib/autoforme.rb +1 -1
- data/lib/autoforme/action.rb +15 -21
- data/lib/autoforme/frameworks/rails.rb +4 -4
- data/lib/autoforme/frameworks/roda.rb +5 -1
- data/lib/autoforme/frameworks/sinatra.rb +2 -2
- data/lib/autoforme/model.rb +3 -10
- data/lib/autoforme/models/sequel.rb +1 -6
- data/lib/autoforme/table.rb +1 -8
- data/lib/autoforme/version.rb +1 -1
- data/spec/all.rb +2 -0
- data/spec/associations_spec.rb +145 -19
- data/spec/basic_spec.rb +229 -44
- data/spec/mtm_spec.rb +86 -9
- data/spec/rails_spec_helper.rb +1 -1
- data/spec/roda_spec.rb +72 -0
- data/spec/spec_helper.rb +26 -2
- data/spec/unit_spec.rb +62 -1
- metadata +19 -3
data/spec/mtm_spec.rb
CHANGED
@@ -17,9 +17,47 @@ describe AutoForme do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
visit("/Artist/browse")
|
20
|
-
page.html.
|
20
|
+
page.html.wont_include 'MTM'
|
21
21
|
visit("/Artist/mtm_edit")
|
22
|
-
page.html.
|
22
|
+
page.html.must_include 'Unhandled Request'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have working Model#associated_object_display_name" do
|
26
|
+
mod = nil
|
27
|
+
app_setup do
|
28
|
+
model Artist
|
29
|
+
model Album do
|
30
|
+
mod = self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
mod.associated_object_display_name(:artist, nil, Artist.load(:name=>'a')).must_equal 'a'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have Model#associated_object_display_name respect :name_method column option" do
|
38
|
+
mod = nil
|
39
|
+
app_setup do
|
40
|
+
model Artist
|
41
|
+
model Album do
|
42
|
+
column_options :artist=>{:name_method=>:id}
|
43
|
+
mod = self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
mod.associated_object_display_name(:artist, nil, Artist.load(:id=>1)).must_equal 1
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have Model#associated_object_display_name raise Error if not valid" do
|
51
|
+
mod = nil
|
52
|
+
app_setup do
|
53
|
+
model Artist
|
54
|
+
model Album do
|
55
|
+
column_options :artist=>{:name_method=>Object.new}
|
56
|
+
mod = self
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
proc{mod.associated_object_display_name(:artist, nil, Artist.load(:name=>'a'))}.must_raise AutoForme::Error
|
23
61
|
end
|
24
62
|
|
25
63
|
it "should have basic many to many association editing working" do
|
@@ -46,7 +84,7 @@ describe AutoForme do
|
|
46
84
|
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
47
85
|
select("Album1", :from=>"Associate With")
|
48
86
|
click_button "Update"
|
49
|
-
page.html.
|
87
|
+
page.html.must_include 'Updated albums association for Artist'
|
50
88
|
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
51
89
|
|
52
90
|
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
@@ -83,7 +121,7 @@ describe AutoForme do
|
|
83
121
|
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
84
122
|
fill_in "Associate With", :with=>a1.id
|
85
123
|
click_button "Update"
|
86
|
-
page.html.
|
124
|
+
page.html.must_include 'Updated albums association for Artist'
|
87
125
|
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
88
126
|
|
89
127
|
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
@@ -92,6 +130,19 @@ describe AutoForme do
|
|
92
130
|
click_button "Update"
|
93
131
|
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
94
132
|
|
133
|
+
visit "/Artist/autocomplete/albums?type=association&q=Album"
|
134
|
+
page.body.must_match(/#{a1.id} - Album1\n#{a2.id} - Album2\n#{a3.id} - Album3/m)
|
135
|
+
|
136
|
+
visit "/Artist/autocomplete/albums?type=association&q=3"
|
137
|
+
page.body.wont_match(/#{a1.id} - Album1\n#{a2.id} - Album2\n#{a3.id} - Album3/m)
|
138
|
+
page.body.must_match(/#{a3.id} - Album3/m)
|
139
|
+
|
140
|
+
visit "/Artist/autocomplete/albums?type=association&exclude=#{Artist.first.id}&q=Album"
|
141
|
+
page.body.must_match(/#{a1.id} - Album1\n#{a3.id} - Album3/m)
|
142
|
+
|
143
|
+
visit("/Artist/mtm_edit")
|
144
|
+
select("Artist1")
|
145
|
+
click_button "Edit"
|
95
146
|
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2"]
|
96
147
|
select("Album2", :from=>"Disassociate From")
|
97
148
|
click_button "Update"
|
@@ -117,7 +168,7 @@ describe AutoForme do
|
|
117
168
|
click_button "Edit"
|
118
169
|
select 'Album1'
|
119
170
|
click_button 'Add'
|
120
|
-
page.html.
|
171
|
+
page.html.must_include 'Updated albums association for Artist'
|
121
172
|
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
122
173
|
|
123
174
|
select 'Album2'
|
@@ -152,7 +203,7 @@ describe AutoForme do
|
|
152
203
|
click_button "Edit"
|
153
204
|
fill_in 'Albums', :with=>a1.id.to_s
|
154
205
|
click_button 'Add'
|
155
|
-
page.html.
|
206
|
+
page.html.must_include 'Updated albums association for Artist'
|
156
207
|
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
157
208
|
|
158
209
|
fill_in 'Albums', :with=>a2.id.to_s
|
@@ -167,6 +218,32 @@ describe AutoForme do
|
|
167
218
|
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album2 Album3'
|
168
219
|
end
|
169
220
|
|
221
|
+
it "should have inline many to many association editing working with xhr" do
|
222
|
+
app_setup do
|
223
|
+
model Artist do
|
224
|
+
inline_mtm_associations do |req|
|
225
|
+
def req.xhr?; action_type == 'mtm_update' end
|
226
|
+
:albums
|
227
|
+
end
|
228
|
+
end
|
229
|
+
model Album
|
230
|
+
end
|
231
|
+
|
232
|
+
Artist.create(:name=>'Artist1')
|
233
|
+
album = Album.create(:name=>'Album1')
|
234
|
+
|
235
|
+
visit("/Artist/edit")
|
236
|
+
select("Artist1")
|
237
|
+
click_button "Edit"
|
238
|
+
select 'Album1'
|
239
|
+
click_button 'Add'
|
240
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
241
|
+
|
242
|
+
click_button 'Remove'
|
243
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal []
|
244
|
+
page.body.must_equal "<option value=\"#{album.id}\">Album1</option>"
|
245
|
+
end
|
246
|
+
|
170
247
|
it "should have working many to many association links on show and edit pages" do
|
171
248
|
app_setup do
|
172
249
|
model Artist do
|
@@ -185,7 +262,7 @@ describe AutoForme do
|
|
185
262
|
click_link 'Edit'
|
186
263
|
select 'Artist1'
|
187
264
|
click_button 'Edit'
|
188
|
-
page.html.
|
265
|
+
page.html.wont_include 'Albums'
|
189
266
|
|
190
267
|
visit("/Album/new")
|
191
268
|
fill_in 'Name', :with=>'Album1'
|
@@ -201,7 +278,7 @@ describe AutoForme do
|
|
201
278
|
click_button 'Show'
|
202
279
|
click_link 'Artist1'
|
203
280
|
page.current_path.must_match %r{Artist/show/\d+}
|
204
|
-
page.html.
|
281
|
+
page.html.wont_include 'Albums'
|
205
282
|
end
|
206
283
|
|
207
284
|
it "should have many to many association editing working when associated class is not using autoforme" do
|
@@ -364,7 +441,7 @@ describe AutoForme do
|
|
364
441
|
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
365
442
|
select("Album1", :from=>"Associate With")
|
366
443
|
click_button "Update"
|
367
|
-
page.html.
|
444
|
+
page.html.must_include 'Updated albums association for Artist'
|
368
445
|
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
369
446
|
|
370
447
|
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
data/spec/rails_spec_helper.rb
CHANGED
@@ -55,7 +55,7 @@ HTML
|
|
55
55
|
end.inspect
|
56
56
|
config.active_support.deprecation = :stderr
|
57
57
|
config.middleware.delete(ActionDispatch::ShowExceptions)
|
58
|
-
config.middleware.delete(
|
58
|
+
config.middleware.delete(Rack::Lock)
|
59
59
|
config.secret_key_base = 'foo'
|
60
60
|
config.eager_load = true
|
61
61
|
initialize!
|
data/spec/roda_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require './spec/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
|
+
it "should have basic functionality working in Roda subclass" do
|
13
|
+
app_setup(Artist)
|
14
|
+
self.app = Class.new(app)
|
15
|
+
visit("/Artist/new")
|
16
|
+
page.title.must_equal 'Artist - New'
|
17
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
18
|
+
click_button 'Create'
|
19
|
+
page.html.must_include 'Created Artist'
|
20
|
+
page.current_path.must_equal '/Artist/new'
|
21
|
+
|
22
|
+
click_link 'Show'
|
23
|
+
page.title.must_equal 'Artist - Show'
|
24
|
+
click_button 'Show'
|
25
|
+
select 'TestArtistNew'
|
26
|
+
click_button 'Show'
|
27
|
+
page.html.must_match(/Name.+TestArtistNew/m)
|
28
|
+
|
29
|
+
click_link 'Edit'
|
30
|
+
page.title.must_equal 'Artist - Edit'
|
31
|
+
click_button 'Edit'
|
32
|
+
select 'TestArtistNew'
|
33
|
+
click_button 'Edit'
|
34
|
+
fill_in 'Name', :with=>'TestArtistUpdate'
|
35
|
+
click_button 'Update'
|
36
|
+
page.html.must_include 'Updated Artist'
|
37
|
+
page.html.must_match(/Name.+TestArtistUpdate/m)
|
38
|
+
page.current_path.must_match %r{/Artist/edit/\d+}
|
39
|
+
|
40
|
+
click_link 'Search'
|
41
|
+
page.title.must_equal 'Artist - Search'
|
42
|
+
fill_in 'Name', :with=>'Upd'
|
43
|
+
click_button 'Search'
|
44
|
+
page.all('table').first['id'].must_equal 'autoforme_table'
|
45
|
+
page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
|
46
|
+
page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
47
|
+
click_link 'CSV Format'
|
48
|
+
page.body.must_equal "Name\nTestArtistUpdate\n"
|
49
|
+
|
50
|
+
visit("/Artist/browse")
|
51
|
+
click_link 'Search'
|
52
|
+
fill_in 'Name', :with=>'Foo'
|
53
|
+
click_button 'Search'
|
54
|
+
page.all('td').map{|s| s.text}.must_equal []
|
55
|
+
|
56
|
+
click_link 'Artist'
|
57
|
+
page.title.must_equal 'Artist - Browse'
|
58
|
+
page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
59
|
+
click_link 'CSV Format'
|
60
|
+
page.body.must_equal "Name\nTestArtistUpdate\n"
|
61
|
+
|
62
|
+
visit("/Artist/browse")
|
63
|
+
page.all('td').last.find('a').click
|
64
|
+
click_button 'Delete'
|
65
|
+
page.title.must_equal 'Artist - Delete'
|
66
|
+
page.html.must_include 'Deleted Artist'
|
67
|
+
page.current_path.must_equal '/Artist/delete'
|
68
|
+
|
69
|
+
click_link 'Artist'
|
70
|
+
page.all('td').map{|s| s.text}.must_equal []
|
71
|
+
end
|
72
|
+
end if ENV['FRAMEWORK'] == 'roda'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,39 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
$: << File.expand_path(File.join(__FILE__, '../../lib'))
|
3
|
+
ENV['FRAMEWORK'] ||= 'roda'
|
4
|
+
|
5
|
+
module AutoFormeSpec
|
6
|
+
end
|
7
|
+
|
8
|
+
if ENV['COVERAGE']
|
9
|
+
ENV.delete('COVERAGE')
|
10
|
+
require 'coverage'
|
11
|
+
require 'simplecov'
|
12
|
+
|
13
|
+
SimpleCov.instance_eval do
|
14
|
+
start do
|
15
|
+
add_filter "/spec/"
|
16
|
+
add_group('Missing'){|src| src.covered_percent < 100}
|
17
|
+
add_group('Covered'){|src| src.covered_percent == 100}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require "./spec/#{ENV['FRAMEWORK']}_spec_helper"
|
23
|
+
|
2
24
|
require 'capybara'
|
3
25
|
require 'capybara/dsl'
|
4
26
|
require 'rack/test'
|
27
|
+
gem 'minitest'
|
5
28
|
require 'minitest/autorun'
|
6
29
|
require 'minitest/hooks/default'
|
7
30
|
|
8
|
-
|
31
|
+
if ENV['WARNING']
|
32
|
+
require 'warning'
|
33
|
+
Warning.ignore([:missing_ivar, :fixnum])
|
9
34
|
end
|
10
35
|
|
11
36
|
require './spec/sequel_spec_helper'
|
12
|
-
require "./spec/#{ENV['FRAMEWORK'] || 'roda'}_spec_helper"
|
13
37
|
|
14
38
|
class Minitest::HooksSpec
|
15
39
|
include Rack::Test::Methods
|
data/spec/unit_spec.rb
CHANGED
@@ -306,6 +306,12 @@ describe AutoForme do
|
|
306
306
|
model.autocomplete_options{|type, req| {:limit=>req}}
|
307
307
|
model.autocomplete(:type=>:show, :query=>'oo', :request=>1).must_equal ["#{a.id} - FooBar"]
|
308
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
|
309
315
|
end
|
310
316
|
|
311
317
|
describe AutoForme do
|
@@ -331,6 +337,7 @@ describe AutoForme do
|
|
331
337
|
end
|
332
338
|
end
|
333
339
|
|
340
|
+
model.association?('artist').must_equal true
|
334
341
|
artist.autocomplete_options({})
|
335
342
|
model.autocomplete(:query=>'foo', :association=>:artist).must_equal []
|
336
343
|
a = Artist.create(:name=>'FooBar')
|
@@ -356,6 +363,35 @@ describe AutoForme do
|
|
356
363
|
end
|
357
364
|
end
|
358
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
|
+
|
359
395
|
describe AutoForme do
|
360
396
|
before(:all) do
|
361
397
|
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
@@ -445,6 +481,31 @@ end
|
|
445
481
|
|
446
482
|
describe AutoForme do
|
447
483
|
it ".version should return a typical version string" do
|
448
|
-
AutoForme.version.must_match
|
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
|
449
510
|
end
|
450
511
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoforme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forme
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: tilt
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rack_csrf
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,10 +229,12 @@ files:
|
|
215
229
|
- lib/autoforme/table.rb
|
216
230
|
- lib/autoforme/version.rb
|
217
231
|
- lib/roda/plugins/autoforme.rb
|
232
|
+
- spec/all.rb
|
218
233
|
- spec/associations_spec.rb
|
219
234
|
- spec/basic_spec.rb
|
220
235
|
- spec/mtm_spec.rb
|
221
236
|
- spec/rails_spec_helper.rb
|
237
|
+
- spec/roda_spec.rb
|
222
238
|
- spec/roda_spec_helper.rb
|
223
239
|
- spec/sequel_spec_helper.rb
|
224
240
|
- spec/sinatra_spec_helper.rb
|
@@ -251,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
267
|
version: '0'
|
252
268
|
requirements: []
|
253
269
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.
|
270
|
+
rubygems_version: 2.6.8
|
255
271
|
signing_key:
|
256
272
|
specification_version: 4
|
257
273
|
summary: Web Administrative Console for Sinatra/Rails and Sequel
|