galakei 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  # Takes care of recoding pages to Shift-JIS for some handsets when required
2
+ require 'nkf'
2
3
  class Galakei::Filter::Recode < Galakei::Filter::Base
3
4
  def self.inject(klass)
4
5
  this_class = self
5
- klass.after_filter self, :if => lambda {|c| this_class.condition?(c) }
6
+ klass.around_filter self, :if => lambda {|c| this_class.condition?(c) }
6
7
  end
7
8
 
8
9
  def condition?
@@ -10,8 +11,30 @@ class Galakei::Filter::Recode < Galakei::Filter::Base
10
11
  end
11
12
 
12
13
  def filter
14
+ deep_apply(controller.params) do |param|
15
+ NKF.nkf('-Sw', param)
16
+ end
17
+ yield
13
18
  doc = Nokogiri::HTML(response.body)
14
19
  response.body = doc.serialize(:encoding => 'Shift_JIS')
15
20
  response.charset = "Shift_JIS"
16
21
  end
22
+
23
+ private
24
+ def deep_apply(obj, &proc)
25
+ case obj
26
+ when Hash
27
+ obj.each_pair do |key, value|
28
+ obj[key] = deep_apply(value, &proc)
29
+ end
30
+ when Array
31
+ obj.collect!{|value| deep_apply(value, &proc)}
32
+ when String
33
+ obj = obj.to_param if obj.respond_to?(:to_param)
34
+ proc.call(obj)
35
+ else
36
+ # NilClass, TrueClass, FalseClass, Tempfile, StringIO, etc...
37
+ return obj
38
+ end
39
+ end
17
40
  end
@@ -1,3 +1,3 @@
1
1
  module Galakei
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -2,9 +2,26 @@
2
2
  require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
3
3
 
4
4
  class RecodeController < ApplicationController
5
+ class << self
6
+ attr_accessor :string
7
+ end
8
+
5
9
  def index
6
10
  render :layout => true, :inline => "Test"
7
11
  end
12
+
13
+ def new
14
+ render :layout => true, :inline => <<-EOD
15
+ <form action="/recode/create" method="post">
16
+ <input id="string" name="string" type="text">
17
+ <input name="commit" type="submit" value="Submit">
18
+ </form>
19
+ EOD
20
+ end
21
+
22
+ def create
23
+ self.class.string = params[:string]
24
+ end
8
25
  end
9
26
 
10
27
  feature 'recode' do
@@ -12,4 +29,18 @@ feature 'recode' do
12
29
  visit 'https://www.example.com/recode/index'
13
30
  page.find(:xpath, '//head/meta')['content'].should == "text/html; charset=Shift_JIS"
14
31
  end
32
+
33
+ scenario 'post request with Shift JIS data on au SSL', :driver => :au do
34
+ visit 'https://www.example.com/recode/new'
35
+ fill_in 'string', :with => "\x82\xA0"
36
+ click_button "Submit"
37
+ RecodeController.string.should == "あ"
38
+ end
39
+
40
+ scenario 'post request with UTF-8 data on au SSL', :driver => :au do
41
+ visit 'https://www.example.com/recode/new'
42
+ fill_in 'string', :with => "あ"
43
+ click_button "Submit"
44
+ RecodeController.string.should_not == "あ"
45
+ end
15
46
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: galakei
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.3
5
+ version: 0.6.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul McMahon
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-04-20 00:00:00 +09:00
15
+ date: 2011-04-21 00:00:00 +09:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency