smarter_paperclip 0.2.1 → 0.3.0

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.
Files changed (81) hide show
  1. data/CHANGELOG.rdoc +2 -0
  2. data/LICENSE +26 -0
  3. data/Manifest +71 -2
  4. data/README.md +3 -1
  5. data/Rakefile +5 -6
  6. data/features/basic.feature +17 -0
  7. data/features/s3.feature +27 -0
  8. data/features/step_definitions/html_steps.rb +14 -0
  9. data/features/step_definitions/rails_steps.rb +90 -0
  10. data/features/step_definitions/s3_steps.rb +9 -0
  11. data/features/step_definitions/web_steps.rb +227 -0
  12. data/features/support/env.rb +3 -0
  13. data/features/support/paths.rb +35 -0
  14. data/features/support/rails.rb +5 -0
  15. data/features/support/s3.rb +25 -0
  16. data/gemfiles/rails2.gemfile +10 -0
  17. data/gemfiles/rails2.gemfile.lock +52 -0
  18. data/gemfiles/rails3.gemfile +10 -0
  19. data/gemfiles/rails3.gemfile.lock +93 -0
  20. data/generators/paperclip/USAGE +5 -0
  21. data/generators/paperclip/paperclip_generator.rb +27 -0
  22. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  23. data/init.rb +3 -1
  24. data/lib/generators/paperclip/USAGE +8 -0
  25. data/lib/generators/paperclip/paperclip_generator.rb +31 -0
  26. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  27. data/lib/paperclip.rb +379 -0
  28. data/lib/paperclip/attachment.rb +350 -0
  29. data/lib/paperclip/callback_compatability.rb +61 -0
  30. data/lib/paperclip/command_line.rb +80 -0
  31. data/lib/paperclip/geometry.rb +115 -0
  32. data/lib/paperclip/interpolations.rb +114 -0
  33. data/lib/paperclip/iostream.rb +45 -0
  34. data/lib/paperclip/matchers.rb +33 -0
  35. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  36. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +75 -0
  37. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  38. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  39. data/lib/paperclip/processor.rb +58 -0
  40. data/lib/paperclip/railtie.rb +24 -0
  41. data/lib/paperclip/storage.rb +2 -0
  42. data/lib/paperclip/storage/filesystem.rb +73 -0
  43. data/lib/paperclip/storage/s3.rb +192 -0
  44. data/lib/paperclip/style.rb +90 -0
  45. data/lib/paperclip/thumbnail.rb +79 -0
  46. data/lib/paperclip/upfile.rb +55 -0
  47. data/lib/paperclip/version.rb +3 -0
  48. data/lib/smarter_paperclip.rb +1 -0
  49. data/lib/tasks/paperclip.rake +79 -0
  50. data/paperclip.gemspec +35 -0
  51. data/shoulda_macros/paperclip.rb +118 -0
  52. data/smarter_paperclip.gemspec +11 -12
  53. data/test/attachment_test.rb +804 -0
  54. data/test/command_line_test.rb +133 -0
  55. data/test/database.yml +4 -0
  56. data/test/fixtures/12k.png +0 -0
  57. data/test/fixtures/50x50.png +0 -0
  58. data/test/fixtures/5k.png +0 -0
  59. data/test/fixtures/bad.png +1 -0
  60. data/test/fixtures/s3.yml +8 -0
  61. data/test/fixtures/text.txt +0 -0
  62. data/test/fixtures/twopage.pdf +0 -0
  63. data/test/geometry_test.rb +177 -0
  64. data/test/helper.rb +146 -0
  65. data/test/integration_test.rb +482 -0
  66. data/test/interpolations_test.rb +127 -0
  67. data/test/iostream_test.rb +71 -0
  68. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  69. data/test/matchers/validate_attachment_content_type_matcher_test.rb +47 -0
  70. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  71. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  72. data/test/paperclip_test.rb +254 -0
  73. data/test/processor_test.rb +10 -0
  74. data/test/storage_test.rb +363 -0
  75. data/test/style_test.rb +141 -0
  76. data/test/thumbnail_test.rb +227 -0
  77. data/test/upfile_test.rb +36 -0
  78. metadata +153 -71
  79. data.tar.gz.sig +0 -0
  80. data/Gemfile +0 -2
  81. metadata.gz.sig +0 -0
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ = Version 0.3.0
2
+ * Moved whole "old" Paperclip here to integrate it with smart extensions
1
3
  = Version 0.2.1
2
4
  * Fixed gem URLs
3
5
  = Version 0.2.0
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+
2
+ LICENSE
3
+
4
+ The MIT License
5
+
6
+ Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+
data/Manifest CHANGED
@@ -1,9 +1,78 @@
1
1
  CHANGELOG.rdoc
2
- Gemfile
2
+ LICENSE
3
3
  MIT-LICENSE
4
- Manifest
5
4
  README.md
6
5
  Rakefile
6
+ features/basic.feature
7
+ features/s3.feature
8
+ features/step_definitions/html_steps.rb
9
+ features/step_definitions/rails_steps.rb
10
+ features/step_definitions/s3_steps.rb
11
+ features/step_definitions/web_steps.rb
12
+ features/support/env.rb
13
+ features/support/paths.rb
14
+ features/support/rails.rb
15
+ features/support/s3.rb
16
+ gemfiles/rails2.gemfile
17
+ gemfiles/rails2.gemfile.lock
18
+ gemfiles/rails3.gemfile
19
+ gemfiles/rails3.gemfile.lock
20
+ generators/paperclip/USAGE
21
+ generators/paperclip/paperclip_generator.rb
22
+ generators/paperclip/templates/paperclip_migration.rb.erb
7
23
  init.rb
24
+ lib/generators/paperclip/USAGE
25
+ lib/generators/paperclip/paperclip_generator.rb
26
+ lib/generators/paperclip/templates/paperclip_migration.rb.erb
27
+ lib/paperclip.rb
28
+ lib/paperclip/attachment.rb
29
+ lib/paperclip/callback_compatability.rb
30
+ lib/paperclip/command_line.rb
31
+ lib/paperclip/geometry.rb
32
+ lib/paperclip/interpolations.rb
33
+ lib/paperclip/iostream.rb
34
+ lib/paperclip/matchers.rb
35
+ lib/paperclip/matchers/have_attached_file_matcher.rb
36
+ lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
37
+ lib/paperclip/matchers/validate_attachment_presence_matcher.rb
38
+ lib/paperclip/matchers/validate_attachment_size_matcher.rb
39
+ lib/paperclip/processor.rb
40
+ lib/paperclip/railtie.rb
41
+ lib/paperclip/storage.rb
42
+ lib/paperclip/storage/filesystem.rb
43
+ lib/paperclip/storage/s3.rb
44
+ lib/paperclip/style.rb
45
+ lib/paperclip/thumbnail.rb
46
+ lib/paperclip/upfile.rb
47
+ lib/paperclip/version.rb
8
48
  lib/smarter_paperclip.rb
49
+ lib/tasks/paperclip.rake
50
+ paperclip.gemspec
51
+ shoulda_macros/paperclip.rb
9
52
  smarter_paperclip.gemspec
53
+ test/attachment_test.rb
54
+ test/command_line_test.rb
55
+ test/database.yml
56
+ test/fixtures/12k.png
57
+ test/fixtures/50x50.png
58
+ test/fixtures/5k.png
59
+ test/fixtures/bad.png
60
+ test/fixtures/s3.yml
61
+ test/fixtures/text.txt
62
+ test/fixtures/twopage.pdf
63
+ test/geometry_test.rb
64
+ test/helper.rb
65
+ test/integration_test.rb
66
+ test/interpolations_test.rb
67
+ test/iostream_test.rb
68
+ test/matchers/have_attached_file_matcher_test.rb
69
+ test/matchers/validate_attachment_content_type_matcher_test.rb
70
+ test/matchers/validate_attachment_presence_matcher_test.rb
71
+ test/matchers/validate_attachment_size_matcher_test.rb
72
+ test/paperclip_test.rb
73
+ test/processor_test.rb
74
+ test/storage_test.rb
75
+ test/style_test.rb
76
+ test/thumbnail_test.rb
77
+ test/upfile_test.rb
78
+ Manifest
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Smarter Paperclip
2
2
 
3
+ Paperclip with some additional cool stuff. This Paperclip version uses old Paperclip but it is tweaked up to work with Rails 3.2.
4
+
3
5
  Collection of Paperclip extensions:
4
6
 
5
7
  - `validates_attachment_minimum_resolution`
6
8
  - `validates_attachment_if_included`
7
9
  - `has_interpolated_attached_file`
8
10
 
9
- Works with Ruby 1.8.7, 1.8.7 EE, 1.9.2
11
+ Works with Ruby 1.8.7, 1.8.7 EE, 1.9.2, 1.9.3
10
12
  Works with Rails3
11
13
 
12
14
  ## Install
data/Rakefile CHANGED
@@ -2,12 +2,11 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('smarter_paperclip', '0.2.1') do |p|
6
- p.description = "Collection of Paperclip extensions"
7
- p.url = "https://github.com/mensfeld/Smarter-Paperclip"
8
- p.author = "Maciej Mensfeld"
9
- p.email = "maciej@mensfeld.pl"
5
+ Echoe.new('smarter_paperclip', '0.3.0') do |p|
6
+ p.description = "Papercli with bunch of extensions"
7
+ p.url = "https://github.com/mensfeld/Smarter-Paperclip"
8
+ p.author = "Maciej Mensfeld"
9
+ p.email = "maciej@mensfeld.pl"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
11
  p.development_dependencies = ["rspec >=2.0.0", "paperclip"]
12
12
  end
13
-
@@ -0,0 +1,17 @@
1
+ Feature: Running paperclip in a Rails app
2
+
3
+ Scenario: Basic utilization
4
+ Given I have a rails application
5
+ And I save the following as "app/models/user.rb"
6
+ """
7
+ class User < ActiveRecord::Base
8
+ has_attached_file :avatar
9
+ end
10
+ """
11
+ When I visit /users/new
12
+ And I fill in "user_name" with "something"
13
+ And I attach the file "test/fixtures/5k.png" to "user_avatar"
14
+ And I press "Submit"
15
+ Then I should see "Name: something"
16
+ And I should see an image with a path of "/system/avatars/1/original/5k.png"
17
+ And the file at "/system/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
@@ -0,0 +1,27 @@
1
+ Feature: Running paperclip in a Rails app using basic S3 support
2
+
3
+ Scenario: Basic utilization
4
+ Given I have a rails application
5
+ And I save the following as "app/models/user.rb"
6
+ """
7
+ class User < ActiveRecord::Base
8
+ has_attached_file :avatar,
9
+ :storage => :s3,
10
+ :path => "/:attachment/:id/:style/:filename",
11
+ :s3_credentials => Rails.root.join("config/s3.yml")
12
+ end
13
+ """
14
+ And I validate my S3 credentials
15
+ And I save the following as "config/s3.yml"
16
+ """
17
+ bucket: <%= ENV['PAPERCLIP_TEST_BUCKET'] || 'paperclip' %>
18
+ access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
19
+ secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
20
+ """
21
+ When I visit /users/new
22
+ And I fill in "user_name" with "something"
23
+ And I attach the file "test/fixtures/5k.png" to "user_avatar"
24
+ And I press "Submit"
25
+ Then I should see "Name: something"
26
+ And I should see an image with a path of "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png"
27
+ And the file at "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
@@ -0,0 +1,14 @@
1
+ Then %r{I should see an image with a path of "([^"]*)"} do |path|
2
+ page.should have_css("img[src^='#{path}']")
3
+ end
4
+
5
+ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
6
+ expected = IO.read(path)
7
+ actual = if web_file.match %r{^https?://}
8
+ Net::HTTP.get(URI.parse(web_file))
9
+ else
10
+ visit(web_file)
11
+ page.body
12
+ end
13
+ actual.should == expected
14
+ end
@@ -0,0 +1,90 @@
1
+ Given "I have a rails application" do
2
+ steps %{
3
+ Given I generate a rails application
4
+ And this plugin is available
5
+ And I have a "users" resource with "name:string"
6
+ And I turn off class caching
7
+ Given I save the following as "app/models/user.rb"
8
+ """
9
+ class User < ActiveRecord::Base
10
+ end
11
+ """
12
+ And I save the following as "config/s3.yml"
13
+ """
14
+ access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
15
+ secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
16
+ bucket: paperclip
17
+ """
18
+ And I save the following as "app/views/users/new.html.erb"
19
+ """
20
+ <% form_for @user, :html => { :multipart => true } do |f| %>
21
+ <%= f.text_field :name %>
22
+ <%= f.file_field :avatar %>
23
+ <%= submit_tag "Submit" %>
24
+ <% end %>
25
+ """
26
+ And I save the following as "app/views/users/show.html.erb"
27
+ """
28
+ <p>Name: <%= @user.name %></p>
29
+ <p>Avatar: <%= image_tag @user.avatar.url %></p>
30
+ """
31
+ And I run "script/generate paperclip user avatar"
32
+ And the rails application is prepped and running
33
+ }
34
+ end
35
+
36
+ Given %r{I generate a rails application} do
37
+ FileUtils.rm_rf TEMP_ROOT
38
+ FileUtils.mkdir_p TEMP_ROOT
39
+ Dir.chdir(TEMP_ROOT) do
40
+ `rails _2.3.8_ #{APP_NAME}`
41
+ end
42
+ end
43
+
44
+ When %r{I save the following as "([^"]*)"} do |path, string|
45
+ FileUtils.mkdir_p(File.join(CUC_RAILS_ROOT, File.dirname(path)))
46
+ File.open(File.join(CUC_RAILS_ROOT, path), 'w') { |file| file.write(string) }
47
+ end
48
+
49
+ When %r{I turn off class caching} do
50
+ Dir.chdir(CUC_RAILS_ROOT) do
51
+ file = "config/environments/test.rb"
52
+ config = IO.read(file)
53
+ config.gsub!(%r{^\s*config.cache_classes.*$},
54
+ "config.cache_classes = false")
55
+ File.open(file, "w"){|f| f.write(config) }
56
+ end
57
+ end
58
+
59
+ When %r{the rails application is prepped and running$} do
60
+ When "I reset the database"
61
+ When "the rails application is running"
62
+ end
63
+
64
+ When %r{I reset the database} do
65
+ When %{I run "rake db:drop db:create db:migrate"}
66
+ end
67
+
68
+ When %r{the rails application is running} do
69
+ Dir.chdir(CUC_RAILS_ROOT) do
70
+ require "config/environment"
71
+ require "capybara/rails"
72
+ end
73
+ end
74
+
75
+ When %r{this plugin is available} do
76
+ $LOAD_PATH << "#{PROJECT_ROOT}/lib"
77
+ require 'paperclip'
78
+ When %{I save the following as "vendor/plugins/paperclip/rails/init.rb"},
79
+ IO.read("#{PROJECT_ROOT}/rails/init.rb")
80
+ end
81
+
82
+ When %r{I run "([^"]*)"} do |command|
83
+ Dir.chdir(CUC_RAILS_ROOT) do
84
+ `#{command}`
85
+ end
86
+ end
87
+
88
+ When %r{I have a "([^"]*)" resource with "([^"]*)"} do |resource, fields|
89
+ When %{I run "script/generate scaffold #{resource} #{fields}"}
90
+ end
@@ -0,0 +1,9 @@
1
+ Given /I validate my S3 credentials/ do
2
+ key = ENV['AWS_ACCESS_KEY_ID']
3
+ secret = ENV['AWS_SECRET_ACCESS_KEY']
4
+
5
+ key.should_not be_nil
6
+ secret.should_not be_nil
7
+
8
+ assert_credentials(key, secret)
9
+ end
@@ -0,0 +1,227 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ require 'uri'
9
+ require 'cgi'
10
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
11
+
12
+ module WithinHelpers
13
+ def with_scope(locator)
14
+ locator ? within(locator) { yield } : yield
15
+ end
16
+ end
17
+ World(WithinHelpers)
18
+
19
+ Given /^(?:|I )am on (.+)$/ do |page_name|
20
+ visit path_to(page_name)
21
+ end
22
+
23
+ When /^(?:|I )go to (.+)$/ do |page_name|
24
+ visit path_to(page_name)
25
+ end
26
+
27
+ When /^(?:|I )visit (\/.+)$/ do |page_path|
28
+ visit page_path
29
+ end
30
+
31
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
32
+ with_scope(selector) do
33
+ click_button(button)
34
+ end
35
+ end
36
+
37
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
38
+ with_scope(selector) do
39
+ click_link(link)
40
+ end
41
+ end
42
+
43
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
44
+ with_scope(selector) do
45
+ fill_in(field, :with => value)
46
+ end
47
+ end
48
+
49
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
50
+ with_scope(selector) do
51
+ fill_in(field, :with => value)
52
+ end
53
+ end
54
+
55
+ # Use this to fill in an entire form with data from a table. Example:
56
+ #
57
+ # When I fill in the following:
58
+ # | Account Number | 5002 |
59
+ # | Expiry date | 2009-11-01 |
60
+ # | Note | Nice guy |
61
+ # | Wants Email? | |
62
+ #
63
+ # TODO: Add support for checkbox, select og option
64
+ # based on naming conventions.
65
+ #
66
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
67
+ with_scope(selector) do
68
+ fields.rows_hash.each do |name, value|
69
+ When %{I fill in "#{name}" with "#{value}"}
70
+ end
71
+ end
72
+ end
73
+
74
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
75
+ with_scope(selector) do
76
+ select(value, :from => field)
77
+ end
78
+ end
79
+
80
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
81
+ with_scope(selector) do
82
+ check(field)
83
+ end
84
+ end
85
+
86
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
87
+ with_scope(selector) do
88
+ uncheck(field)
89
+ end
90
+ end
91
+
92
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
93
+ with_scope(selector) do
94
+ choose(field)
95
+ end
96
+ end
97
+
98
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
99
+ with_scope(selector) do
100
+ attach_file(field, path)
101
+ end
102
+ end
103
+
104
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
105
+ require 'json'
106
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
107
+ actual = JSON.pretty_generate(JSON.parse(response.body))
108
+ expected.should == actual
109
+ end
110
+
111
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
112
+ with_scope(selector) do
113
+ if page.respond_to? :should
114
+ page.should have_content(text)
115
+ else
116
+ assert page.has_content?(text)
117
+ end
118
+ end
119
+ end
120
+
121
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
122
+ regexp = Regexp.new(regexp)
123
+ with_scope(selector) do
124
+ if page.respond_to? :should
125
+ page.should have_xpath('//*', :text => regexp)
126
+ else
127
+ assert page.has_xpath?('//*', :text => regexp)
128
+ end
129
+ end
130
+ end
131
+
132
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
133
+ with_scope(selector) do
134
+ if page.respond_to? :should
135
+ page.should have_no_content(text)
136
+ else
137
+ assert page.has_no_content?(text)
138
+ end
139
+ end
140
+ end
141
+
142
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
143
+ regexp = Regexp.new(regexp)
144
+ with_scope(selector) do
145
+ if page.respond_to? :should
146
+ page.should have_no_xpath('//*', :text => regexp)
147
+ else
148
+ assert page.has_no_xpath?('//*', :text => regexp)
149
+ end
150
+ end
151
+ end
152
+
153
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
154
+ with_scope(selector) do
155
+ field = find_field(field)
156
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
157
+ if field_value.respond_to? :should
158
+ field_value.should =~ /#{value}/
159
+ else
160
+ assert_match(/#{value}/, field_value)
161
+ end
162
+ end
163
+ end
164
+
165
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
166
+ with_scope(selector) do
167
+ field = find_field(field)
168
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
169
+ if field_value.respond_to? :should_not
170
+ field_value.should_not =~ /#{value}/
171
+ else
172
+ assert_no_match(/#{value}/, field_value)
173
+ end
174
+ end
175
+ end
176
+
177
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
178
+ with_scope(selector) do
179
+ field_checked = find_field(label)['checked']
180
+ if field_checked.respond_to? :should
181
+ field_checked.should be_true
182
+ else
183
+ assert field_checked
184
+ end
185
+ end
186
+ end
187
+
188
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
189
+ with_scope(selector) do
190
+ field_checked = find_field(label)['checked']
191
+ if field_checked.respond_to? :should
192
+ field_checked.should be_false
193
+ else
194
+ assert !field_checked
195
+ end
196
+ end
197
+ end
198
+
199
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
200
+ current_path = URI.parse(current_url).path
201
+ if current_path.respond_to? :should
202
+ current_path.should == path_to(page_name)
203
+ else
204
+ assert_equal path_to(page_name), current_path
205
+ end
206
+ end
207
+
208
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
209
+ query = URI.parse(current_url).query
210
+ actual_params = query ? CGI.parse(query) : {}
211
+ expected_params = {}
212
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
213
+
214
+ if actual_params.respond_to? :should
215
+ actual_params.should == expected_params
216
+ else
217
+ assert_equal expected_params, actual_params
218
+ end
219
+ end
220
+
221
+ Then /^I save and open the page$/ do
222
+ save_and_open_page
223
+ end
224
+
225
+ Then /^show me the page$/ do
226
+ save_and_open_page
227
+ end