autoforme 1.3.0 → 1.4.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 +10 -0
- data/Rakefile +5 -1
- data/lib/autoforme/frameworks/rails.rb +1 -0
- data/lib/autoforme/frameworks/roda.rb +3 -1
- data/lib/autoforme/frameworks/sinatra.rb +3 -3
- data/lib/autoforme/models/sequel.rb +2 -1
- data/lib/autoforme/request.rb +17 -2
- data/lib/autoforme/version.rb +1 -1
- data/spec/basic_spec.rb +29 -5
- data/spec/mtm_spec.rb +1 -0
- data/spec/sequel_spec_helper.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299ca55f54b46bf0629229262853d3dc19a5bc64
|
4
|
+
data.tar.gz: c136195e2191c628c71b0e66e8dad48db965ac37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fe74271b2d60e2269041d3c8c17300538d043eb5901d97e4c73936a088c8f9d9524c9c09419edac647188eb3ffecc6b2fee1b91ccf05516694e43c16c0ebdb7
|
7
|
+
data.tar.gz: f4680d5384dfa5984579f4d7022b956d1e0d6c077b3069de0543b5a8d4260d0bb23e662839f7992f434cd2542cb8ce3766cc8cc32c2d0d94203424071996a2d9
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 1.4.0 (2016-05-18)
|
2
|
+
|
3
|
+
* Handle selecting a blank object during show/edit/delete/mtm_edit by showing the same page (jeremyevans)
|
4
|
+
|
5
|
+
* Support UUID primary keys (badosu, jeremyevans) (#6)
|
6
|
+
|
7
|
+
* Add Request#env for getting the environment for the request (jeremyevans)
|
8
|
+
|
9
|
+
* Handle search results pagination correctly when an id parameter is used (badosu, jeremyevans) (#5)
|
10
|
+
|
1
11
|
=== 1.3.0 (2016-02-02)
|
2
12
|
|
3
13
|
* Add support for running with --enable-frozen-string-literal on ruby 2.3 (jeremyevans)
|
data/Rakefile
CHANGED
@@ -18,7 +18,11 @@ end
|
|
18
18
|
task :default => :roda_spec
|
19
19
|
|
20
20
|
desc "Run specs for all frameworks"
|
21
|
-
|
21
|
+
spec_tasks = [:roda_spec, :sinatra_spec]
|
22
|
+
if RUBY_VERSION >= '1.9'
|
23
|
+
spec_tasks << :rails_spec
|
24
|
+
end
|
25
|
+
task :spec => spec_tasks
|
22
26
|
|
23
27
|
%w'roda sinatra rails'.each do |framework|
|
24
28
|
desc "Run specs with for #{framework} with coverage"
|
@@ -15,7 +15,7 @@ module AutoForme
|
|
15
15
|
@model = captures[0]
|
16
16
|
@action_type = captures[1]
|
17
17
|
@path = @env['SCRIPT_NAME']
|
18
|
-
|
18
|
+
set_id(captures[2])
|
19
19
|
end
|
20
20
|
|
21
21
|
# Redirect to the given path
|
@@ -58,8 +58,8 @@ 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
|
+
@controller.get %r{\A#{prefix}/(\w+)/(\w+)(?:/([\w-]+))?\z}, &block
|
62
|
+
@controller.post %r{\A#{prefix}/(\w+)/(\w+)(?:/([\w-]+))?\z}, &block
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -193,7 +193,8 @@ module AutoForme
|
|
193
193
|
def paginate(type, request, ds, opts={})
|
194
194
|
return ds.all if opts[:all_results]
|
195
195
|
limit = limit_for(type, request)
|
196
|
-
|
196
|
+
%r{\/(\d+)\z} =~ request.env['PATH_INFO']
|
197
|
+
offset = (($1||1).to_i - 1) * limit
|
197
198
|
objs = ds.limit(limit+1, (offset if offset > 0)).all
|
198
199
|
next_page = false
|
199
200
|
if objs.length > limit
|
data/lib/autoforme/request.rb
CHANGED
@@ -20,10 +20,12 @@ module AutoForme
|
|
20
20
|
attr_reader :path
|
21
21
|
|
22
22
|
# The id related to the request, which is usually the primary
|
23
|
-
# key of the related model instance
|
24
|
-
# pages is used as the page
|
23
|
+
# key of the related model instance.
|
25
24
|
attr_reader :id
|
26
25
|
|
26
|
+
# The HTTP request environment hash
|
27
|
+
attr_reader :env
|
28
|
+
|
27
29
|
# The params for the current request
|
28
30
|
attr_reader :params
|
29
31
|
|
@@ -51,5 +53,18 @@ module AutoForme
|
|
51
53
|
def set_flash_now_error(message)
|
52
54
|
@controller.flash.now[:error] = message
|
53
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def set_id(path_id)
|
60
|
+
@id = path_id
|
61
|
+
if param_id = @params['id']
|
62
|
+
case @action_type
|
63
|
+
when 'show', 'edit', 'delete', 'mtm_edit'
|
64
|
+
@id = param_id
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@id = nil if @id && @id.empty?
|
68
|
+
end
|
54
69
|
end
|
55
70
|
end
|
data/lib/autoforme/version.rb
CHANGED
data/spec/basic_spec.rb
CHANGED
@@ -20,12 +20,14 @@ describe AutoForme do
|
|
20
20
|
|
21
21
|
click_link 'Show'
|
22
22
|
page.title.must_equal 'Artist - Show'
|
23
|
+
click_button 'Show'
|
23
24
|
select 'TestArtistNew'
|
24
25
|
click_button 'Show'
|
25
26
|
page.html.must_match /Name.+TestArtistNew/m
|
26
27
|
|
27
28
|
click_link 'Edit'
|
28
29
|
page.title.must_equal 'Artist - Edit'
|
30
|
+
click_button 'Edit'
|
29
31
|
select 'TestArtistNew'
|
30
32
|
click_button 'Edit'
|
31
33
|
fill_in 'Name', :with=>'TestArtistUpdate'
|
@@ -142,6 +144,23 @@ describe AutoForme do
|
|
142
144
|
click_button 'Edit'
|
143
145
|
end
|
144
146
|
|
147
|
+
it "should support showing models with custom ids" do
|
148
|
+
db_setup(:tracks => proc do
|
149
|
+
column :id, String, :primary_key => true
|
150
|
+
column :name, String
|
151
|
+
end)
|
152
|
+
|
153
|
+
model_setup(:Track => [:tracks])
|
154
|
+
Track.unrestrict_primary_key
|
155
|
+
app_setup(Track)
|
156
|
+
|
157
|
+
Track.create(:id => 'dark-side', :name => 'The Dark Side of the Moon')
|
158
|
+
|
159
|
+
visit("/Track/show/dark-side")
|
160
|
+
|
161
|
+
page.html.must_include 'The Dark Side of the Moon'
|
162
|
+
end
|
163
|
+
|
145
164
|
it "should support custom redirects" do
|
146
165
|
app_setup(Artist) do
|
147
166
|
redirect do |obj, type, req|
|
@@ -162,6 +181,7 @@ describe AutoForme do
|
|
162
181
|
click_button 'Update'
|
163
182
|
page.current_path.must_match %r{/Artist/show/\d}
|
164
183
|
click_link 'Delete'
|
184
|
+
click_button 'Delete'
|
165
185
|
select 'TestArtistNew'
|
166
186
|
click_button 'Delete'
|
167
187
|
click_button 'Delete'
|
@@ -312,28 +332,32 @@ describe AutoForme do
|
|
312
332
|
end
|
313
333
|
5.times{|i| Artist.create(:name=>i.to_s)}
|
314
334
|
visit("/Artist/browse")
|
315
|
-
|
335
|
+
pager_class = lambda do |text|
|
336
|
+
node = all('ul.pager li').select{|n| n[:class] if n.find('a').text == text}.first
|
337
|
+
node[:class] if node
|
338
|
+
end
|
339
|
+
pager_class.call("Previous").must_equal 'disabled'
|
316
340
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1'
|
317
341
|
click_link 'Next'
|
318
342
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 3'
|
319
343
|
click_link 'Next'
|
320
344
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'4'
|
321
|
-
|
345
|
+
pager_class.call("Next").must_equal 'disabled'
|
322
346
|
click_link 'Previous'
|
323
347
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 3'
|
324
348
|
click_link 'Previous'
|
325
349
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1'
|
326
|
-
|
350
|
+
pager_class.call("Previous").must_equal 'disabled'
|
327
351
|
|
328
352
|
click_link 'Search'
|
329
353
|
click_button 'Search'
|
330
354
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1 2'
|
331
355
|
click_link 'Next'
|
332
356
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'3 4'
|
333
|
-
|
357
|
+
pager_class.call("Next").must_equal 'disabled'
|
334
358
|
click_link 'Previous'
|
335
359
|
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1 2'
|
336
|
-
|
360
|
+
pager_class.call("Previous").must_equal 'disabled'
|
337
361
|
end
|
338
362
|
|
339
363
|
it "should support specifying supported actions" do
|
data/spec/mtm_spec.rb
CHANGED
data/spec/sequel_spec_helper.rb
CHANGED
@@ -5,16 +5,23 @@ require 'logger'
|
|
5
5
|
module AutoFormeSpec
|
6
6
|
TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric}
|
7
7
|
def self.db_setup(tables)
|
8
|
-
|
8
|
+
db_url = ENV['DATABASE_URL']
|
9
|
+
db_url ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
10
|
+
db = Sequel.connect(db_url)
|
9
11
|
#db.loggers << Logger.new($stdout)
|
10
|
-
tables.each do |table,
|
12
|
+
tables.each do |table, table_spec|
|
11
13
|
db.create_table(table) do
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
if table_spec.kind_of? Enumerable
|
15
|
+
primary_key :id
|
16
|
+
table_spec.each do |name, type, opts|
|
17
|
+
column name, TYPE_MAP[type], opts||{}
|
18
|
+
end
|
19
|
+
elsif table_spec.respond_to? :call
|
20
|
+
self.instance_eval(&table_spec)
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
24
|
+
|
18
25
|
db
|
19
26
|
end
|
20
27
|
|
@@ -22,7 +29,7 @@ module AutoFormeSpec
|
|
22
29
|
models.each do |name, (table, associations)|
|
23
30
|
klass = Class.new(Sequel::Model(db[table]))
|
24
31
|
Object.const_set(name, klass)
|
25
|
-
klass.class_eval do
|
32
|
+
klass.class_eval do
|
26
33
|
if associations
|
27
34
|
associations.each do |type, assoc, opts|
|
28
35
|
associate(type, assoc, opts||{})
|
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.4.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-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forme
|