galakei 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/galakei.rb CHANGED
@@ -4,6 +4,7 @@ if defined?(Rails)
4
4
  end
5
5
  require 'galakei/request'
6
6
  require 'galakei/docomo_css'
7
+ require 'galakei/session_id_parameter'
7
8
 
8
9
  module Galakei
9
10
  autoload :Email, "galakei/email"
@@ -16,10 +17,5 @@ module Galakei
16
17
  autoload :ContentType, "galakei/filter/content_type"
17
18
  autoload :Haml, "galakei/filter/haml"
18
19
  autoload :Views, "galakei/filter/views"
19
- autoload :SessionIdParameter, "galakei/filter/session_id_parameter"
20
- end
21
- module SessionIdParameter
22
- autoload :InForm, "galakei/session_id_parameter/in_form"
23
- autoload :InUrl, "galakei/session_id_parameter/in_url"
24
20
  end
25
21
  end
@@ -0,0 +1,6 @@
1
+ module Galakei
2
+ module SessionIdParameter
3
+ autoload :InForm, "galakei/session_id_parameter/in_form"
4
+ autoload :InUrl, "galakei/session_id_parameter/in_url"
5
+ end
6
+ end
@@ -1,10 +1,27 @@
1
+ # When making a get request from a form, query string parameters are ignored.
2
+ # Instead, the parameters must be added as hidden fields. This module ensures
3
+ # that the session id parameter is properly injected into forms.
1
4
  module Galakei::SessionIdParameter::InForm
2
5
  def extra_tags_for_form(html_options)
3
6
  s = super
4
7
  if !request.cookies? && html_options["method"] == "get"
5
- key = ::Rails.application.config.session_options[:key]
6
- s << tag(:input, :type => "hidden", :name => key, :value => request.session_options[:id])
8
+ s << session_input_tag
7
9
  end
8
10
  s
9
11
  end
12
+
13
+ def button_to(name, options = {}, html_options = {})
14
+ s = super
15
+ if !request.cookies? && html_options[:method] == :get
16
+ s.sub!("</form>",session_input_tag + "</form>".html_safe)
17
+ end
18
+ s
19
+ end
20
+
21
+ private
22
+
23
+ def session_input_tag
24
+ key = ::Rails.application.config.session_options[:key]
25
+ tag(:input, :type => "hidden", :name => key, :value => request.session_options[:id])
26
+ end
10
27
  end
@@ -1,3 +1,3 @@
1
1
  module Galakei
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -15,7 +15,7 @@ class SessionsController < ApplicationController
15
15
  render :layout => true, :inline => <<-EOD
16
16
  <%= form_for @search, :url => "/sessions", :html => { :method => :get } do |f| %>"
17
17
  <%= f.text_field :query %>
18
- <%= f.submit %>
18
+ <%= f.submit "in_get_form" %>
19
19
  <% end %>
20
20
  EOD
21
21
  end
@@ -23,7 +23,21 @@ class SessionsController < ApplicationController
23
23
  def link
24
24
  session[:previous_page] = "link"
25
25
  render :layout => true, :inline => <<-EOD
26
- <%= link_to "Link", :action => :index %>
26
+ <%= link_to "link", :action => :index %>
27
+ EOD
28
+ end
29
+
30
+ def button_to_get
31
+ session[:previous_page] = "button_to_get"
32
+ render :layout => true, :inline => <<-EOD
33
+ <%= button_to "button_to_get", {:action => :index}, :method => :get %>
34
+ EOD
35
+ end
36
+
37
+ def button_to_post
38
+ session[:previous_page] = "button_to_post"
39
+ render :layout => true, :inline => <<-EOD
40
+ <%= button_to "button_to_post", :action => :index %>
27
41
  EOD
28
42
  end
29
43
 
@@ -37,34 +51,36 @@ end
37
51
 
38
52
 
39
53
  feature 'session' do
40
- context 'in get form' do
41
- scenario 'for au', :driver => :au do
42
- visit '/sessions/in_get_form'
43
- click_on "Create Search"
44
- page.should have_content("Session Data: in_get_form")
45
- page.should have_content("Session Param: false")
46
- end
54
+ %w[in_get_form link button_to_post].each do |s|
55
+ context s do
56
+ scenario 'for au', :driver => :au do
57
+ visit "/sessions/#{s}"
58
+ click_on s
59
+ page.should have_content("Session Data: #{s}")
60
+ page.should have_content("Session Param: false")
61
+ end
47
62
 
48
- scenario 'for docomo', :driver => :docomo do
49
- visit '/sessions/in_get_form'
50
- click_on "Create Search"
51
- page.should have_content("Session Data: in_get_form")
52
- page.should have_content("Session Param: true")
63
+ scenario 'for docomo', :driver => :docomo do
64
+ visit "/sessions/#{s}"
65
+ click_on s
66
+ page.should have_content("Session Data: #{s}")
67
+ page.should have_content("Session Param: true")
68
+ end
53
69
  end
54
70
  end
55
-
56
- context 'clicking link' do
71
+ context "button_to_get" do
57
72
  scenario 'for au', :driver => :au do
58
- visit '/sessions/link'
59
- click_on "Link"
60
- page.should have_content("Session Data: link")
73
+ visit "/sessions/button_to_get"
74
+ click_on "button_to_get"
75
+ page.should have_content("Session Data: button_to_get")
61
76
  page.should have_content("Session Param: false")
62
77
  end
63
78
 
64
79
  scenario 'for docomo', :driver => :docomo do
65
- visit '/sessions/link'
66
- click_on "Link"
67
- page.should have_content("Session Data: link")
80
+ visit "/sessions/button_to_get"
81
+ page.find('form input[name="_myapp_session"]')["value"].should_not be_blank
82
+ click_on "button_to_get"
83
+ page.should have_content("Session Data: button_to_get")
68
84
  page.should have_content("Session Param: true")
69
85
  end
70
86
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul McMahon
@@ -91,6 +91,7 @@ files:
91
91
  - lib/galakei/input_mode.rb
92
92
  - lib/galakei/railtie.rb
93
93
  - lib/galakei/request.rb
94
+ - lib/galakei/session_id_parameter.rb
94
95
  - lib/galakei/session_id_parameter/in_form.rb
95
96
  - lib/galakei/session_id_parameter/in_url.rb
96
97
  - lib/galakei/session_id_parameter/railtie.rb