autoforme 1.8.0 → 1.9.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
  SHA256:
3
- metadata.gz: 5112ef1a062e3fa4a586f605365004eb733e25c7e49c7d52d0399d2d5596a692
4
- data.tar.gz: 3142feb7e88e43ec825eedb9dfa700dd2c710cdce59b7839241117ad66b6568a
3
+ metadata.gz: 1754f8c1e90ba00be770867d9f31f44174795d39bdba0ea4b4f042cdff18412f
4
+ data.tar.gz: '09cd6e1316462bdceaa7e352b846430fdc319bfcfaac0aba488ffa0b2043113c'
5
5
  SHA512:
6
- metadata.gz: 937e7ced506f742fbd9ec7632cf69a6a93b1996d884a63996162a38ad949c0ef3b6022a910fe51748f9792c9d9ce3703ffa6691e321f93bcd9917e05f3f24677
7
- data.tar.gz: a369fc3b50aef5cf9546fb512c0d92a63de9cc0f15b8ac16f84b5fa2291f688ea10f0a711ddf9573b3e1c6257015174c147f05af6e7f073ae37be1e392386c85
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)
@@ -87,7 +87,7 @@ module AutoForme
87
87
  else
88
88
  return false unless model.supported_action?(normalized_type, request)
89
89
 
90
- if title = TITLE_MAP[type]
90
+ if title = TITLE_MAP[@normalized_type]
91
91
  @title = "#{model.class_name} - #{title}"
92
92
  end
93
93
  end
@@ -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
@@ -6,7 +6,7 @@ module AutoForme
6
6
  MAJOR = 1
7
7
 
8
8
  # The minor version of AutoForme, updated for new feature releases of AutoForme.
9
- MINOR = 8
9
+ MINOR = 9
10
10
 
11
11
  # The patch version of AutoForme, updated only for bug fixes from the last
12
12
  # feature release.
@@ -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 correct handle validation errors" do
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'
@@ -4,8 +4,7 @@ require 'autoforme'
4
4
  require 'rack/csrf'
5
5
 
6
6
  begin
7
- require 'erubis'
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><%= flash[:notice] %></p></div>
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><%= flash[:error] %></p></div>
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
- use Rack::Session::Cookie, :secret => '1'
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.8.0
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-06-11 00:00:00.000000000 Z
11
+ date: 2018-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forme