utf8_enforcer_workaround 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ *SPIKE*
20
+ *emfile.lock
21
+ tags
22
+
23
+ # For emacs:
24
+ *~
25
+ #\#*
26
+ #.\#*
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ #-*- ruby -*-
2
+ appraise "Rails32" do
3
+ gem "rails", "~> 3.2.0"
4
+ gem "utf8_enforcer_workaround", :path => "../"
5
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in utf8_enforcer_workaround.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jarl Friis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ Utf8EnforcerWorkaround
2
+ ======================
3
+
4
+ Make utf8 enforcer tag to be applied only for non-standards-complying browsers.
5
+
6
+
7
+ Requirements
8
+ ------------
9
+
10
+ `utf8_enforcer_workaround` depends on Rails 3.2 and `browser`
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'utf8_enforcer_workaround'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install utf8_enforcer_workaround
26
+
27
+ Usage
28
+ -----
29
+
30
+ Add this line of code in your ApplicationController:
31
+
32
+ utf8_enforcer_workaround
33
+
34
+
35
+ Contributing
36
+ ------------
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ Copyright
45
+ ---------
46
+
47
+ Copyright (c) 2012 Jarl Friis. See LICENSE.txt for
48
+ further details.
49
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'rake/testtask'
4
+ require 'cucumber/rake/task'
5
+
6
+ desc 'Default: clean, appraisal:install, all.'
7
+ task :default => [:clean, :all]
8
+
9
+ desc 'Test the plugin under all supported Rails versions.'
10
+ task :all do |t|
11
+ if ENV['BUNDLE_GEMFILE']
12
+ exec('rake test cucumber')
13
+ else
14
+ Rake::Task["appraisal:install"].execute
15
+ exec('rake appraisal test cucumber')
16
+ end
17
+ end
18
+
19
+ desc 'Test the plugin.'
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << 'lib' << 'profile'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = true
24
+ end
25
+
26
+ desc 'Run integration test'
27
+ Cucumber::Rake::Task.new do |t|
28
+ t.cucumber_opts = %w{--format progress}
29
+ end
30
+
31
+ desc 'Start an IRB session with all necessary files required.'
32
+ task :shell do |t|
33
+ chdir File.dirname(__FILE__)
34
+ exec 'irb -I lib/ -I lib/utf8_enforcer_workaround -r rubygems -r active_record -r tempfile -r init'
35
+ end
36
+
37
+ desc 'Clean up files.'
38
+ task :clean do |t|
39
+ FileUtils.rm_rf "doc"
40
+ FileUtils.rm_rf "tmp"
41
+ FileUtils.rm_rf "pkg"
42
+ FileUtils.rm_rf "public"
43
+ FileUtils.rm "test/debug.log" rescue nil
44
+ FileUtils.rm "test/utf8_enforcer_workaround.db" rescue nil
45
+ Dir.glob("utf8_enforcer_workaround-*.gem").each{|f| FileUtils.rm f }
46
+ end
@@ -0,0 +1,12 @@
1
+ Feature: Default browsers does not see a utf8 param.
2
+ For Compliant browser there shall be no utf8 parameter in a default form.
3
+
4
+ Background:
5
+ Given I generate a new rails application
6
+ And I run a rails generator to generate a "User" scaffold with "name:string"
7
+ And I run a migration
8
+
9
+ Scenario:
10
+ Given I start the rails application
11
+ When I go to the new user page
12
+ Then there is no utf8 input tag
@@ -0,0 +1,20 @@
1
+ Feature: Non compliant browsers does see a utf8 param.
2
+ For Non compliant browser there shall be a hidden parameter containing a utf8 value.
3
+
4
+ Background:
5
+ Given I generate a new rails application
6
+ And I run a rails generator to generate a "User" scaffold with "name:string"
7
+ And I run a migration
8
+
9
+ Scenario:
10
+ Given I write to "app/controllers/application_controller.rb" with:
11
+ """
12
+ class ApplicationController < ActionController::Base
13
+ protect_from_forgery
14
+ utf8_enforcer_workaround
15
+ end
16
+ """
17
+ And I start the rails application
18
+ And I use Internet Explorer
19
+ When I go to the new user page
20
+ Then there is a utf8 input tag
@@ -0,0 +1,199 @@
1
+ Given /^I generate a new rails application$/ do
2
+ steps %{
3
+ When I run `bundle exec #{new_application_command} #{APP_NAME}`
4
+ And I cd to "#{APP_NAME}"
5
+ And I turn off class caching
6
+ And I write to "Gemfile" with:
7
+ """
8
+ source "http://rubygems.org"
9
+ gem "rails", "#{framework_version}"
10
+ gem "sqlite3"
11
+ gem "capybara"
12
+ gem "gherkin"
13
+ """
14
+ And I configure the application to use "utf8_enforcer_workaround" from this project
15
+ And I reset Bundler environment variable
16
+ And I successfully run `bundle install --local`
17
+ }
18
+ end
19
+
20
+ Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
21
+ step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
22
+ end
23
+
24
+ Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
25
+ step %[I successfully run `bundle exec #{generator_command} paperclip #{model_name} #{attachment_name}`]
26
+ end
27
+
28
+ Given /^I run a paperclip_database generator to create storage for paperclip "(.*?)" to the "(.*?)" model$/ do |attachment_name, model_name|
29
+ step %[I successfully run `bundle exec #{generator_command} paperclip_database #{model_name} #{attachment_name}`]
30
+ end
31
+
32
+ Given /^I run a migration$/ do
33
+ step %[I successfully run `bundle exec rake db:migrate`]
34
+ end
35
+
36
+ Given /^I update my new user view to include the file upload field$/ do
37
+ if framework_version?("3")
38
+ steps %{
39
+ Given I overwrite "app/views/users/new.html.erb" with:
40
+ """
41
+ <%= form_for @user, :html => { :multipart => true } do |f| %>
42
+ <%= f.label :name %>
43
+ <%= f.text_field :name %>
44
+ <%= f.label :attachment %>
45
+ <%= f.file_field :attachment %>
46
+ <%= submit_tag "Submit" %>
47
+ <% end %>
48
+ """
49
+ }
50
+ else
51
+ steps %{
52
+ Given I overwrite "app/views/users/new.html.erb" with:
53
+ """
54
+ <% form_for @user, :html => { :multipart => true } do |f| %>
55
+ <%= f.label :name %>
56
+ <%= f.text_field :name %>
57
+ <%= f.label :attachment %>
58
+ <%= f.file_field :attachment %>
59
+ <%= submit_tag "Submit" %>
60
+ <% end %>
61
+ """
62
+ }
63
+ end
64
+ end
65
+
66
+ Given /^I update my user view to include the attachment$/ do
67
+ steps %{
68
+ Given I overwrite "app/views/users/show.html.erb" with:
69
+ """
70
+ <p>Name: <%= @user.name %></p>
71
+ <p>Attachment: <%= image_tag @user.attachment.url %></p>
72
+ """
73
+ }
74
+ end
75
+
76
+ Given /^I add this snippet to the User model:$/ do |snippet|
77
+ file_name = "app/models/user.rb"
78
+ in_current_dir do
79
+ content = File.read(file_name)
80
+ File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
81
+ end
82
+ end
83
+
84
+ Given /^I add this snippet to the "(.*?)" controller:$/ do |controller_name, snippet|
85
+ file_name = "app/controllers/#{controller_name}_controller.rb"
86
+ in_current_dir do
87
+ content = File.read(file_name)
88
+ File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
89
+ end
90
+ end
91
+
92
+ Given /^I start the rails application$/ do
93
+ in_current_dir do
94
+ require "./config/environment"
95
+ require "capybara/rails"
96
+ end
97
+ end
98
+
99
+ Given /^I reload my application$/ do
100
+ Rails::Application.reload!
101
+ end
102
+
103
+ When %r{I turn off class caching} do
104
+ in_current_dir do
105
+ file = "config/environments/test.rb"
106
+ config = IO.read(file)
107
+ config.gsub!(%r{^\s*config.cache_classes.*$},
108
+ "config.cache_classes = false")
109
+ File.open(file, "w"){|f| f.write(config) }
110
+ end
111
+ end
112
+
113
+ Given /^I update my application to use Bundler$/ do
114
+ if framework_version?("2")
115
+ boot_config_template = File.read('features/support/fixtures/boot_config.txt')
116
+ preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
117
+ gemfile_template = File.read('features/support/fixtures/gemfile.txt')
118
+ in_current_dir do
119
+ content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
120
+ File.open("config/boot.rb", "w") { |file| file.write(content) }
121
+ File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
122
+ File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
123
+ end
124
+ end
125
+ end
126
+
127
+ Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
128
+ if framework_version?("2.3")
129
+ require 'fileutils'
130
+ source = File.expand_path('lib/tasks/paperclip.rake')
131
+ destination = in_current_dir { File.expand_path("lib/tasks") }
132
+ FileUtils.cp source, destination
133
+ append_to "Rakefile", "require 'paperclip'"
134
+ end
135
+ end
136
+
137
+ Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
138
+ expected = IO.binread(path)
139
+ actual = if web_file.match %r{^https?://}
140
+ Net::HTTP.get(URI.parse(web_file))
141
+ else
142
+ visit(web_file)
143
+ page.source
144
+ end
145
+ actual.should == expected
146
+ end
147
+
148
+ When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
149
+ append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
150
+ steps %{And I run `bundle install --local`}
151
+ end
152
+
153
+ When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
154
+ append_to_gemfile "gem '#{gem_name}'"
155
+ end
156
+
157
+ When /^I append gems from Appraisal Gemfile$/ do
158
+ File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
159
+ if line =~ /^gem "(?!rails|appraisal)/
160
+ append_to_gemfile line.strip
161
+ end
162
+ end
163
+ end
164
+
165
+ When /^I comment out the gem "(.*?)" from the Gemfile$/ do |gemname|
166
+ comment_out_gem_in_gemfile gemname
167
+ end
168
+
169
+ Then /^the result of "(.*?)" should be the same as "(.*?)"$/ do |rails_expr, path|
170
+ expected = IO.binread(path)
171
+ actual = eval "#{rails_expr}"
172
+ actual.should == expected
173
+ end
174
+
175
+
176
+ module FileHelpers
177
+ def append_to(path, contents)
178
+ in_current_dir do
179
+ File.open(path, "a") do |file|
180
+ file.puts
181
+ file.puts contents
182
+ end
183
+ end
184
+ end
185
+
186
+ def append_to_gemfile(contents)
187
+ append_to('Gemfile', contents)
188
+ end
189
+
190
+ def comment_out_gem_in_gemfile(gemname)
191
+ in_current_dir do
192
+ gemfile = File.read("Gemfile")
193
+ gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
194
+ File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
195
+ end
196
+ end
197
+ end
198
+
199
+ World(FileHelpers)
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ Then /there is (a|no) utf8 input tag/ do |exists|
3
+ rails32_xpath = "//input[@name='utf8' and @type='hidden' and @value='✓']"
4
+ if exists == 'a'
5
+ page.should have_xpath(rails32_xpath)
6
+ elsif exists == 'no'
7
+ page.should have_no_xpath(rails32_xpath)
8
+ else
9
+ raise ArgumentError.new("exists shall be either 'a' or 'no'")
10
+ end
11
+ end
12
+
13
+ Then /I use Internet Explorer/ do
14
+ set_headers({'HTTP_USER_AGENT'=> "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"})
15
+ end
@@ -0,0 +1,209 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
20
+
21
+
22
+ require 'uri'
23
+ require 'cgi'
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
+
27
+ module WithinHelpers
28
+ def with_scope(locator)
29
+ locator ? within(*selector_for(locator)) { yield } : yield
30
+ end
31
+ end
32
+ World(WithinHelpers)
33
+
34
+ # Single-line step scoper
35
+ When /^(.*) within (.*[^:])$/ do |step, parent|
36
+ with_scope(parent) { When step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { When "#{step}:", table_or_string }
42
+ end
43
+
44
+ Given /^(?:|I )am on (.+)$/ do |page_name|
45
+ visit path_to(page_name)
46
+ end
47
+
48
+ When /^(?:|I )go to (.+)$/ do |page_name|
49
+ visit path_to(page_name)
50
+ end
51
+
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
54
+ end
55
+
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
58
+ end
59
+
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
62
+ end
63
+
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
66
+ end
67
+
68
+ # Use this to fill in an entire form with data from a table. Example:
69
+ #
70
+ # When I fill in the following:
71
+ # | Account Number | 5002 |
72
+ # | Expiry date | 2009-11-01 |
73
+ # | Note | Nice guy |
74
+ # | Wants Email? | |
75
+ #
76
+ # TODO: Add support for checkbox, select og option
77
+ # based on naming conventions.
78
+ #
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ When %{I fill in "#{name}" with "#{value}"}
82
+ end
83
+ end
84
+
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
87
+ end
88
+
89
+ When /^(?:|I )check "([^"]*)"$/ do |field|
90
+ check(field)
91
+ end
92
+
93
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
+ uncheck(field)
95
+ end
96
+
97
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
98
+ choose(field)
99
+ end
100
+
101
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
+ attach_file(field, File.expand_path(path))
103
+ end
104
+
105
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
+ if page.respond_to? :should
107
+ page.should have_content(text)
108
+ else
109
+ assert page.has_content?(text)
110
+ end
111
+ end
112
+
113
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
114
+ regexp = Regexp.new(regexp)
115
+
116
+ if page.respond_to? :should
117
+ page.should have_xpath('//*', :text => regexp)
118
+ else
119
+ assert page.has_xpath?('//*', :text => regexp)
120
+ end
121
+ end
122
+
123
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
+ if page.respond_to? :should
125
+ page.should have_no_content(text)
126
+ else
127
+ assert page.has_no_content?(text)
128
+ end
129
+ end
130
+
131
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
132
+ regexp = Regexp.new(regexp)
133
+
134
+ if page.respond_to? :should
135
+ page.should have_no_xpath('//*', :text => regexp)
136
+ else
137
+ assert page.has_no_xpath?('//*', :text => regexp)
138
+ end
139
+ end
140
+
141
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
+ with_scope(parent) do
143
+ field = find_field(field)
144
+ if field.value.respond_to? :should
145
+ field.value.should =~ /#{value}/
146
+ else
147
+ assert_match(/#{value}/, field.value)
148
+ end
149
+ end
150
+ end
151
+
152
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
153
+ with_scope(parent) do
154
+ field = find_field(field)
155
+ if field.value.respond_to? :should_not
156
+ field.value.should_not =~ /#{value}/
157
+ else
158
+ assert_no_match(/#{value}/, field.value)
159
+ end
160
+ end
161
+ end
162
+
163
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
164
+ with_scope(parent) do
165
+ field_checked = find_field(label)['checked']
166
+ if field_checked.respond_to? :should
167
+ field_checked.should be_true
168
+ else
169
+ assert field_checked
170
+ end
171
+ end
172
+ end
173
+
174
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
175
+ with_scope(parent) do
176
+ field_checked = find_field(label)['checked']
177
+ if field_checked.respond_to? :should
178
+ field_checked.should be_false
179
+ else
180
+ assert !field_checked
181
+ end
182
+ end
183
+ end
184
+
185
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
186
+ current_path = URI.parse(current_url).path
187
+ if current_path.respond_to? :should
188
+ current_path.should == path_to(page_name)
189
+ else
190
+ assert_equal path_to(page_name), current_path
191
+ end
192
+ end
193
+
194
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
195
+ query = URI.parse(current_url).query
196
+ actual_params = query ? CGI.parse(query) : {}
197
+ expected_params = {}
198
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
199
+
200
+ if actual_params.respond_to? :should
201
+ actual_params.should == expected_params
202
+ else
203
+ assert_equal expected_params, actual_params
204
+ end
205
+ end
206
+
207
+ Then /^show me the page$/ do
208
+ save_and_open_page
209
+ end
@@ -0,0 +1,20 @@
1
+ #require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ require 'aruba/cucumber'
11
+ require 'capybara/cucumber'
12
+
13
+ Before do
14
+ @aruba_timeout_seconds = 120
15
+ end
16
+
17
+ #$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
18
+ #require 'utf8_enforcer_workaround'
19
+
20
+ #require 'rspec/expectations'
@@ -0,0 +1,28 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+ when /the new user page/
14
+ '/users/new'
15
+ else
16
+ begin
17
+ page_name =~ /the (.*) page/
18
+ path_components = $1.split(/\s+/)
19
+ self.send(path_components.push('path').join('_').to_sym)
20
+ rescue Object => e
21
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
22
+ "Now, go and add a mapping in #{__FILE__}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ World(NavigationHelpers)
@@ -0,0 +1,47 @@
1
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
2
+ APP_NAME = 'testapp'.freeze
3
+ BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
4
+ ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
5
+
6
+ ENV['RAILS_ENV'] = 'test'
7
+
8
+ Before do
9
+ ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
10
+ @framework_version = nil
11
+ end
12
+
13
+ After do
14
+ ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
15
+ ENV[key] = value
16
+ end
17
+ end
18
+
19
+ When /^I reset Bundler environment variable$/ do
20
+ BUNDLE_ENV_VARS.each do |key|
21
+ ENV[key] = nil
22
+ end
23
+ end
24
+
25
+ module RailsCommandHelpers
26
+ def framework_version?(version_string)
27
+ framework_version =~ /^#{version_string}/
28
+ end
29
+
30
+ def framework_version
31
+ @framework_version ||= `rails -v`[/^Rails (.+)$/, 1]
32
+ end
33
+
34
+ def new_application_command
35
+ framework_version?("3") ? "rails new" : "rails"
36
+ end
37
+
38
+ def generator_command
39
+ framework_version?("3") ? "script/rails generate" : "script/generate"
40
+ end
41
+
42
+ def runner_command
43
+ framework_version?("3") ? "script/rails runner" : "script/runner"
44
+ end
45
+ end
46
+
47
+ World(RailsCommandHelpers)
@@ -0,0 +1,19 @@
1
+ module HtmlSelectorsHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+ when "the page"
11
+ "html > body"
12
+ else
13
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
14
+ "Now, go and add a mapping in #{__FILE__}"
15
+ end
16
+ end
17
+ end
18
+
19
+ World(HtmlSelectorsHelpers)
@@ -0,0 +1,14 @@
1
+ # https://gist.github.com/358664 (by aslakhellesoy)
2
+ module RackHeaderHack
3
+ def set_headers(headers)
4
+ driver = page.driver.browser
5
+ def driver.env
6
+ @env.merge(super)
7
+ end
8
+ def driver.env=(env)
9
+ @env = env
10
+ end
11
+ driver.env = headers
12
+ end
13
+ end
14
+ World(RackHeaderHack)
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "utf8_enforcer_workaround", :path=>"../"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,3 @@
1
+ require "utf8_enforcer_workaround/version"
2
+ require "utf8_enforcer_workaround/action_view/helpers/form_tag_helper"
3
+ require "utf8_enforcer_workaround/action_controller/base"
@@ -0,0 +1,19 @@
1
+ require "browser"
2
+
3
+ module Utf8EnforcerWorkaround
4
+ module ActionController
5
+ module Base
6
+ extend ActiveSupport::Concern
7
+ module ClassMethods
8
+ def utf8_enforcer_workaround
9
+ before_filter do
10
+ @utf8_enforcer_tag_enabled = browser.ie?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ ActionController::Base.send(:include, Utf8EnforcerWorkaround::ActionController::Base)
19
+
@@ -0,0 +1,22 @@
1
+ require 'action_view'
2
+
3
+ module Utf8EnforcerWorkaround
4
+ module ActionView
5
+ module Helpers
6
+ module FormTagHelper
7
+ def utf8_enforcer_tag_with_tag_removed
8
+ if @utf8_enforcer_tag_enabled
9
+ utf8_enforcer_tag_without_tag_removed
10
+ else
11
+ "".html_safe
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ ActionView::Helpers::FormTagHelper.class_eval do
20
+ include Utf8EnforcerWorkaround::ActionView::Helpers::FormTagHelper
21
+ included { alias_method_chain :utf8_enforcer_tag, :tag_removed }
22
+ end
@@ -0,0 +1,3 @@
1
+ module Utf8EnforcerWorkaround
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,32 @@
1
+ # -*- ruby -*-
2
+ # $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require File.expand_path('../lib/utf8_enforcer_workaround/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Jarl Friis"]
7
+ gem.email = ["jarl@softace.dk"]
8
+ gem.description = %q{Make utf8_enforcer to be applied only for non-standards-complying browsers.}
9
+ gem.summary = %q{Make utf8_enforcer to be applied only for non-standards-complying browsers.}
10
+ gem.homepage = "https://github.com/softace/utf8_enforcer_workaround"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "utf8_enforcer_workaround"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Utf8EnforcerWorkaround::VERSION
18
+ gem.platform = Gem::Platform::RUBY
19
+
20
+ gem.rubyforge_project = "utf8_enforcer_workaround"
21
+
22
+ gem.add_dependency('rails', '>= 3.2.0')
23
+ gem.add_dependency('browser', '>= 0.1.0')
24
+
25
+ gem.add_development_dependency('bundler')
26
+ gem.add_development_dependency('rake')
27
+ gem.add_development_dependency('appraisal', '~> 0.4')
28
+ gem.add_development_dependency('cucumber', '~> 1.2')
29
+ gem.add_development_dependency('sqlite3', '~> 1.3')
30
+ gem.add_development_dependency('aruba')
31
+ gem.add_development_dependency('capybara')
32
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: utf8_enforcer_workaround
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jarl Friis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: browser
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: appraisal
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.4'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.4'
94
+ - !ruby/object:Gem::Dependency
95
+ name: cucumber
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.2'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.2'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.3'
126
+ - !ruby/object:Gem::Dependency
127
+ name: aruba
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: capybara
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Make utf8_enforcer to be applied only for non-standards-complying browsers.
159
+ email:
160
+ - jarl@softace.dk
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - Appraisals
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - features/compliant_browser.feature
172
+ - features/non_compliant_browser.feature
173
+ - features/step_definitions/rails_steps.rb
174
+ - features/step_definitions/utf8_enforcer_workaround_steps.rb
175
+ - features/step_definitions/web_steps.rb
176
+ - features/support/env.rb
177
+ - features/support/paths.rb
178
+ - features/support/rails.rb
179
+ - features/support/selectors.rb
180
+ - features/support/user_agent.rb
181
+ - gemfiles/Rails32.gemfile
182
+ - lib/utf8_enforcer_workaround.rb
183
+ - lib/utf8_enforcer_workaround/action_controller/base.rb
184
+ - lib/utf8_enforcer_workaround/action_view/helpers/form_tag_helper.rb
185
+ - lib/utf8_enforcer_workaround/version.rb
186
+ - utf8_enforcer_workaround.gemspec
187
+ homepage: https://github.com/softace/utf8_enforcer_workaround
188
+ licenses: []
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ! '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ segments:
200
+ - 0
201
+ hash: 3002947666520516683
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
209
+ - 0
210
+ hash: 3002947666520516683
211
+ requirements: []
212
+ rubyforge_project: utf8_enforcer_workaround
213
+ rubygems_version: 1.8.24
214
+ signing_key:
215
+ specification_version: 3
216
+ summary: Make utf8_enforcer to be applied only for non-standards-complying browsers.
217
+ test_files:
218
+ - features/compliant_browser.feature
219
+ - features/non_compliant_browser.feature
220
+ - features/step_definitions/rails_steps.rb
221
+ - features/step_definitions/utf8_enforcer_workaround_steps.rb
222
+ - features/step_definitions/web_steps.rb
223
+ - features/support/env.rb
224
+ - features/support/paths.rb
225
+ - features/support/rails.rb
226
+ - features/support/selectors.rb
227
+ - features/support/user_agent.rb