autoforme 1.8.0 → 1.9.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 +6 -0
- data/lib/autoforme/action.rb +1 -1
- data/lib/autoforme/frameworks/roda.rb +18 -0
- data/lib/autoforme/version.rb +1 -1
- data/spec/basic_spec.rb +3 -1
- data/spec/roda_spec_helper.rb +20 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1754f8c1e90ba00be770867d9f31f44174795d39bdba0ea4b4f042cdff18412f
|
4
|
+
data.tar.gz: '09cd6e1316462bdceaa7e352b846430fdc319bfcfaac0aba488ffa0b2043113c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33b535cf2f5a8b1b40300077323b68665091fce86cadc577955986baacc1bfc65b2ee74fecb3688ee453424a29e38c60876358e5b68daa11b05539f031c2620e
|
7
|
+
data.tar.gz: dd05af8198487de125df170d72c3bc37c4497ebfa6d59c71d9a55285372b49fda99516640f8a4e49f06f44396ec1b731bb039350d73a9f1a7ebc320e8a10ada2
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.9.0 (2018-07-18)
|
2
|
+
|
3
|
+
* Add support for using flash string keys in the Roda support, to work with Roda's sessions plugin (jeremyevans)
|
4
|
+
|
5
|
+
* Show correct page title on error pages (jeremyevans)
|
6
|
+
|
1
7
|
=== 1.8.0 (2018-06-11)
|
2
8
|
|
3
9
|
* Add support for Roda route_csrf plugin for request-specific CSRF tokens (jeremyevans)
|
data/lib/autoforme/action.rb
CHANGED
@@ -37,6 +37,18 @@ module AutoForme
|
|
37
37
|
@env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
|
38
38
|
end
|
39
39
|
|
40
|
+
# Set the flash at notice level when redirecting, so it shows
|
41
|
+
# up on the redirected page.
|
42
|
+
def set_flash_notice(message)
|
43
|
+
@controller.flash[flash_symbol_keys? ? :notice : 'notice'] = message
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set the current flash at error level, used when displaying
|
47
|
+
# pages when there is an error.
|
48
|
+
def set_flash_now_error(message)
|
49
|
+
@controller.flash.now[flash_symbol_keys? ? :error : 'error'] = message
|
50
|
+
end
|
51
|
+
|
40
52
|
# Use Rack::Csrf for csrf protection if it is defined.
|
41
53
|
def csrf_token_hash(action=nil)
|
42
54
|
if @controller.respond_to?(:check_csrf!)
|
@@ -53,6 +65,12 @@ module AutoForme
|
|
53
65
|
{::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
|
54
66
|
end
|
55
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def flash_symbol_keys?
|
72
|
+
!@controller.opts[:sessions_convert_symbols]
|
73
|
+
end
|
56
74
|
end
|
57
75
|
|
58
76
|
attr_reader :route_proc
|
data/lib/autoforme/version.rb
CHANGED
data/spec/basic_spec.rb
CHANGED
@@ -573,7 +573,7 @@ describe AutoForme do
|
|
573
573
|
page.all('td').map{|s| s.text}.must_equal []
|
574
574
|
end
|
575
575
|
|
576
|
-
it "should
|
576
|
+
it "should correctly handle validation errors" do
|
577
577
|
app_setup(Artist)
|
578
578
|
Artist.send(:define_method, :validate) do
|
579
579
|
errors.add(:name, "bad name") if name == 'Foo'
|
@@ -583,6 +583,7 @@ describe AutoForme do
|
|
583
583
|
page.title.must_equal 'Artist - New'
|
584
584
|
fill_in 'Name', :with=>'Foo'
|
585
585
|
click_button 'Create'
|
586
|
+
page.title.must_equal 'Artist - New'
|
586
587
|
page.html.must_include 'Error Creating Artist'
|
587
588
|
page.html.must_include 'bad name'
|
588
589
|
fill_in 'Name', :with=>'TestArtistNew'
|
@@ -597,6 +598,7 @@ describe AutoForme do
|
|
597
598
|
click_button 'Edit'
|
598
599
|
fill_in 'Name', :with=>'Foo'
|
599
600
|
click_button 'Update'
|
601
|
+
page.title.must_equal 'Artist - Edit'
|
600
602
|
page.html.must_include 'Error Updating Artist'
|
601
603
|
page.html.must_include 'bad name'
|
602
604
|
fill_in 'Name', :with=>'TestArtistUpdate'
|
data/spec/roda_spec_helper.rb
CHANGED
@@ -4,8 +4,7 @@ require 'autoforme'
|
|
4
4
|
require 'rack/csrf'
|
5
5
|
|
6
6
|
begin
|
7
|
-
require '
|
8
|
-
require 'tilt/erubis'
|
7
|
+
require 'tilt/erubi'
|
9
8
|
rescue LoadError
|
10
9
|
require 'tilt/erb'
|
11
10
|
end
|
@@ -20,17 +19,31 @@ class AutoFormeSpec::App < Roda
|
|
20
19
|
<html>
|
21
20
|
<head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
|
22
21
|
<body>
|
23
|
-
<% if flash[:notice] %>
|
24
|
-
<div class="alert alert-success"><p><%=
|
22
|
+
<% if notice = opts[:sessions_convert_symbols] ? flash['notice'] : flash[:notice] %>
|
23
|
+
<div class="alert alert-success"><p><%= notice %></p></div>
|
25
24
|
<% end %>
|
26
|
-
<% if flash[:error] %>
|
27
|
-
<div class="alert alert-error"><p><%=
|
25
|
+
<% if error = opts[:sessions_convert_symbols] ? flash['error'] : flash[:error] %>
|
26
|
+
<div class="alert alert-error"><p><%= error %></p></div>
|
28
27
|
<% end %>
|
29
28
|
<%= yield %>
|
30
29
|
</body></html>"
|
31
30
|
HTML
|
32
31
|
|
33
|
-
|
32
|
+
plugin :flash
|
33
|
+
|
34
|
+
if defined?(Roda::RodaVersionNumber) && Roda::RodaVersionNumber >= 30100
|
35
|
+
if ENV['RODA_ROUTE_CSRF'] == '0'
|
36
|
+
require 'roda/session_middleware'
|
37
|
+
opts[:sessions_convert_symbols] = true
|
38
|
+
use RodaSessionMiddleware, :secret=>SecureRandom.random_bytes(64)
|
39
|
+
else
|
40
|
+
ENV['RODA_ROUTE_CSRF'] ||= '1'
|
41
|
+
plugin :sessions, :secret=>SecureRandom.random_bytes(64)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
use Rack::Session::Cookie, :secret => '1'
|
45
|
+
end
|
46
|
+
|
34
47
|
if ENV['RODA_ROUTE_CSRF'].to_i > 0
|
35
48
|
plugin :route_csrf, :require_request_specific_tokens=>ENV['RODA_ROUTE_CSRF'] == '1'
|
36
49
|
else
|
@@ -42,7 +55,6 @@ HTML
|
|
42
55
|
plugin :not_found do
|
43
56
|
'Unhandled Request'
|
44
57
|
end
|
45
|
-
plugin :flash
|
46
58
|
|
47
59
|
def self.autoforme(klass=nil, opts={}, &block)
|
48
60
|
sc = Class.new(self)
|
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.9.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: 2018-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forme
|