galakei 0.3.2 → 0.3.3

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.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .bundle
2
2
  Gemfile.lock
3
3
  pkg/*
4
+ log
data/Gemfile CHANGED
@@ -5,4 +5,8 @@ gemspec
5
5
 
6
6
  group :development do
7
7
  gem 'rspec', '>= 2.5.0'
8
+ gem 'capybara'
9
+ gem 'steak'
10
+ gem 'sqlite3'
11
+ gem 'rspec-rails'
8
12
  end
@@ -41,7 +41,7 @@ module Galakei
41
41
  else
42
42
  options[:istyle] = inputmode[:istyle]
43
43
  options[:mode] = inputmode[:mode]
44
- options[:style] ||= %Q{-wap-input-format:*#{inputmode[:other_wap_input_format]};}
44
+ options[:style] ||= %Q{-wap-input-format:*#{inputmode[:other_wap_input_format]}}
45
45
  end
46
46
  end
47
47
  end
@@ -1,20 +1,21 @@
1
+ require 'docomo_css'
2
+
1
3
  module Galakei
2
4
  class Railtie < Rails::Railtie
3
5
  config.galakei = ActiveSupport::OrderedOptions.new
4
- config.galakei.session_id_parameter = false
5
6
  initializer "galakei.extend.action_controller", :after => "docomo_css.extend.action_controller" do |app|
6
7
  ActiveSupport.on_load :action_controller do
7
8
  include Galakei::HelperMethods
8
9
  docomo_filter
9
10
  filters = %w[Views ContentType]
10
11
  filters << :Haml if defined?(Haml)
11
- filters << :SessionIdParameter if app.config.galakei.session_id_parameter
12
12
  filters.each {|f| Galakei::Filter.const_get(f).inject(self) }
13
13
  end
14
14
  ActiveSupport.on_load :action_view do
15
15
  include Galakei::InputMode
16
- include Galakei::SessionIdParameterInForm
17
16
  end
18
17
  end
19
18
  end
20
19
  end
20
+
21
+ require 'galakei/session_id_parameter/railtie'
@@ -0,0 +1,10 @@
1
+ module Galakei::SessionIdParameter::InForm
2
+ def extra_tags_for_form(html_options)
3
+ s = super
4
+ 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])
7
+ end
8
+ s
9
+ end
10
+ end
@@ -1,8 +1,4 @@
1
- class Galakei::Filter::SessionIdParameter < Galakei::Filter::Base
2
- def self.inject(klass)
3
- klass.before_filter self
4
- end
5
-
1
+ class Galakei::SessionIdParameter::InUrl < Galakei::Filter::Base
6
2
  def filter
7
3
  key = ::Rails.application.config.session_options[:key]
8
4
  if device_needs_session_param_in_url?
@@ -0,0 +1,19 @@
1
+ require 'docomo_css'
2
+
3
+ module Galakei
4
+ module SessionIdParameter
5
+ class Railtie < Rails::Railtie
6
+ config.galakei.session_id_parameter = false
7
+ initializer "galakei.session_id_parameter" do |app|
8
+ if app.config.galakei.session_id_parameter
9
+ ActiveSupport.on_load :action_controller do
10
+ before_filter Galakei::SessionIdParameter::InUrl
11
+ end
12
+ ActiveSupport.on_load :action_view do
13
+ include Galakei::SessionIdParameter::InForm
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Galakei
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/galakei.rb CHANGED
@@ -18,4 +18,8 @@ module Galakei
18
18
  autoload :Views, "galakei/filter/views"
19
19
  autoload :SessionIdParameter, "galakei/filter/session_id_parameter"
20
20
  end
21
+ module SessionIdParameter
22
+ autoload :InForm, "galakei/session_id_parameter/in_form"
23
+ autoload :InUrl, "galakei/session_id_parameter/in_url"
24
+ end
21
25
  end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require "steak"
3
+ require 'capybara/rspec'
4
+ require File.expand_path(File.dirname(__FILE__) + "/app/fake")
5
+
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+
8
+ require 'rspec/rails'
@@ -0,0 +1,20 @@
1
+ require 'rails'
2
+ require 'active_record'
3
+ require 'action_controller/railtie'
4
+ require 'action_view/railtie'
5
+ require 'galakei/railtie'
6
+
7
+ # database
8
+ ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
9
+ ActiveRecord::Base.establish_connection('test')
10
+
11
+ # config
12
+ app = Class.new(Rails::Application)
13
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
14
+ app.config.session_store :cookie_store, :key => "_myapp_session"
15
+ app.config.active_support.deprecation = :log
16
+ app.config.galakei.session_id_parameter = true
17
+ app.initialize!
18
+
19
+ app.routes.draw { match ':controller(/:action(/:id))' }
20
+ class ApplicationController < ActionController::Base; end
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
3
+
4
+ class EmojiController < ApplicationController
5
+ def index
6
+ render :inline => "<%= emoji_table.black_sun_with_rays %>"
7
+ end
8
+ end
9
+
10
+ feature 'emoji table' do
11
+ scenario 'for docomo', :driver => :docomo do
12
+ visit '/emoji'
13
+ page.body.should match("&#xE63E;")
14
+ end
15
+
16
+ scenario 'for au', :driver => :au do
17
+ visit '/emoji'
18
+ page.body.should match("&#xE488;")
19
+ end
20
+
21
+ scenario 'for softbank', :driver => :softbank do
22
+ visit '/emoji'
23
+ page.body.should match("&#xE04A;")
24
+ end
25
+
26
+ scenario 'for non galakei' do
27
+ visit '/emoji'
28
+ page.body.should match("&#x2600;")
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
3
+
4
+ class HandsetDetectionController < ApplicationController
5
+ def index
6
+ render :inline => <<-ERB
7
+ <% if galakei? %>
8
+ <% if request.docomo? %>
9
+ docomo
10
+ <% elsif request.au? %>
11
+ au
12
+ <% elsif request.softbank? %>
13
+ softbank
14
+ <% end %>
15
+ <% else %>
16
+ not galakei
17
+ <% end %>
18
+ ERB
19
+ end
20
+ end
21
+
22
+
23
+ feature 'handset detection' do
24
+ scenario 'for docomo', :driver => :docomo do
25
+ visit '/handset_detection'
26
+ page.body.should match("docomo")
27
+ end
28
+
29
+ scenario 'for au', :driver => :au do
30
+ visit '/handset_detection'
31
+ page.body.should match("au")
32
+ end
33
+
34
+ scenario 'for softbank', :driver => :softbank do
35
+ visit '/handset_detection'
36
+ page.body.should match("softbank")
37
+ end
38
+
39
+ scenario 'for non galakei' do
40
+ visit '/handset_detection'
41
+ page.body.should match("not galakei")
42
+ end
43
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
3
+
4
+ class InputModeController < ApplicationController
5
+ class User
6
+ extend ActiveModel::Naming
7
+ include ActiveModel::Conversion
8
+ attr_accessor :hiragana, :hankaku_kana, :alphabet, :number_input_mode, :number_type
9
+ def persisted?; false end
10
+ end
11
+ def index
12
+ @user = User.new
13
+ render :inline => <<-EOD
14
+ <%= form_for @user, :url => "/" do |f| %>"
15
+ <%= f.text_field :hiragana, :inputmode => "hiragana" %>
16
+ <%= f.text_field :hankaku_kana, :inputmode => "hankaku_kana" %>
17
+ <%= f.text_field :alphabet, :inputmode => "alphabet" %>
18
+ <%= f.text_field :number_input_mode, :inputmode => "number" %>
19
+ <%= f.text_field :number_type, :type => "number" %>
20
+ <% end %>
21
+ EOD
22
+ end
23
+ end
24
+
25
+ feature 'input mode' do
26
+ scenario 'for docomo', :driver => :docomo do
27
+ visit '/input_mode'
28
+ within 'form' do
29
+ hiragana_input = page.find("#input_mode_controller_user_hiragana")
30
+ hiragana_input["style"].should == '-wap-input-format:"*<ja:h>"'
31
+ hankaku_kana_input = page.find("#input_mode_controller_user_hankaku_kana")
32
+ hankaku_kana_input["style"].should == '-wap-input-format:"*<ja:hk>"'
33
+ alphabet_input = page.find("#input_mode_controller_user_alphabet")
34
+ alphabet_input["style"].should == '-wap-input-format:"*<ja:en>"'
35
+ %w[input_mode type].each do |s|
36
+ e = page.find("#input_mode_controller_user_number_#{s}")
37
+ e["style"].should == '-wap-input-format:"*<ja:n>"'
38
+ end
39
+ end
40
+ end
41
+
42
+ # Although this markup should work for both au and softbank, since we are
43
+ # dynamicly determining this, perhaps we should just put in appropriate stuff
44
+ %w[au softbank].each do |carrier|
45
+ scenario "for #{carrier}", :driver => carrier.to_sym do
46
+ visit '/input_mode'
47
+ within 'form' do
48
+ e = page.find("#input_mode_controller_user_hiragana")
49
+ e["style"].should == '-wap-input-format:*M'
50
+ e["mode"].should == 'hiragana'
51
+ e["istyle"].should == '1'
52
+
53
+ e = page.find("#input_mode_controller_user_hankaku_kana")
54
+ e["style"].should == '-wap-input-format:*M'
55
+ e["mode"].should == 'hankakukana'
56
+ e["istyle"].should == '2'
57
+
58
+ e = page.find("#input_mode_controller_user_alphabet")
59
+ e["style"].should == '-wap-input-format:*m'
60
+ e["mode"].should == 'alphabet'
61
+ e["istyle"].should == '3'
62
+
63
+ %w[input_mode type].each do |s|
64
+ e = page.find("#input_mode_controller_user_number_#{s}")
65
+ e["style"].should == '-wap-input-format:*N'
66
+ e["mode"].should == 'numeric'
67
+ e["istyle"].should == '4'
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
3
+
4
+ class SessionsController < ApplicationController
5
+ class Search
6
+ extend ActiveModel::Naming
7
+ include ActiveModel::Conversion
8
+ attr_accessor :query
9
+ def persisted?; false end
10
+ end
11
+
12
+ def in_get_form
13
+ session[:previous_page] = "in_get_form"
14
+ @search = Search.new
15
+ render :inline => <<-EOD
16
+ <%= form_for @search, :url => "/sessions", :html => { :method => :get } do |f| %>"
17
+ <%= f.text_field :query %>
18
+ <%= f.submit %>
19
+ <% end %>
20
+ EOD
21
+ end
22
+
23
+ def link
24
+ session[:previous_page] = "link"
25
+ render :inline => <<-EOD
26
+ <%= link_to "Link", :action => :index %>
27
+ EOD
28
+ end
29
+
30
+ def index
31
+ render :inline => <<-EOD
32
+ Session Data: #{session[:previous_page]}
33
+ Session Param: #{params.key?(:_myapp_session)}
34
+ EOD
35
+ end
36
+ end
37
+
38
+
39
+ 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
47
+
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")
53
+ end
54
+ end
55
+
56
+ context 'clicking link' do
57
+ scenario 'for au', :driver => :au do
58
+ visit '/sessions/link'
59
+ click_on "Link"
60
+ page.should have_content("Session Data: link")
61
+ page.should have_content("Session Param: false")
62
+ end
63
+
64
+ scenario 'for docomo', :driver => :docomo do
65
+ visit '/sessions/link'
66
+ click_on "Link"
67
+ page.should have_content("Session Data: link")
68
+ page.should have_content("Session Param: true")
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ class Capybara::Driver::RackTestWithUserAgent < Capybara::Driver::RackTest
2
+ def initialize(app, user_agent)
3
+ super(app)
4
+ @user_agent = user_agent
5
+ end
6
+ private
7
+ def env
8
+ super.tap {|env| env['HTTP_USER_AGENT'] = @user_agent }
9
+ end
10
+ end
11
+
12
+ Capybara.register_driver :docomo do |app|
13
+ Capybara::Driver::RackTestWithUserAgent.new(app, "DoCoMo/2.0 P903i(c100;TB;W24H12)")
14
+ end
15
+
16
+ Capybara.register_driver :au do |app|
17
+ Capybara::Driver::RackTestWithUserAgent.new(app, "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
18
+ end
19
+
20
+ Capybara.register_driver :softbank do |app|
21
+ Capybara::Driver::RackTestWithUserAgent.new(app, "SoftBank/1.0/943SH/SHJ001/SN*************** Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1")
22
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul McMahon
@@ -84,16 +84,24 @@ files:
84
84
  - lib/galakei/filter/base.rb
85
85
  - lib/galakei/filter/content_type.rb
86
86
  - lib/galakei/filter/haml.rb
87
- - lib/galakei/filter/session_id_parameter.rb
88
87
  - lib/galakei/filter/views.rb
89
88
  - lib/galakei/helper_methods.rb
90
89
  - lib/galakei/input_mode.rb
91
90
  - lib/galakei/railtie.rb
92
91
  - lib/galakei/request.rb
93
- - lib/galakei/session_id_parameter_in_form.rb
92
+ - lib/galakei/session_id_parameter/in_form.rb
93
+ - lib/galakei/session_id_parameter/in_url.rb
94
+ - lib/galakei/session_id_parameter/railtie.rb
94
95
  - lib/galakei/shoulda_macros.rb
95
96
  - lib/galakei/use_rack_request_to_extract_sid.rb
96
97
  - lib/galakei/version.rb
98
+ - spec/acceptance/acceptance_helper.rb
99
+ - spec/acceptance/app/fake.rb
100
+ - spec/acceptance/emoji_table_spec.rb
101
+ - spec/acceptance/handset_detection_spec.rb
102
+ - spec/acceptance/input_mode_spec.rb
103
+ - spec/acceptance/session_spec.rb
104
+ - spec/acceptance/support/handsets.rb
97
105
  - spec/galakei/filter/content_type_spec.rb
98
106
  - spec/galakei/request_spec.rb
99
107
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- module Galakei
2
- module SessionIdParameterInForm
3
- def extra_tags_for_form(html_options)
4
- s = super
5
- if html_options["method"] == "get"
6
- key = ::Rails.application.config.session_options[:key]
7
- s << tag(:input, :type => "hidden", :name => key, :value => request.session_options[:id])
8
- end
9
- s
10
- end
11
- end
12
- end