autoforme 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f75b662ff8c3d65dfbf9a7e4187aac673af1ffff
4
- data.tar.gz: e6d75bd0451be7511938859903bde4311891d0d3
3
+ metadata.gz: 83fda57cc1135158108ed30103403c23d0600ccf
4
+ data.tar.gz: 42e3f1e0bae263ea3e5babc767cb3492bf2f5efe
5
5
  SHA512:
6
- metadata.gz: 32550500006667014af561745e6d002455aba058846433e3fa5ecaf9f4fdfce1038ee1cd736f713151d0347fb80d2a7665c0c6de8d71a7e2c0d5707bc81d2a9c
7
- data.tar.gz: 25122fe3de631c441156721d44fa3544b67f7c2eaae17ede522922aeb5ee13d4304712986373637e6ff984afb7a83c4a7a6a52f498707aa6dcc8de96dd67c0d9
6
+ metadata.gz: 0d716b34aec6a9b8a7e85e6c3928a029240ff1959b3e94358cdbcd974164f34a6a68206d698977d5cdfedbf253b6973ae04713574693f20d18c6933647e7c47f
7
+ data.tar.gz: fc8efa80a2e498952c10c1052b9eccee17d20a5d488e7416537e3eae89b76f6505cddf3058be80580f139e959f5d3a9f82c2c8bbfb411b172f7783e704b5f0c0
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.7.0 (2017-10-27)
2
+
3
+ * Respect Model#forme_namespace method for parameter names (adam12, jeremyevans) (#9)
4
+
5
+ * Typecast column values when searching (jeremyevans)
6
+
1
7
  === 1.6.0 (2017-05-04)
2
8
 
3
9
  * Fix mtm code when using model classes with different primary key names (jeremyevans)
@@ -3,7 +3,7 @@
3
3
  AutoForme is an administrative web front end to an ORM that uses
4
4
  Forme [1] for building the HTML forms. It is designed to
5
5
  integrate easily into web frameworks, and currently supports
6
- Sinatra, Roda, and Rails. The only currently supported ORM is
6
+ Roda, Sinatra, and Rails. The only currently supported ORM is
7
7
  Sequel::Model.
8
8
 
9
9
  AutoForme's UI and capabilities are modeled on
@@ -178,7 +178,7 @@ table_class :: The html class string to use for the browse and search tables
178
178
  These hook options should be callable objects that are called with the model object and the request.
179
179
 
180
180
  after_create :: Called after creating the object
181
- after_destroy :: Called after destroy the object
181
+ after_destroy :: Called after destroying the object
182
182
  after_update :: Called after updating the object
183
183
  before_create :: Called before creating the object
184
184
  before_destroy :: Called before destroy the object
@@ -10,10 +10,15 @@ module AutoForme
10
10
  # What association types to recognize. Other association types are ignored.
11
11
  SUPPORTED_ASSOCIATION_TYPES = [:many_to_one, :one_to_one, :one_to_many, :many_to_many]
12
12
 
13
+ # The namespace for form parameter names for this model, needs to match
14
+ # the ones automatically used by Forme.
15
+ attr_reader :params_name
16
+
13
17
  # Make sure the forme plugin is loaded into the model.
14
18
  def initialize(*)
15
19
  super
16
20
  model.plugin :forme
21
+ @params_name = model.new.forme_namespace
17
22
  end
18
23
 
19
24
  # The base class for the underlying model, ::Sequel::Model.
@@ -23,7 +28,7 @@ module AutoForme
23
28
 
24
29
  # The name of the form param for the given association.
25
30
  def form_param_name(assoc)
26
- "#{model.send(:underscore, model.name)}[#{association_key(assoc)}]"
31
+ "#{params_name}[#{association_key(assoc)}]"
27
32
  end
28
33
 
29
34
  # Set the fields for the given action type to the object based on the request params.
@@ -114,12 +119,6 @@ module AutoForme
114
119
  obj.pk
115
120
  end
116
121
 
117
- # The namespace for form parameter names for this model, needs to match
118
- # the ones automatically used by Forme.
119
- def params_name
120
- model.send(:underscore, model.name)
121
- end
122
-
123
122
  # Retrieve underlying model instance with matching primary key
124
123
  def with_pk(type, request, pk)
125
124
  dataset_for(type, request).with_pk!(pk)
@@ -171,7 +170,7 @@ module AutoForme
171
170
  elsif column_type(c) == :string
172
171
  ds = ds.where(S.ilike(S.qualify(model.table_name, c), "%#{ds.escape_like(v.to_s)}%"))
173
172
  else
174
- ds = ds.where(S.qualify(model.table_name, c)=>v.to_s)
173
+ ds = ds.where(S.qualify(model.table_name, c)=>model.db.typecast_value(column_type(c), v))
175
174
  end
176
175
  end
177
176
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AutoForme
4
4
  # Version constant, use <tt>AutoForme.version</tt> instead.
5
- VERSION = '1.6.0'.freeze
5
+ VERSION = '1.7.0'.freeze
6
6
 
7
7
  # Returns the version as a frozen string (e.g. '0.1.0')
8
8
  def self.version
@@ -607,6 +607,86 @@ describe AutoForme do
607
607
  end
608
608
  end
609
609
 
610
+ describe AutoForme do
611
+ before(:all) do
612
+ db_setup(:artists=>[[:name, :string], [:active, :boolean]])
613
+ model_setup(:Artist=>[:artists])
614
+ end
615
+ after(:all) do
616
+ Object.send(:remove_const, :Artist)
617
+ end
618
+
619
+ it "should typecast when searching" do
620
+ app_setup(Artist)
621
+ Artist.plugin(:typecast_on_load, :active) if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
622
+ visit("/Artist/new")
623
+ page.title.must_equal 'Artist - New'
624
+ select 'True'
625
+ fill_in 'Name', :with=>'TestArtistNew'
626
+ click_button 'Create'
627
+ page.html.must_include 'Created Artist'
628
+ page.current_path.must_equal '/Artist/new'
629
+
630
+ click_link 'Show'
631
+ page.title.must_equal 'Artist - Show'
632
+ click_button 'Show'
633
+ select 'TestArtistNew'
634
+ click_button 'Show'
635
+ page.html.must_match(/Active.+True.+Name.+TestArtistNew/m)
636
+
637
+ click_link 'Edit'
638
+ page.title.must_equal 'Artist - Edit'
639
+ click_button 'Edit'
640
+ select 'TestArtistNew'
641
+ click_button 'Edit'
642
+ select 'False'
643
+ fill_in 'Name', :with=>'TestArtistUpdate'
644
+ click_button 'Update'
645
+ page.html.must_include 'Updated Artist'
646
+ page.html.must_match(/Active.+False.+Name.+TestArtistUpdate/m)
647
+ page.current_path.must_match %r{/Artist/edit/\d+}
648
+
649
+ click_link 'Search'
650
+ page.title.must_equal 'Artist - Search'
651
+ fill_in 'Name', :with=>'Upd'
652
+ select 'False'
653
+ click_button 'Search'
654
+ page.all('table').first['id'].must_equal 'autoforme_table'
655
+ page.all('th').map{|s| s.text}.must_equal ['Active', 'Name', 'Show', 'Edit', 'Delete']
656
+ page.all('td').map{|s| s.text}.must_equal ['false', "TestArtistUpdate", "Show", "Edit", "Delete"]
657
+ click_link 'CSV Format'
658
+ page.body.must_equal "Active,Name\nfalse,TestArtistUpdate\n"
659
+
660
+ visit("/Artist/browse")
661
+ click_link 'Search'
662
+ fill_in 'Name', :with=>'Foo'
663
+ click_button 'Search'
664
+ page.all('td').map{|s| s.text}.must_equal []
665
+
666
+ visit("/Artist/browse")
667
+ click_link 'Search'
668
+ select 'True'
669
+ click_button 'Search'
670
+ page.all('td').map{|s| s.text}.must_equal []
671
+
672
+ click_link 'Artist'
673
+ page.title.must_equal 'Artist - Browse'
674
+ page.all('td').map{|s| s.text}.must_equal ["false", "TestArtistUpdate", "Show", "Edit", "Delete"]
675
+ click_link 'CSV Format'
676
+ page.body.must_equal "Active,Name\nfalse,TestArtistUpdate\n"
677
+
678
+ visit("/Artist/browse")
679
+ page.all('td').last.find('a').click
680
+ click_button 'Delete'
681
+ page.title.must_equal 'Artist - Delete'
682
+ page.html.must_include 'Deleted Artist'
683
+ page.current_path.must_equal '/Artist/delete'
684
+
685
+ click_link 'Artist'
686
+ page.all('td').map{|s| s.text}.must_equal []
687
+ end
688
+ end
689
+
610
690
  describe AutoForme do
611
691
  before(:all) do
612
692
  db_setup(:artists=>(0..5).map{|i|[:"n#{i}", :string]})
@@ -1041,3 +1121,28 @@ describe AutoForme do
1041
1121
  page.all('td').map{|s| s.text}.must_equal []
1042
1122
  end
1043
1123
  end
1124
+
1125
+ describe AutoForme do
1126
+ before(:all) do
1127
+ db_setup(:artists=>[[:name, :string]])
1128
+ Namespace = Module.new
1129
+
1130
+ class Namespace::Artist < Sequel::Model(db[:artists])
1131
+ def forme_namespace
1132
+ "artist"
1133
+ end
1134
+ end
1135
+ end
1136
+ after(:all) do
1137
+ Object.send(:remove_const, :Namespace)
1138
+ end
1139
+
1140
+ it "respects the forme_namespace method on the model" do
1141
+ app_setup(Namespace::Artist)
1142
+ visit("/Namespace::Artist/new")
1143
+ fill_in 'Name', :with=>'TestArtistNew'
1144
+ click_button 'Create'
1145
+ page.html.must_include 'Created Namespace::Artist'
1146
+ page.current_path.must_equal '/Namespace::Artist/new'
1147
+ end
1148
+ end
@@ -58,8 +58,10 @@ 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'
61
+ if Rails.version > '4.2'
62
62
  config.action_dispatch.cookies_serializer = :json
63
+ end
64
+ if Rails.version > '5'
63
65
  # Force Rails to dispatch to correct controller
64
66
  ActionDispatch::Routing::RouteSet::Dispatcher.class_eval do
65
67
  define_method(:controller){|_| controller}
@@ -33,7 +33,6 @@ HTML
33
33
  use Rack::Session::Cookie, :secret => '1'
34
34
  use Rack::Csrf
35
35
 
36
- plugin :static_path_info unless ENV['RODA_NO_STATIC_PATH_INFO']
37
36
  template_opts = {:default_encoding=>nil}
38
37
  plugin :render, :layout=>{:inline=>LAYOUT}, :template_opts=>template_opts, :opts=>template_opts
39
38
  plugin :not_found do
@@ -3,7 +3,7 @@ require 'sequel'
3
3
  require 'logger'
4
4
 
5
5
  module AutoFormeSpec
6
- TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric}
6
+ TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric, :boolean=>TrueClass}
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:/'
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.6.0
4
+ version: 1.7.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: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forme
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.0
19
+ version: 1.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.0
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +194,7 @@ dependencies:
194
194
  version: '0'
195
195
  description: |
196
196
  AutoForme is an web administrative console for Sequel::Model that
197
- supports Sinatra and Rails. It offers the following features:
197
+ supports Roda, Sinatra, and Rails. It offers the following features:
198
198
 
199
199
  * Create, update, edit, and view model objects
200
200
  * Browse and search model objects
@@ -250,7 +250,7 @@ rdoc_options:
250
250
  - "--line-numbers"
251
251
  - "--inline-source"
252
252
  - "--title"
253
- - 'AutoForme: Web Administrative Console for Sinatra/Rails and Sequel'
253
+ - 'AutoForme: Web Administrative Console for Roda/Sinatra/Rails and Sequel::Model'
254
254
  - "--main"
255
255
  - README.rdoc
256
256
  require_paths:
@@ -267,8 +267,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  version: '0'
268
268
  requirements: []
269
269
  rubyforge_project:
270
- rubygems_version: 2.6.11
270
+ rubygems_version: 2.6.13
271
271
  signing_key:
272
272
  specification_version: 4
273
- summary: Web Administrative Console for Sinatra/Rails and Sequel
273
+ summary: Web Administrative Console for Roda/Sinatra/Rails and Sequel::Model
274
274
  test_files: []