autoforme 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7431cd2d4051bea42ed58879c0d0418de7282b5d
4
- data.tar.gz: f8d7d4c14152aef6efeedd2fb763df6cd3d4e77d
3
+ metadata.gz: f75b662ff8c3d65dfbf9a7e4187aac673af1ffff
4
+ data.tar.gz: e6d75bd0451be7511938859903bde4311891d0d3
5
5
  SHA512:
6
- metadata.gz: 3047d058fccd77841b9caa2855e9f9a0ecbb54e975c44586c68d01ddcdc5a06a10769ed7f207740318b0be748b7becff1b2f3178ef5fcb5ee8a17d661d65dfb0
7
- data.tar.gz: 82b9b6c81507bae202145f7b4af5d1eec35eec0bade86491a08a389a85896849d5f5c2d0f5ce524ee25fab51bb5f250dd6d1caa9166e9e4196e9e7df761f99cc
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)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2016 Jeremy Evans
1
+ Copyright (c) 2013-2017 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
@@ -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-mini btn-primary')
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-mini btn-danger')
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
- @controller.get %r{\A#{prefix}/([\w:]+)/(\w+)(?:/([\w-]+))?\z}, &block
62
- @controller.post %r{\A#{prefix}/([\w:]+)/(\w+)(?:/([\w-]+))?\z}, &block
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, model.primary_key)=>subquery)
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
@@ -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-mini btn-info\">Show</a></td>" if show
63
- html << "<td><a href=\"#{action.url_for("edit/#{model.primary_key_value(obj)}")}\" class=\"btn btn-mini btn-primary\">Edit</a></td>" if edit
64
- html << "<td><a href=\"#{action.url_for("delete/#{model.primary_key_value(obj)}")}\" class=\"btn btn-mini btn-danger\">Delete</a></td>" if delete
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>"
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AutoForme
4
4
  # Version constant, use <tt>AutoForme.version</tt> instead.
5
- VERSION = '1.5.0'.freeze
5
+ VERSION = '1.6.0'.freeze
6
6
 
7
7
  # Returns the version as a frozen string (e.g. '0.1.0')
8
8
  def self.version
@@ -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 ? [:albums__name, :artist__name] : [:artist__name, :albums__name]}
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 ? [:albums__name, :artist__name] : [:artist__name, :albums__name]}
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 :artist__name
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 :albums__name
691
+ order Sequel[:albums][:name]
692
692
  end
693
693
  model Album do
694
694
  columns [:name, :artist]
@@ -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}]])
@@ -36,8 +36,8 @@ HTML
36
36
  layout 'layout'
37
37
 
38
38
  def session_set
39
- session.merge!(params)
40
- render :text=>''
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]
@@ -11,6 +11,10 @@ rescue LoadError
11
11
  end
12
12
 
13
13
  class AutoFormeSpec::App < Roda
14
+ opts[:unsupported_block_result] = :raise
15
+ opts[:unsupported_matcher] = :raise
16
+ opts[:verbatim_string_matcher] = true
17
+
14
18
  LAYOUT = <<HTML
15
19
  <!DOCTYPE html>
16
20
  <html>
@@ -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
 
@@ -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).must_equal 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).must_equal 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).must_equal 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.must_equal nil
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.must_equal nil
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.must_equal nil
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).must_equal 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).must_equal 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.must_equal nil
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.5.0
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: 2016-11-18 00:00:00.000000000 Z
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.8
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