acts_as_multipart_form 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +157 -0
- data/LICENSE.txt +20 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +65 -0
- data/VERSION +1 -0
- data/acts_as_multipart_form.gemspec +163 -0
- data/app/controllers/multipart_form/in_progress_forms_controller.rb +0 -0
- data/app/models/multipart_form/in_progress_form.rb +20 -0
- data/app/views/multipart_form/_breadcrumb.html.erb +21 -0
- data/app/views/multipart_form/_index_links.html.erb +20 -0
- data/app/views/multipart_form/in_progress_form/index.html.erb +0 -0
- data/app/views/multipart_form/in_progress_form/index.html.haml +0 -0
- data/lib/acts_as_multipart_form.rb +2 -0
- data/lib/acts_as_multipart_form/config.rb +36 -0
- data/lib/acts_as_multipart_form/engine.rb +4 -0
- data/lib/acts_as_multipart_form/multipart_form_in_controller.rb +301 -0
- data/lib/acts_as_multipart_form/multipart_form_in_model.rb +105 -0
- data/lib/acts_as_multipart_form/railtie.rb +14 -0
- data/lib/generators/acts_as_multipart_form/install_generator.rb +44 -0
- data/lib/generators/acts_as_multipart_form/templates/config.rb +6 -0
- data/lib/generators/acts_as_multipart_form/templates/migrations/install_migration.rb.erb +17 -0
- data/spec/acts_as_multipart_form_spec.rb +7 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/people_controller.rb +53 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/person.rb +5 -0
- data/spec/dummy/app/models/person_with_multiple_actsas.rb +5 -0
- data/spec/dummy/app/models/person_with_multiple_forms.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/people/_job_info.html.erb +8 -0
- data/spec/dummy/app/views/people/_person_info.html.erb +8 -0
- data/spec/dummy/app/views/people/hire_form.html.erb +10 -0
- data/spec/dummy/app/views/people/index.html.erb +16 -0
- data/spec/dummy/app/views/people/show.html.erb +0 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/acts_as_multipart_form.rb +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +66 -0
- data/spec/dummy/db/migrate/20110715180834_create_people.rb +13 -0
- data/spec/dummy/db/migrate/20110722130249_create_multipart_form_tables.rb +17 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/features/form_breadcrumb.feature +75 -0
- data/spec/dummy/features/form_submission.feature +23 -0
- data/spec/dummy/features/index_links.feature +56 -0
- data/spec/dummy/features/step_definitions/acts_as_multipart_form_steps.rb +30 -0
- data/spec/dummy/features/step_definitions/config_steps.rb +23 -0
- data/spec/dummy/features/step_definitions/web_steps.rb +214 -0
- data/spec/dummy/features/support/env.rb +15 -0
- data/spec/dummy/features/support/paths.rb +31 -0
- data/spec/dummy/features/support/selectors.rb +39 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +191 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/in_progress_form_spec.rb +43 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/multipart_form_in_controller_integeration_spec.rb +23 -0
- data/spec/multipart_form_in_controller_spec.rb +360 -0
- data/spec/multipart_form_in_model_integration_spec.rb +30 -0
- data/spec/multipart_form_in_model_spec.rb +156 -0
- data/spec/spec_helper.rb +38 -0
- metadata +296 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '0a102f4a26e48b284a15de73420d2d98ff59d8ddc4f8af5500f54c92f7c331cfb8d8cae6af25980ec3639c895fd19e29f495d0ec931eefa7a33fbd84980720f5'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
|
3
|
+
|
4
|
+
match "people/hire_form/:id/:multipart_form_part", :to => "people#hire_form", :as => "person_hire_form"
|
5
|
+
match "people/hire_form/:id", :to => "people#hire_form", :as => "person_hire_form"
|
6
|
+
match "people/hire_form", :to => "people#hire_form", :as => "person_hire_form"
|
7
|
+
|
8
|
+
resources :people
|
9
|
+
|
10
|
+
# The priority is based upon order of creation:
|
11
|
+
# first created -> highest priority.
|
12
|
+
|
13
|
+
# Sample of regular route:
|
14
|
+
# match 'products/:id' => 'catalog#view'
|
15
|
+
# Keep in mind you can assign values other than :controller and :action
|
16
|
+
|
17
|
+
# Sample of named route:
|
18
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
19
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
20
|
+
|
21
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
22
|
+
# resources :products
|
23
|
+
|
24
|
+
# Sample resource route with options:
|
25
|
+
# resources :products do
|
26
|
+
# member do
|
27
|
+
# get 'short'
|
28
|
+
# post 'toggle'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# collection do
|
32
|
+
# get 'sold'
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
# Sample resource route with sub-resources:
|
37
|
+
# resources :products do
|
38
|
+
# resources :comments, :sales
|
39
|
+
# resource :seller
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route with more complex sub-resources
|
43
|
+
# resources :products do
|
44
|
+
# resources :comments
|
45
|
+
# resources :sales do
|
46
|
+
# get 'recent', :on => :collection
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
50
|
+
# Sample resource route within a namespace:
|
51
|
+
# namespace :admin do
|
52
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
53
|
+
# # (app/controllers/admin/products_controller.rb)
|
54
|
+
# resources :products
|
55
|
+
# end
|
56
|
+
|
57
|
+
# You can have the root of your site routed with "root"
|
58
|
+
# just remember to delete public/index.html.
|
59
|
+
# root :to => "welcome#index"
|
60
|
+
|
61
|
+
# See how all your routes lay out with "rake routes"
|
62
|
+
|
63
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
64
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
65
|
+
# match ':controller(/:action(/:id(.:format)))'
|
66
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateMultipartFormTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :multipart_form_in_progress_forms do |t|
|
4
|
+
t.string :form_subject_type
|
5
|
+
t.integer :form_subject_id
|
6
|
+
t.string :form_name
|
7
|
+
t.string :last_completed_step
|
8
|
+
t.boolean :completed
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :multipart_form_in_progress_forms
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20110722130249) do
|
14
|
+
|
15
|
+
create_table "multipart_form_in_progress_forms", :force => true do |t|
|
16
|
+
t.string "form_subject_type"
|
17
|
+
t.integer "form_subject_id"
|
18
|
+
t.string "form_name"
|
19
|
+
t.string "last_completed_step"
|
20
|
+
t.boolean "completed"
|
21
|
+
t.datetime "created_at"
|
22
|
+
t.datetime "updated_at"
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table "people", :force => true do |t|
|
26
|
+
t.string "name"
|
27
|
+
t.datetime "created_at"
|
28
|
+
t.datetime "updated_at"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Feature: I should be able to navigate usin ght einformation in the form breadcrumb
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given show_previous_next_links is set to true
|
5
|
+
And show_incomplete_parts is set to true
|
6
|
+
|
7
|
+
Scenario: I should be able to see all of the links if the form is complete
|
8
|
+
Given there are no People in the system
|
9
|
+
And a person with a complete multipart form exists
|
10
|
+
When I go to the person hire_form first page for that person
|
11
|
+
Then I should see "Person Info"
|
12
|
+
And I should see "Job Info"
|
13
|
+
|
14
|
+
Scenario: I should not be able to see links to parts that are not complete if the show incomplete parts config option is set to false
|
15
|
+
Given there are no People in the system
|
16
|
+
And a person with an incomplete multipart form exists
|
17
|
+
And show_incomplete_parts is set to false
|
18
|
+
When I go to the person hire_form first page for that person
|
19
|
+
Then I should see "Person Info"
|
20
|
+
And I should not see "Job Info"
|
21
|
+
|
22
|
+
Scenario: I should be able to see links to parts that are not complete if the show incomplete parts config option is set to true
|
23
|
+
Given there are no People in the system
|
24
|
+
And a person with an incomplete multipart form exists
|
25
|
+
When I go to the person hire_form first page for that person
|
26
|
+
Then I should see "Person Info"
|
27
|
+
And I should see "Job Info"
|
28
|
+
|
29
|
+
Scenario: I should be able to see a next link if the show_previous_next_links is set to true
|
30
|
+
Given there are no People in the system
|
31
|
+
And a person with an incomplete multipart form exists
|
32
|
+
When I go to the person hire_form first page for that person
|
33
|
+
Then I should see "Next"
|
34
|
+
|
35
|
+
Scenario: I should not be able to see a next link if the show_previous_next_links is set to false
|
36
|
+
Given there are no People in the system
|
37
|
+
And a person with an incomplete multipart form exists
|
38
|
+
And show_previous_next_links is set to false
|
39
|
+
When I go to the person hire_form first page for that person
|
40
|
+
Then I should not see "Next"
|
41
|
+
|
42
|
+
Scenario: I should be able to see a previous link if the show_previous_next_links is set to true
|
43
|
+
Given there are no People in the system
|
44
|
+
And a person with an incomplete multipart form exists
|
45
|
+
When I go to the person hire_form first page for that person
|
46
|
+
Then I should see "Previous"
|
47
|
+
|
48
|
+
Scenario: I should not be able to see a previous link if the show_previous_next_links is set to false
|
49
|
+
Given there are no People in the system
|
50
|
+
And a person with an incomplete multipart form exists
|
51
|
+
And show_previous_next_links is set to false
|
52
|
+
When I go to the person hire_form first page for that person
|
53
|
+
Then I should not see "Previous"
|
54
|
+
|
55
|
+
Scenario: When I click on a form part link, I should be taken to that page
|
56
|
+
Given there are no People in the system
|
57
|
+
And a person with an incomplete multipart form exists
|
58
|
+
And I am on the person hire_form first page for that person
|
59
|
+
When I follow "Job Info"
|
60
|
+
Then I should be on the person hire_form page
|
61
|
+
|
62
|
+
Scenario: When I click on a previous link, I should be taken to the previous page
|
63
|
+
Given there are no People in the system
|
64
|
+
And a person with an incomplete multipart form exists
|
65
|
+
And I am on the person hire_form first page for that person
|
66
|
+
When I follow "Previous"
|
67
|
+
Then I should be on the person hire_form page
|
68
|
+
|
69
|
+
Scenario: When I click on a next link, I should be taken to the next page
|
70
|
+
Given there are no People in the system
|
71
|
+
And a person with an incomplete multipart form exists
|
72
|
+
And I am on the person hire_form first page for that person
|
73
|
+
When I follow "Next"
|
74
|
+
Then I should be on the person hire_form page
|
75
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: I should be able to submit data using the multipart form system
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given show_previous_next_links is set to true
|
5
|
+
And show_incomplete_parts is set to true
|
6
|
+
|
7
|
+
Scenario: Submitting on the first first page
|
8
|
+
Given there are no People in the system
|
9
|
+
And a person with an incomplete multipart form exists
|
10
|
+
When I go to the person hire_form page for that person
|
11
|
+
And I fill in "person_name" with "Ethan"
|
12
|
+
And I press "Submit"
|
13
|
+
Then that person's information should have updated
|
14
|
+
And I should be on the person hire_form page
|
15
|
+
|
16
|
+
Scenario: Submitting on the last page
|
17
|
+
Given there are no People in the system
|
18
|
+
And a person with an incomplete multipart form exists
|
19
|
+
When I go to the person hire_form last page for that person
|
20
|
+
And I fill in "person_name" with "Ethan"
|
21
|
+
And I press "Submit"
|
22
|
+
Then that person's information should have updated
|
23
|
+
And I should be on the person show page for that person
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Feature: I should be able to navigate using the information in the index links partial
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given show_incomplete_parts is set to false
|
5
|
+
And use_numbered_parts_on_index is set to false
|
6
|
+
|
7
|
+
Scenario: I should see complete is the form is complete
|
8
|
+
Given there are no People in the system
|
9
|
+
And a person with a complete multipart form exists
|
10
|
+
When I go to the people index page
|
11
|
+
Then I should see "Complete"
|
12
|
+
And I should not see "Incomplete"
|
13
|
+
|
14
|
+
Scenario: I shold see incomplete if the form is incomplete
|
15
|
+
Given there are no People in the system
|
16
|
+
And a person with an incomplete multipart form exists
|
17
|
+
When I go to the people index page
|
18
|
+
Then I should not see "Complete"
|
19
|
+
And I should see "Incomplete"
|
20
|
+
|
21
|
+
Scenario: If the form is complete, I should see all the form parts
|
22
|
+
Given there are no People in the system
|
23
|
+
And a person with a complete multipart form exists
|
24
|
+
When I go to the people index page
|
25
|
+
Then I should see "Person Info"
|
26
|
+
And I should see "Job Info"
|
27
|
+
|
28
|
+
Scenario: If the form is incomplete, I should not see all the form parts
|
29
|
+
Given there are no People in the system
|
30
|
+
And a person with an incomplete multipart form exists
|
31
|
+
When I go to the people index page
|
32
|
+
Then I should see "Person Info"
|
33
|
+
And I should not see "Job Info"
|
34
|
+
|
35
|
+
Scenario: I should not see any form parts after the last completed step fo the in progress form object
|
36
|
+
Given there are no People in the system
|
37
|
+
And a person with an incomplete multipart form exists
|
38
|
+
When I go to the people index page
|
39
|
+
Then I should see "Person Info"
|
40
|
+
And I should not see "Job Info"
|
41
|
+
|
42
|
+
Scenario: Clicking on a form part should take me to that form, that part, for that record
|
43
|
+
Given there are no People in the system
|
44
|
+
And a person with an incomplete multipart form exists
|
45
|
+
When I go to the people index page
|
46
|
+
And I follow "Person Info"
|
47
|
+
Then I should be on the person hire_form page
|
48
|
+
|
49
|
+
Scenario: I should see numbered links if the config options include numbered links
|
50
|
+
Given there are no People in the system
|
51
|
+
And a person with a complete multipart form exists
|
52
|
+
And use_numbered_parts_on_index is set to true
|
53
|
+
When I go to the people index page
|
54
|
+
Then I should see "1"
|
55
|
+
And I should see "2"
|
56
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Given /^there are no People in the system$/ do
|
2
|
+
Person.all.each do |p|
|
3
|
+
p.destroy
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^a person with a complete multipart form exists$/ do
|
8
|
+
p = Person.create(:name => "Jeremiah")
|
9
|
+
ipf = MultipartForm::InProgressForm.create(
|
10
|
+
:form_subject_type => "Person",
|
11
|
+
:form_subject_id => p.id,
|
12
|
+
:form_name => "hire_form",
|
13
|
+
:completed => true,
|
14
|
+
:last_completed_step => "job_info_update")
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^a person with an incomplete multipart form exists$/ do
|
18
|
+
p = Person.create(:name => "Jeremiah")
|
19
|
+
ipf = MultipartForm::InProgressForm.create(
|
20
|
+
:form_subject_type => "Person",
|
21
|
+
:form_subject_id => p.id,
|
22
|
+
:form_name => "hire_form",
|
23
|
+
:completed => false,
|
24
|
+
:last_completed_step => "person_info_update")
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^that person's information should have updated$/) do
|
28
|
+
p = Person.last
|
29
|
+
p.name.should == "Ethan"
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Given(/^use_numbered_parts_on_index is set to true$/) do
|
2
|
+
ActsAsMultipartForm.config.use_numbered_parts_on_index = true
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^use_numbered_parts_on_index is set to false$/) do
|
6
|
+
ActsAsMultipartForm.config.use_numbered_parts_on_index = false
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /^show_previous_next_links is set to true$/ do
|
10
|
+
ActsAsMultipartForm.config.show_previous_next_links = true
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^show_previous_next_links is set to false$/ do
|
14
|
+
ActsAsMultipartForm.config.show_previous_next_links = false
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^show_incomplete_parts is set to true$/ do
|
18
|
+
ActsAsMultipartForm.config.show_incomplete_parts = true
|
19
|
+
end
|
20
|
+
|
21
|
+
Given /^show_incomplete_parts is set to false$/ do
|
22
|
+
ActsAsMultipartForm.config.show_incomplete_parts = false
|
23
|
+
end
|
@@ -0,0 +1,214 @@
|
|
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
|
+
# moved to maniuplation steps
|
90
|
+
When /^(?:|I )check "([^"]*)"$/ do |field|
|
91
|
+
check(field)
|
92
|
+
end
|
93
|
+
|
94
|
+
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
95
|
+
uncheck(field)
|
96
|
+
end
|
97
|
+
|
98
|
+
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
99
|
+
choose(field)
|
100
|
+
end
|
101
|
+
|
102
|
+
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
103
|
+
attach_file(field, File.expand_path(path))
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
107
|
+
if page.respond_to? :should
|
108
|
+
page.should have_content(text)
|
109
|
+
else
|
110
|
+
assert page.has_content?(text)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
115
|
+
regexp = Regexp.new(regexp)
|
116
|
+
|
117
|
+
if page.respond_to? :should
|
118
|
+
page.should have_xpath('//*', :text => regexp)
|
119
|
+
else
|
120
|
+
assert page.has_xpath?('//*', :text => regexp)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
125
|
+
if page.respond_to? :should
|
126
|
+
page.should have_no_content(text)
|
127
|
+
else
|
128
|
+
assert page.has_no_content?(text)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
133
|
+
regexp = Regexp.new(regexp)
|
134
|
+
|
135
|
+
if page.respond_to? :should
|
136
|
+
page.should have_no_xpath('//*', :text => regexp)
|
137
|
+
else
|
138
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
143
|
+
with_scope(parent) do
|
144
|
+
field = find_field(field)
|
145
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
146
|
+
if field_value.respond_to? :should
|
147
|
+
field_value.should =~ /#{value}/
|
148
|
+
else
|
149
|
+
assert_match(/#{value}/, field_value)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
155
|
+
with_scope(parent) do
|
156
|
+
field = find_field(field)
|
157
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
158
|
+
if field_value.respond_to? :should_not
|
159
|
+
field_value.should_not =~ /#{value}/
|
160
|
+
else
|
161
|
+
assert_no_match(/#{value}/, field_value)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# moved to generic steps
|
167
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
168
|
+
with_scope(parent) do
|
169
|
+
field_checked = find_field(label)['checked']
|
170
|
+
if field_checked.respond_to? :should
|
171
|
+
field_checked.should be_true
|
172
|
+
else
|
173
|
+
assert field_checked
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# moved to generic steps
|
179
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
180
|
+
with_scope(parent) do
|
181
|
+
field_checked = find_field(label)['checked']
|
182
|
+
if field_checked.respond_to? :should
|
183
|
+
field_checked.should be_false
|
184
|
+
else
|
185
|
+
assert !field_checked
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
191
|
+
current_path = URI.parse(current_url).path
|
192
|
+
if current_path.respond_to? :should
|
193
|
+
current_path.should == path_to(page_name)
|
194
|
+
else
|
195
|
+
assert_equal path_to(page_name), current_path
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
200
|
+
query = URI.parse(current_url).query
|
201
|
+
actual_params = query ? CGI.parse(query) : {}
|
202
|
+
expected_params = {}
|
203
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
204
|
+
|
205
|
+
if actual_params.respond_to? :should
|
206
|
+
actual_params.should == expected_params
|
207
|
+
else
|
208
|
+
assert_equal expected_params, actual_params
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
Then /^show me the page$/ do
|
213
|
+
save_and_open_page
|
214
|
+
end
|