autoforme 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/MIT-LICENSE +1 -1
- data/lib/autoforme/action.rb +2 -2
- data/lib/autoforme/frameworks/sinatra.rb +7 -2
- data/lib/autoforme/models/sequel.rb +1 -1
- data/lib/autoforme/table.rb +3 -3
- data/lib/autoforme/version.rb +1 -1
- data/spec/associations_spec.rb +4 -4
- data/spec/mtm_spec.rb +51 -0
- data/spec/rails_spec_helper.rb +9 -2
- data/spec/roda_spec_helper.rb +4 -0
- data/spec/sequel_spec_helper.rb +3 -1
- data/spec/unit_spec.rb +9 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f75b662ff8c3d65dfbf9a7e4187aac673af1ffff
|
4
|
+
data.tar.gz: e6d75bd0451be7511938859903bde4311891d0d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32550500006667014af561745e6d002455aba058846433e3fa5ecaf9f4fdfce1038ee1cd736f713151d0347fb80d2a7665c0c6de8d71a7e2c0d5707bc81d2a9c
|
7
|
+
data.tar.gz: 25122fe3de631c441156721d44fa3544b67f7c2eaae17ede522922aeb5ee13d4304712986373637e6ff984afb7a83c4a7a6a52f498707aa6dcc8de96dd67c0d9
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 1.6.0 (2017-05-04)
|
2
|
+
|
3
|
+
* Fix mtm code when using model classes with different primary key names (jeremyevans)
|
4
|
+
|
5
|
+
* Work with Sinatra 2 (jeremyevans)
|
6
|
+
|
7
|
+
* Use btn-xs class instead of btn-mini for small buttons (jeremyevans)
|
8
|
+
|
1
9
|
=== 1.5.0 (2016-11-18)
|
2
10
|
|
3
11
|
* Allow autocompleting for associated objects even if current class doesn't support autocompleting (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/lib/autoforme/action.rb
CHANGED
@@ -650,7 +650,7 @@ module AutoForme
|
|
650
650
|
else
|
651
651
|
f.input(assoc, {:dataset=>model.unassociated_mtm_objects(request, assoc, obj), :multiple=>false, :add_blank=>true}.merge(add_opts))
|
652
652
|
end
|
653
|
-
f.button(:value=>'Add', :class=>'btn btn-
|
653
|
+
f.button(:value=>'Add', :class=>'btn btn-xs btn-primary')
|
654
654
|
end.to_s
|
655
655
|
end
|
656
656
|
t << "</div>"
|
@@ -675,7 +675,7 @@ module AutoForme
|
|
675
675
|
t << association_link(mc, assoc_obj)
|
676
676
|
form_attr = form_attributes(:action=>url_for("mtm_update/#{model.primary_key_value(obj)}?association=#{assoc}&remove%5b%5d=#{model.primary_key_value(assoc_obj)}&redir=edit"), :method=>'post', :class => 'mtm_remove_associations', 'data-add'=>"#add_#{assoc}")
|
677
677
|
t << Forme.form(form_attr, form_opts) do |f|
|
678
|
-
f.button(:value=>'Remove', :class=>'btn btn-
|
678
|
+
f.button(:value=>'Remove', :class=>'btn btn-xs btn-danger')
|
679
679
|
end.to_s
|
680
680
|
t << "</li>"
|
681
681
|
end
|
@@ -58,8 +58,13 @@ module AutoForme
|
|
58
58
|
end
|
59
59
|
|
60
60
|
prefix = Regexp.escape(framework.prefix) if framework.prefix
|
61
|
-
|
62
|
-
|
61
|
+
if ::Sinatra::VERSION < '2'
|
62
|
+
prefix = "\\A#{prefix}"
|
63
|
+
suffix = "\\z"
|
64
|
+
end
|
65
|
+
regexp = %r{#{prefix}/([\w:]+)/(\w+)(?:/([\w-]+))?#{suffix}}
|
66
|
+
@controller.get regexp, &block
|
67
|
+
@controller.post regexp, &block
|
63
68
|
end
|
64
69
|
end
|
65
70
|
end
|
@@ -319,7 +319,7 @@ module AutoForme
|
|
319
319
|
subquery = model.db.from(ref[:join_table]).
|
320
320
|
select(ref.qualified_right_key).
|
321
321
|
where(ref.qualified_left_key=>obj.pk)
|
322
|
-
ds = ds.exclude(S.qualify(ref.associated_class.table_name,
|
322
|
+
ds = ds.exclude(S.qualify(ref.associated_class.table_name, ref.associated_class.primary_key)=>subquery)
|
323
323
|
ds = assoc_class.apply_dataset_options(:association, request, ds) if assoc_class
|
324
324
|
ds
|
325
325
|
end
|
data/lib/autoforme/table.rb
CHANGED
@@ -59,9 +59,9 @@ module AutoForme
|
|
59
59
|
end
|
60
60
|
html << "<td>#{val}</td>"
|
61
61
|
end
|
62
|
-
html << "<td><a href=\"#{action.url_for("show/#{model.primary_key_value(obj)}")}\" class=\"btn btn-
|
63
|
-
html << "<td><a href=\"#{action.url_for("edit/#{model.primary_key_value(obj)}")}\" class=\"btn btn-
|
64
|
-
html << "<td><a href=\"#{action.url_for("delete/#{model.primary_key_value(obj)}")}\" class=\"btn btn-
|
62
|
+
html << "<td><a href=\"#{action.url_for("show/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-info\">Show</a></td>" if show
|
63
|
+
html << "<td><a href=\"#{action.url_for("edit/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-primary\">Edit</a></td>" if edit
|
64
|
+
html << "<td><a href=\"#{action.url_for("delete/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-danger\">Delete</a></td>" if delete
|
65
65
|
html << "</tr>"
|
66
66
|
end
|
67
67
|
html << "</tbody></table>"
|
data/lib/autoforme/version.rb
CHANGED
data/spec/associations_spec.rb
CHANGED
@@ -329,7 +329,7 @@ describe AutoForme do
|
|
329
329
|
model Album do
|
330
330
|
columns [:name, :artist]
|
331
331
|
eager_graph :artist
|
332
|
-
order{|type, req| type == :edit ? [:
|
332
|
+
order{|type, req| type == :edit ? [Sequel[:albums][:name], Sequel[:artist][:name]] : [Sequel[:artist][:name], Sequel[:albums][:name]]}
|
333
333
|
display_name{|obj, type| type == :edit ? "#{obj.name} (#{obj.artist.name})" : "#{obj.artist.name}-#{obj.name}"}
|
334
334
|
end
|
335
335
|
end
|
@@ -349,7 +349,7 @@ describe AutoForme do
|
|
349
349
|
model Album do
|
350
350
|
columns [:name, :artist]
|
351
351
|
eager_graph :artist
|
352
|
-
order{|type, req| type == :edit ? [:
|
352
|
+
order{|type, req| type == :edit ? [Sequel[:albums][:name], Sequel[:artist][:name]] : [Sequel[:artist][:name], Sequel[:albums][:name]]}
|
353
353
|
display_name{|obj, type| type == :edit ? "#{obj.name} (#{obj.artist.name})" : "#{obj.artist.name}-#{obj.name}"}
|
354
354
|
end
|
355
355
|
end
|
@@ -647,7 +647,7 @@ describe AutoForme do
|
|
647
647
|
model Album do
|
648
648
|
columns [:name, :artist]
|
649
649
|
eager_graph :artist
|
650
|
-
order :
|
650
|
+
order Sequel[:artist][:name]
|
651
651
|
end
|
652
652
|
end
|
653
653
|
|
@@ -688,7 +688,7 @@ describe AutoForme do
|
|
688
688
|
app_setup do
|
689
689
|
model Artist do
|
690
690
|
eager_graph :albums
|
691
|
-
order :
|
691
|
+
order Sequel[:albums][:name]
|
692
692
|
end
|
693
693
|
model Album do
|
694
694
|
columns [:name, :artist]
|
data/spec/mtm_spec.rb
CHANGED
@@ -405,6 +405,57 @@ describe AutoForme do
|
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
408
|
+
describe AutoForme do
|
409
|
+
before(:all) do
|
410
|
+
db_setup(:artists=>proc{primary_key :artist_id; String :name}, :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
411
|
+
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
412
|
+
end
|
413
|
+
after(:all) do
|
414
|
+
Object.send(:remove_const, :Album)
|
415
|
+
Object.send(:remove_const, :Artist)
|
416
|
+
end
|
417
|
+
|
418
|
+
it "should have basic many to many association editing working" do
|
419
|
+
app_setup do
|
420
|
+
model Artist do
|
421
|
+
mtm_associations :albums
|
422
|
+
end
|
423
|
+
model Album
|
424
|
+
end
|
425
|
+
|
426
|
+
Artist.create(:name=>'Artist1')
|
427
|
+
Album.create(:name=>'Album1')
|
428
|
+
Album.create(:name=>'Album2')
|
429
|
+
Album.create(:name=>'Album3')
|
430
|
+
|
431
|
+
visit("/Artist/mtm_edit")
|
432
|
+
page.title.must_equal 'Artist - Many To Many Edit'
|
433
|
+
click_button "Edit"
|
434
|
+
select("Artist1")
|
435
|
+
click_button "Edit"
|
436
|
+
|
437
|
+
find('h2').text.must_equal 'Edit Albums for Artist1'
|
438
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
439
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
440
|
+
select("Album1", :from=>"Associate With")
|
441
|
+
click_button "Update"
|
442
|
+
page.html.must_include 'Updated albums association for Artist'
|
443
|
+
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
444
|
+
|
445
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
446
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
447
|
+
select("Album2", :from=>"Associate With")
|
448
|
+
select("Album3", :from=>"Associate With")
|
449
|
+
select("Album1", :from=>"Disassociate From")
|
450
|
+
click_button "Update"
|
451
|
+
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
452
|
+
|
453
|
+
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
454
|
+
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
455
|
+
end
|
456
|
+
|
457
|
+
end
|
458
|
+
|
408
459
|
describe AutoForme do
|
409
460
|
before(:all) do
|
410
461
|
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
data/spec/rails_spec_helper.rb
CHANGED
@@ -36,8 +36,8 @@ HTML
|
|
36
36
|
layout 'layout'
|
37
37
|
|
38
38
|
def session_set
|
39
|
-
session
|
40
|
-
render :
|
39
|
+
params.each{|k,v| session[k] = v}
|
40
|
+
render :plain=>''
|
41
41
|
end
|
42
42
|
|
43
43
|
AutoForme.for(:rails, self, opts) do
|
@@ -58,6 +58,13 @@ HTML
|
|
58
58
|
config.middleware.delete(Rack::Lock)
|
59
59
|
config.secret_key_base = 'foo'
|
60
60
|
config.eager_load = true
|
61
|
+
if Rails.version > '5'
|
62
|
+
config.action_dispatch.cookies_serializer = :json
|
63
|
+
# Force Rails to dispatch to correct controller
|
64
|
+
ActionDispatch::Routing::RouteSet::Dispatcher.class_eval do
|
65
|
+
define_method(:controller){|_| controller}
|
66
|
+
end
|
67
|
+
end
|
61
68
|
initialize!
|
62
69
|
end
|
63
70
|
[sc, framework]
|
data/spec/roda_spec_helper.rb
CHANGED
data/spec/sequel_spec_helper.rb
CHANGED
@@ -7,7 +7,8 @@ module AutoFormeSpec
|
|
7
7
|
def self.db_setup(tables)
|
8
8
|
db_url = ENV['DATABASE_URL']
|
9
9
|
db_url ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
10
|
-
db = Sequel.connect(db_url)
|
10
|
+
db = Sequel.connect(db_url, :identifier_mangling=>false)
|
11
|
+
db.extension :freeze_datasets
|
11
12
|
#db.loggers << Logger.new($stdout)
|
12
13
|
tables.each do |table, table_spec|
|
13
14
|
db.create_table(table) do
|
@@ -22,6 +23,7 @@ module AutoFormeSpec
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
db.freeze
|
25
27
|
db
|
26
28
|
end
|
27
29
|
|
data/spec/unit_spec.rb
CHANGED
@@ -68,7 +68,7 @@ describe AutoForme do
|
|
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_be_nil
|
72
72
|
framework.order :bar
|
73
73
|
model.order_for(:browse, nil).must_equal :bar
|
74
74
|
framework.order{|mod, type, req| [mod.name.to_sym, type, req]}
|
@@ -80,7 +80,7 @@ describe AutoForme do
|
|
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_be_nil
|
84
84
|
model.eager [:foo]
|
85
85
|
model.eager_for(:browse, nil).must_equal [:foo]
|
86
86
|
model.eager{|type, req| [type, req]}
|
@@ -88,7 +88,7 @@ describe AutoForme do
|
|
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_be_nil
|
92
92
|
model.eager_graph [:foo]
|
93
93
|
model.eager_graph_for(:browse, nil).must_equal [:foo]
|
94
94
|
model.eager_graph{|type, req| [type, req]}
|
@@ -96,7 +96,7 @@ describe AutoForme do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should handle filter lookup" do
|
99
|
-
model.filter_for.
|
99
|
+
model.filter_for.must_be_nil
|
100
100
|
framework.filter{|mod| lambda{|ds, type, req| [ds, mod.name.to_sym, type, req]}}
|
101
101
|
model.filter_for.call(1, :browse, 2).must_equal [1, :Artist, :browse, 2]
|
102
102
|
model.filter{|ds, type, req| [ds, type, req]}
|
@@ -104,7 +104,7 @@ describe AutoForme do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should handle redirect lookup" do
|
107
|
-
model.redirect_for.
|
107
|
+
model.redirect_for.must_be_nil
|
108
108
|
framework.redirect{|mod| lambda{|obj, type, req| [obj, mod.name.to_sym, type, req]}}
|
109
109
|
model.redirect_for.call(1, :new, 2).must_equal [1, :Artist, :new, 2]
|
110
110
|
model.redirect{|obj, type, req| [obj, type, req]}
|
@@ -112,7 +112,7 @@ describe AutoForme do
|
|
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_be_nil
|
116
116
|
framework.display_name :foo
|
117
117
|
model.display_name_for.must_equal :foo
|
118
118
|
framework.display_name{|mod| mod.name.to_sym}
|
@@ -248,7 +248,7 @@ describe AutoForme do
|
|
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_be_nil
|
252
252
|
framework.page_header "foo"
|
253
253
|
model.page_header_for(:show, nil).must_equal 'foo'
|
254
254
|
framework.page_header{|mod, type, req| "#{mod} #{type} #{req}"}
|
@@ -260,7 +260,7 @@ describe AutoForme do
|
|
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_be_nil
|
264
264
|
framework.page_footer "foo"
|
265
265
|
model.page_footer_for(:show, nil).must_equal 'foo'
|
266
266
|
framework.page_footer{|mod, type, req| "#{mod} #{type} #{req}"}
|
@@ -461,7 +461,7 @@ describe AutoForme::OptsAttributes do
|
|
461
461
|
end
|
462
462
|
|
463
463
|
it "should act as a getter if given no arguments, and setter if given arguments or a block" do
|
464
|
-
@o.foo.
|
464
|
+
@o.foo.must_be_nil
|
465
465
|
@o.foo(1).must_equal 1
|
466
466
|
@o.foo.must_equal 1
|
467
467
|
p = proc{}
|
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.6.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:
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forme
|
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
267
|
version: '0'
|
268
268
|
requirements: []
|
269
269
|
rubyforge_project:
|
270
|
-
rubygems_version: 2.6.
|
270
|
+
rubygems_version: 2.6.11
|
271
271
|
signing_key:
|
272
272
|
specification_version: 4
|
273
273
|
summary: Web Administrative Console for Sinatra/Rails and Sequel
|