surveyor 0.9.10 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README.md +82 -3
  2. data/VERSION +1 -1
  3. data/app/controllers/surveyor_controller.rb +43 -27
  4. data/app/helpers/surveyor_helper.rb +4 -1
  5. data/app/models/answer.rb +3 -0
  6. data/app/models/dependency.rb +4 -0
  7. data/app/models/dependency_condition.rb +4 -0
  8. data/app/models/question.rb +4 -1
  9. data/app/models/question_group.rb +4 -1
  10. data/app/models/response.rb +4 -0
  11. data/app/models/response_set.rb +3 -0
  12. data/app/models/survey.rb +4 -1
  13. data/app/models/survey_section.rb +3 -0
  14. data/app/models/validation.rb +5 -0
  15. data/app/models/validation_condition.rb +4 -0
  16. data/app/views/partials/_question_group.html.haml +1 -1
  17. data/config/routes.rb +2 -1
  18. data/features/step_definitions/web_steps.rb +273 -0
  19. data/features/support/env.rb +47 -14
  20. data/features/support/paths.rb +4 -6
  21. data/generators/extend_surveyor/templates/EXTENDING_SURVEYOR +12 -7
  22. data/generators/extend_surveyor/templates/extensions/survey_extensions.rb +8 -2
  23. data/generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb +1 -1
  24. data/generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb +1 -1
  25. data/generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb +1 -2
  26. data/generators/surveyor/templates/assets/stylesheets/surveyor.css +1 -1
  27. data/generators/surveyor/templates/initializers/surveyor.rb +4 -6
  28. data/rails/init.rb +1 -0
  29. data/spec/factories.rb +3 -1
  30. data/spec/models/survey_section_spec.rb +1 -3
  31. data/surveyor.gemspec +8 -6
  32. metadata +20 -10
  33. data/features/step_definitions/webrat_steps.rb +0 -119
data/README.md CHANGED
@@ -2,17 +2,68 @@
2
2
 
3
3
  Surveyor is a rails (gem) plugin, that brings surveys to your rails app. Before Rails 2.3, it was implemented as a Rails Engine. Surveys are written in a DSL (Domain Specific Language), with examples available in the "kitchen sink" survey.
4
4
 
5
+ ## Why you might want to use Surveyor
6
+
7
+ If you have to have a part of your Rails app that asks users questions as part of a survey, quiz, or questionnaire then you should consider using Surveyor. This plugin was designed out of the need to deliver clinical research surveys to large populations of people but it can be used for any type of survey. It has an easy to use DSL to define the questions, response dependencies (if user answers 'A' to question 1 then show question 1a, etc...), and structure (different sections of longer questionnaires).
8
+
9
+ To build your questionnaire you define it using a custom DSL. Having a DSL instead of a GUI makes it significantly easier to import long surveys (no more endless clicking and typing into tiny text boxes). It also means that you can let your customer write out the survey, edit, re-edit, tweak, throw out and start over, any number of surveys without having to change a single line of code in your app.
10
+
11
+ ## DSL example
12
+
13
+ Our DSL supports a wide range of question types (too many to list here) and varying dependency logic. Here are the first few questions of the "kitchen_sink" survey which should give you and idea of how the DSL works. The full example with all the types of questions is in the plugin and available if you run the installation instructions below.
14
+
15
+ survey "“Kitchen Sink” survey" do
16
+
17
+ section "Basic questions" do
18
+ # A label is a question that accepts no answers
19
+ label "These questions are examples of the basic supported input types"
20
+
21
+ # A basic question with radio buttons
22
+ question_1 "What is your favorite color?", :pick => :one
23
+ answer "red"
24
+ answer "blue"
25
+ answer "green"
26
+ answer "yellow"
27
+ answer :other
28
+
29
+ # A basic question with checkboxes
30
+ # "question" and "answer" may be abbreviated as "q" and "a"
31
+ q_2 "Choose the colors you don't like", :pick => :any
32
+ a_1 "red"
33
+ a_2 "blue"
34
+ a_3 "green"
35
+ a_4 "yellow"
36
+ a :omit
37
+
38
+ # A dependent question, with conditions and rule to logically join them
39
+ # the question's reference identifier is "2a", and the answer's reference_identifier is "1"
40
+ # question reference identifiers used in conditions need to be unique on a survey for the lookups to work
41
+ q_2a "Please explain why you don't like this color?"
42
+ a_1 "explanation", :text
43
+ dependency :rule => "A or B or C or D"
44
+ condition_A :q_2, "==", :a_1
45
+ condition_B :q_2, "==", :a_2
46
+ condition_C :q_2, "==", :a_3
47
+ condition_D :q_2, "==", :a_4
48
+
49
+ # ... other question, sections and such. See kitchen_sink_survey.rb for more.
50
+ end
51
+
52
+ end
53
+
54
+ The survey above shows a couple simple question types. The first one is a "pick one" type with the "other" custom entry. The second question is a "pick any" type with the option to "omit". It also has a dependency where you can ask a follow up question based on how the user answered the previous question. Notice the way the dependency is defined as a string. This implementation supports any number of complex dependency rules so not just "A or B or C or D" but "A and (B or C) and D" or "!A or ((B and !C) or D)". The conditions are the letters used they are evaluated separately using the operators defined for "==","<>", ">=","<", (the usual stuff) the plugged in to the dependency rule and evaluated. See the example survey for more details.
55
+
5
56
  # Installation
6
57
 
7
58
  As a plugin:
8
59
 
9
60
  gem install haml
10
- script/plugin install git://github.com/breakpointer/surveyor.git -r 'tag v0.9.10'
61
+ script/plugin install git://github.com/breakpointer/surveyor.git -r 'tag v0.10.0'
11
62
 
12
63
  Or as a gem plugin:
13
64
 
14
65
  # in environment.rb
15
- config.gem "surveyor", :version => '>=0.9.10', :source => 'http://gemcutter.org'
66
+ config.gem "surveyor", :version => '~> 0.10.0', :source => 'http://gemcutter.org'
16
67
 
17
68
  rake gems:install
18
69
 
@@ -29,6 +80,18 @@ The rake surveyor task overwrites previous surveys by default, but can append in
29
80
 
30
81
  rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
31
82
 
83
+ The rake tasks above generate surveys in our custom survey DSL (which is a great format for end users and stakeholders to use).
84
+ After you have run them start up your app:
85
+
86
+ script/server
87
+
88
+ (or however you normally start your app) and goto:
89
+
90
+ http://localhost:3000/surveys
91
+
92
+ Try taking the survey and compare it to the contents of the DSL file kitchen\_sink\_survey.rb. See how each type of
93
+ DSL question maps to the resulting rendered view of the question.
94
+
32
95
  # Configuration
33
96
 
34
97
  The surveyor generator creates config/initializers/surveyor.rb. There, you can specify:
@@ -103,10 +166,26 @@ The <code>surveyor\_includes</code> helper just calls <code>surveyor\_stylsheets
103
166
 
104
167
  # Dependencices
105
168
 
106
- Surveyor depends on Rails 2.3 and the SASS style sheet language, part of HAML (http://haml.hamptoncatlin.com/download)
169
+ Surveyor depends on Rails 2.3 and the SASS style sheet language, part of HAML (http://haml.hamptoncatlin.com/download). For running the test suite you will need rspec and have the rspec plugin installed in your application.
170
+
171
+ # Test Suite and Development
172
+
173
+ To work on the plugin code (for enhancements, and bug fixes, etc...) fork this github project. Then clone the project under the vendor/plugins directory in a Rails app used only for development:
174
+
107
175
 
108
176
  # Changes
109
177
 
178
+ 0.9.11
179
+
180
+ * adding rails init.rb to make gem loading work. thanks mike gurley. closes #52.
181
+ * Repeater changed to only have +1, not +3 as previous
182
+ * added locking and transaction to surveyor update action. Prevents bug that caused duplicated answers
183
+ * some light re-factoring and code readability changes
184
+ * some code formatting changes
185
+ * added require statement to specs so the factory_girl test dependency was more clear
186
+ * spiced up the readme... may have some typos
187
+ * readme update
188
+
110
189
  0.9.10
111
190
 
112
191
  * styles, adding labels for dates, correcting labels for radio buttons
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.10
1
+ 0.10.0
@@ -2,31 +2,34 @@
2
2
  # The "resource" is a survey attempt/session populating a response set.
3
3
 
4
4
  class SurveyorController < ApplicationController
5
-
5
+
6
6
  # Layout
7
7
  layout Surveyor::Config['default.layout'] || 'surveyor_default'
8
-
8
+
9
9
  # Extending surveyor
10
- include SurveyorControllerExtensions if Surveyor::Config['extend_controller']
10
+ include SurveyorControllerExtensions if Surveyor::Config['extend'].include?("surveyor_controller")
11
11
  before_filter :extend_actions
12
-
12
+
13
13
  # RESTful authentication
14
14
  if Surveyor::Config['use_restful_authentication']
15
15
  include AuthenticatedSystem
16
16
  before_filter :login_required
17
17
  end
18
-
18
+
19
19
  # Get the response set or current_user
20
20
  # before_filter :get_response_set, :except => [:new, :create]
21
21
  before_filter :get_current_user, :only => [:new, :create]
22
-
22
+
23
23
  # Actions
24
24
  def new
25
25
  @surveys = Survey.find(:all)
26
26
  redirect_to surveyor_default(:index) unless available_surveys_path == surveyor_default(:index)
27
27
  end
28
+
28
29
  def create
29
- if (@survey = Survey.find_by_access_code(params[:survey_code])) && (@response_set = ResponseSet.create(:survey => @survey, :user_id => (@current_user.nil? ? @current_user : @current_user.id)))
30
+ @survey = Survey.find_by_access_code(params[:survey_code])
31
+ @response_set = ResponseSet.create(:survey => @survey, :user_id => (@current_user.nil? ? @current_user : @current_user.id))
32
+ if (@survey && @response_set)
30
33
  flash[:notice] = "Survey was successfully started."
31
34
  redirect_to(edit_my_survey_path(:survey_code => @survey.access_code, :response_set_code => @response_set.access_code))
32
35
  else
@@ -34,13 +37,20 @@ class SurveyorController < ApplicationController
34
37
  redirect_to(available_surveys_path)
35
38
  end
36
39
  end
40
+
37
41
  def show
38
42
  end
43
+
39
44
  def edit
40
- if @response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => [:question, :answer]})
45
+ @response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => [:question, :answer]})
46
+ if @response_set
41
47
  @survey = Survey.with_sections.find_by_id(@response_set.survey_id)
42
48
  @sections = @survey.sections
43
- @section = params[:section] ? @sections.with_includes.find(section_id_from(params[:section])) || @sections.with_includes.first : @sections.with_includes.first
49
+ if params[:section]
50
+ @section = @sections.with_includes.find(section_id_from(params[:section])) || @sections.with_includes.first
51
+ else
52
+ @section = @sections.with_includes.first
53
+ end
44
54
  @questions = @section.questions
45
55
  @dependents = (@response_set.unanswered_dependencies - @section.questions) || []
46
56
  else
@@ -48,20 +58,25 @@ class SurveyorController < ApplicationController
48
58
  redirect_to(available_surveys_path)
49
59
  end
50
60
  end
61
+
51
62
  def update
52
- if @response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => :answer})
53
- @response_set.current_section_id = params[:current_section_id]
54
- else
55
- flash[:notice] = "Unable to find your responses to the survey"
56
- redirect_to(available_surveys_path) and return
57
- end
58
-
59
- if params[:responses] or params[:response_groups]
60
- @response_set.clear_responses
61
- saved = @response_set.update_attributes(:response_attributes => (params[:responses] || {}).dup , :response_group_attributes => (params[:response_groups] || {}).dup) #copy (dup) to preserve params because we manipulate params in the response_set methods
62
- if (saved && params[:finish])
63
- @response_set.complete!
64
- saved = @response_set.save!
63
+ saved = nil
64
+ ActiveRecord::Base.transaction do
65
+ if @response_set = ResponseSet.find_by_access_code(params[:response_set_code], :include => {:responses => :answer},:lock => true)
66
+ @response_set.current_section_id = params[:current_section_id]
67
+ else
68
+ flash[:notice] = "Unable to find your responses to the survey"
69
+ redirect_to(available_surveys_path) and return
70
+ end
71
+
72
+ if params[:responses] or params[:response_groups]
73
+ @response_set.clear_responses
74
+ saved = @response_set.update_attributes(:response_attributes => (params[:responses] || {}).dup ,
75
+ :response_group_attributes => (params[:response_groups] || {}).dup) #copy (dup) to preserve params because we manipulate params in the response_set methods
76
+ if (saved && params[:finish])
77
+ @response_set.complete!
78
+ saved = @response_set.save!
79
+ end
65
80
  end
66
81
  end
67
82
  respond_to do |format|
@@ -82,21 +97,22 @@ class SurveyorController < ApplicationController
82
97
  end
83
98
 
84
99
  private
85
-
100
+
86
101
  # Filters
87
102
  def get_current_user
88
103
  @current_user = self.respond_to?(:current_user) ? self.current_user : nil
89
104
  end
90
-
105
+
91
106
  # Params: the name of some submit buttons store the section we'd like to go to. for repeater questions, an anchor to the repeater group is also stored
92
107
  # e.g. params[:section] = {"1"=>{"question_group_1"=>"<= add row"}}
93
108
  def section_id_from(p)
94
109
  p.respond_to?(:keys) ? p.keys.first : p
95
110
  end
111
+
96
112
  def anchor_from(p)
97
113
  p.respond_to?(:keys) && p[p.keys.first].respond_to?(:keys) ? p[p.keys.first].keys.first : nil
98
114
  end
99
-
115
+
100
116
  # Extending surveyor
101
117
  def surveyor_default(type = :finish)
102
118
  # http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
@@ -110,10 +126,10 @@ class SurveyorController < ApplicationController
110
126
  return available_surveys_path
111
127
  end
112
128
  end
113
-
129
+
114
130
  def extend_actions
115
131
  # http://blog.mattwynne.net/2009/07/11/rails-tip-use-polymorphism-to-extend-your-controllers-at-runtime/
116
- self.extend SurveyorControllerExtensions::Actions if Surveyor::Config['extend_controller'] && defined? SurveyorControllerExtensions::Actions
132
+ self.extend SurveyorControllerExtensions::Actions if Surveyor::Config['extend'].include?("surveyor_controller") && defined? SurveyorControllerExtensions::Actions
117
133
  end
118
134
 
119
135
  end
@@ -1,5 +1,8 @@
1
1
  module SurveyorHelper
2
-
2
+
3
+ # Extending surveyor
4
+ include SurveyorHelperExtensions if Surveyor::Config['extend'].include?("surveyor_helper")
5
+
3
6
  # Configuration
4
7
  def surveyor_config
5
8
  Surveyor::Config
data/app/models/answer.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Answer < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
2
5
 
3
6
  # Associations
4
7
  belongs_to :question
@@ -1,4 +1,8 @@
1
1
  class Dependency < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
2
6
  # Associations
3
7
  belongs_to :question
4
8
  belongs_to :question_group
@@ -1,4 +1,8 @@
1
1
  class DependencyCondition < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
2
6
  # Constants
3
7
  OPERATORS = %w(== != < > <= >=) # CONSTANT or @@class_variable when validations listed before class method
4
8
 
@@ -1,5 +1,8 @@
1
1
  class Question < ActiveRecord::Base
2
-
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
3
6
  # Associations
4
7
  belongs_to :survey_section
5
8
  belongs_to :question_group
@@ -1,5 +1,8 @@
1
1
  class QuestionGroup < ActiveRecord::Base
2
-
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
3
6
  has_many :questions
4
7
  has_one :dependency
5
8
 
@@ -1,4 +1,8 @@
1
1
  class Response < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
2
6
  include ActionView::Helpers::SanitizeHelper
3
7
 
4
8
  # Associations
@@ -1,5 +1,8 @@
1
1
  class ResponseSet < ActiveRecord::Base
2
2
 
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
3
6
  # Associations
4
7
  belongs_to :survey
5
8
  belongs_to :user
data/app/models/survey.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  class Survey < ActiveRecord::Base
2
-
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
3
6
  # Associations
4
7
  has_many :sections, :class_name => "SurveySection", :order => 'display_order'
5
8
  has_many :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => 'display_order'
@@ -1,5 +1,8 @@
1
1
  class SurveySection < ActiveRecord::Base
2
2
 
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
3
6
  # Associations
4
7
  has_many :questions, :order => "display_order ASC"
5
8
  belongs_to :survey
@@ -1,4 +1,9 @@
1
1
  class Validation < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
6
+
2
7
  # Associations
3
8
  belongs_to :answer
4
9
  has_many :validation_conditions
@@ -1,4 +1,8 @@
1
1
  class ValidationCondition < ActiveRecord::Base
2
+
3
+ # Extending surveyor
4
+ include "#{self.name}Extensions".constantize if Surveyor::Config['extend'].include?(self.name.underscore)
5
+
2
6
  # Constants
3
7
  OPERATORS = %w(== != < > <= >= =~)
4
8
 
@@ -25,7 +25,7 @@
25
25
  %th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
26
26
  - when :repeater
27
27
  %ul.repeater
28
- - (response_set.count_group_responses(group_questions) + 3).times do |group_number|
28
+ - (response_set.count_group_responses(group_questions) + 1).times do |group_number|
29
29
  %li.repeater
30
30
  - group_questions.each do |question|
31
31
  = render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => group_number, :disabled => false}))
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
- root = Surveyor::Config['default.relative_url_root'] || "surveys/"
2
+ root = Surveyor::Config['default.relative_url_root'] || "surveys"
3
+ root = (root << "/").gsub(/\/+/, "/")
3
4
  map.with_options :controller => 'surveyor' do |s|
4
5
  s.available_surveys "#{root}", :conditions => {:method => :get}, :action => "new" # GET survey list
5
6
  s.take_survey "#{root}:survey_code", :conditions => {:method => :post}, :action => "create" # Only POST of survey to create
@@ -0,0 +1,273 @@
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 File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
10
+
11
+ # Commonly used webrat steps
12
+ # http://github.com/brynary/webrat
13
+
14
+ Given /^(?:|I )am on (.+)$/ do |page_name|
15
+ visit path_to(page_name)
16
+ end
17
+
18
+ When /^(?:|I )go to (.+)$/ do |page_name|
19
+ visit path_to(page_name)
20
+ end
21
+
22
+ When /^(?:|I )press "([^\"]*)"$/ do |button|
23
+ click_button(button)
24
+ end
25
+
26
+ When /^(?:|I )follow "([^\"]*)"$/ do |link|
27
+ click_link(link)
28
+ end
29
+
30
+ When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
31
+ click_link_within(parent, link)
32
+ end
33
+
34
+ When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
35
+ fill_in(field, :with => value)
36
+ end
37
+
38
+ When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
39
+ fill_in(field, :with => value)
40
+ end
41
+
42
+ # Use this to fill in an entire form with data from a table. Example:
43
+ #
44
+ # When I fill in the following:
45
+ # | Account Number | 5002 |
46
+ # | Expiry date | 2009-11-01 |
47
+ # | Note | Nice guy |
48
+ # | Wants Email? | |
49
+ #
50
+ # TODO: Add support for checkbox, select og option
51
+ # based on naming conventions.
52
+ #
53
+ When /^(?:|I )fill in the following:$/ do |fields|
54
+ fields.rows_hash.each do |name, value|
55
+ When %{I fill in "#{name}" with "#{value}"}
56
+ end
57
+ end
58
+
59
+ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
60
+ select(value, :from => field)
61
+ end
62
+
63
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
64
+ # When I select "December 25, 2008 10:00" as the date and time
65
+ When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
66
+ select_datetime(time)
67
+ end
68
+
69
+ # Use this step when using multiple datetime_select helpers on a page or
70
+ # you want to specify which datetime to select. Given the following view:
71
+ # <%= f.label :preferred %><br />
72
+ # <%= f.datetime_select :preferred %>
73
+ # <%= f.label :alternative %><br />
74
+ # <%= f.datetime_select :alternative %>
75
+ # The following steps would fill out the form:
76
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
77
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
78
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
79
+ select_datetime(datetime, :from => datetime_label)
80
+ end
81
+
82
+ # Use this step in conjunction with Rail's time_select helper. For example:
83
+ # When I select "2:20PM" as the time
84
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
85
+ # will convert the 2:20PM to 14:20 and then select it.
86
+ When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
87
+ select_time(time)
88
+ end
89
+
90
+ # Use this step when using multiple time_select helpers on a page or you want to
91
+ # specify the name of the time on the form. For example:
92
+ # When I select "7:30AM" as the "Gym" time
93
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
94
+ select_time(time, :from => time_label)
95
+ end
96
+
97
+ # Use this step in conjunction with Rail's date_select helper. For example:
98
+ # When I select "February 20, 1981" as the date
99
+ When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
100
+ select_date(date)
101
+ end
102
+
103
+ # Use this step when using multiple date_select helpers on one page or
104
+ # you want to specify the name of the date on the form. For example:
105
+ # When I select "April 26, 1982" as the "Date of Birth" date
106
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
107
+ select_date(date, :from => date_label)
108
+ end
109
+
110
+ When /^(?:|I )check "([^\"]*)"$/ do |field|
111
+ check(field)
112
+ end
113
+
114
+ When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
115
+ uncheck(field)
116
+ end
117
+
118
+ When /^(?:|I )choose "([^\"]*)"$/ do |field|
119
+ choose(field)
120
+ end
121
+
122
+ # Adds support for validates_attachment_content_type. Without the mime-type getting
123
+ # passed to attach_file() you will get a "Photo file is not one of the allowed file types."
124
+ # error message
125
+ When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
126
+ type = path.split(".")[1]
127
+
128
+ case type
129
+ when "jpg"
130
+ type = "image/jpg"
131
+ when "jpeg"
132
+ type = "image/jpeg"
133
+ when "png"
134
+ type = "image/png"
135
+ when "gif"
136
+ type = "image/gif"
137
+ end
138
+
139
+ attach_file(field, path, type)
140
+ end
141
+
142
+ Then /^(?:|I )should see "([^\"]*)"$/ do |text|
143
+ if defined?(Spec::Rails::Matchers)
144
+ response.should contain(text)
145
+ else
146
+ assert_contain text
147
+ end
148
+ end
149
+
150
+ Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
151
+ within(selector) do |content|
152
+ if defined?(Spec::Rails::Matchers)
153
+ content.should contain(text)
154
+ else
155
+ hc = Webrat::Matchers::HasContent.new(text)
156
+ assert hc.matches?(content), hc.failure_message
157
+ end
158
+ end
159
+ end
160
+
161
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
162
+ regexp = Regexp.new(regexp)
163
+ if defined?(Spec::Rails::Matchers)
164
+ response.should contain(regexp)
165
+ else
166
+ assert_match(regexp, response_body)
167
+ end
168
+ end
169
+
170
+ Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
171
+ within(selector) do |content|
172
+ regexp = Regexp.new(regexp)
173
+ if defined?(Spec::Rails::Matchers)
174
+ content.should contain(regexp)
175
+ else
176
+ assert_match(regexp, content)
177
+ end
178
+ end
179
+ end
180
+
181
+ Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
182
+ if defined?(Spec::Rails::Matchers)
183
+ response.should_not contain(text)
184
+ else
185
+ assert_not_contain(text)
186
+ end
187
+ end
188
+
189
+ Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
190
+ within(selector) do |content|
191
+ if defined?(Spec::Rails::Matchers)
192
+ content.should_not contain(text)
193
+ else
194
+ hc = Webrat::Matchers::HasContent.new(text)
195
+ assert !hc.matches?(content), hc.negative_failure_message
196
+ end
197
+ end
198
+ end
199
+
200
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
201
+ regexp = Regexp.new(regexp)
202
+ if defined?(Spec::Rails::Matchers)
203
+ response.should_not contain(regexp)
204
+ else
205
+ assert_not_contain(regexp)
206
+ end
207
+ end
208
+
209
+ Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
210
+ within(selector) do |content|
211
+ regexp = Regexp.new(regexp)
212
+ if defined?(Spec::Rails::Matchers)
213
+ content.should_not contain(regexp)
214
+ else
215
+ assert_no_match(regexp, content)
216
+ end
217
+ end
218
+ end
219
+
220
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
221
+ if defined?(Spec::Rails::Matchers)
222
+ field_labeled(field).value.should =~ /#{value}/
223
+ else
224
+ assert_match(/#{value}/, field_labeled(field).value)
225
+ end
226
+ end
227
+
228
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
229
+ if defined?(Spec::Rails::Matchers)
230
+ field_labeled(field).value.should_not =~ /#{value}/
231
+ else
232
+ assert_no_match(/#{value}/, field_labeled(field).value)
233
+ end
234
+ end
235
+
236
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
237
+ if defined?(Spec::Rails::Matchers)
238
+ field_labeled(label).should be_checked
239
+ else
240
+ assert field_labeled(label).checked?
241
+ end
242
+ end
243
+
244
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
245
+ if defined?(Spec::Rails::Matchers)
246
+ field_labeled(label).should_not be_checked
247
+ else
248
+ assert !field_labeled(label).checked?
249
+ end
250
+ end
251
+
252
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
253
+ if defined?(Spec::Rails::Matchers)
254
+ URI.parse(current_url).path.should == path_to(page_name)
255
+ else
256
+ assert_equal path_to(page_name), URI.parse(current_url).path
257
+ end
258
+ end
259
+
260
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
261
+ actual_params = CGI.parse(URI.parse(current_url).query)
262
+ expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
263
+
264
+ if defined?(Spec::Rails::Matchers)
265
+ actual_params.should == expected_params
266
+ else
267
+ assert_equal expected_params, actual_params
268
+ end
269
+ end
270
+
271
+ Then /^show me the page$/ do
272
+ save_and_open_page
273
+ end
@@ -1,24 +1,57 @@
1
- # Sets up the Rails environment for Cucumber
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
+
2
7
  ENV["RAILS_ENV"] ||= "cucumber"
3
8
  require File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
4
- require 'cucumber/rails/world'
5
-
6
- # Comment out the next line if you don't want Cucumber Unicode support
7
- require 'cucumber/formatter/unicode'
8
9
 
9
- # Comment out the next line if you don't want transactions to
10
- # open/roll back around each scenario
11
- Cucumber::Rails.use_transactional_fixtures
12
-
13
- # Comment out the next line if you want Rails' own error handling
14
- # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
15
- Cucumber::Rails.bypass_rescue
10
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
11
+ require 'cucumber/rails/world'
12
+ require 'cucumber/rails/active_record'
13
+ require 'cucumber/web/tableish'
16
14
 
17
15
  require 'webrat'
16
+ require 'webrat/core/matchers'
18
17
 
19
18
  Webrat.configure do |config|
20
19
  config.mode = :rails
20
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
21
21
  end
22
22
 
23
- require 'cucumber/rails/rspec'
24
- require 'webrat/core/matchers'
23
+
24
+ # If you set this to false, any error raised from within your app will bubble
25
+ # up to your step definition and out to cucumber unless you catch it somewhere
26
+ # on the way. You can make Rails rescue errors and render error pages on a
27
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
28
+ #
29
+ # If you set this to true, Rails will rescue all errors and render error
30
+ # pages, more or less in the same way your application would behave in the
31
+ # default production environment. It's not recommended to do this for all
32
+ # of your scenarios, as this makes it hard to discover errors in your application.
33
+ ActionController::Base.allow_rescue = false
34
+
35
+ # If you set this to true, each scenario will run in a database transaction.
36
+ # You can still turn off transactions on a per-scenario basis, simply tagging
37
+ # a feature or scenario with the @no-txn tag. If you are using Capybara,
38
+ # tagging with @culerity or @javascript will also turn transactions off.
39
+ #
40
+ # If you set this to false, transactions will be off for all scenarios,
41
+ # regardless of whether you use @no-txn or not.
42
+ #
43
+ # Beware that turning transactions off will leave data in your database
44
+ # after each scenario, which can lead to hard-to-debug failures in
45
+ # subsequent scenarios. If you do this, we recommend you create a Before
46
+ # block that will explicitly put your database in a known state.
47
+ Cucumber::Rails::World.use_transactional_fixtures = true
48
+
49
+ # How to clean your database when transactions are turned off. See
50
+ # http://github.com/bmabey/database_cleaner for more info.
51
+ if defined?(ActiveRecord::Base)
52
+ begin
53
+ require 'database_cleaner'
54
+ DatabaseCleaner.strategy = :truncation
55
+ rescue LoadError => ignore_if_database_cleaner_not_present
56
+ end
57
+ end
@@ -3,16 +3,16 @@ module NavigationHelpers
3
3
  #
4
4
  # When /^I go to (.+)$/ do |page_name|
5
5
  #
6
- # step definition in webrat_steps.rb
6
+ # step definition in web_steps.rb
7
7
  #
8
8
  def path_to(page_name)
9
9
  case page_name
10
10
 
11
- when /the homepage/
11
+ when /the home\s?page/
12
12
  '/'
13
13
 
14
14
  # Add more mappings here.
15
- # Here is a more fancy example:
15
+ # Here is an example that pulls values out of the Regexp:
16
16
  #
17
17
  # when /^(.*)'s profile page$/i
18
18
  # user_profile_path(User.find_by_login($1))
@@ -22,6 +22,4 @@ module NavigationHelpers
22
22
  "Now, go and add a mapping in #{__FILE__}"
23
23
  end
24
24
  end
25
- end
26
-
27
- World(NavigationHelpers)
25
+ end
@@ -1,12 +1,17 @@
1
1
 
2
- Any of surveyor's models class_eval, class methods, and instance methods can be modified. Include the following in config/initializers/surveyor.rb:
2
+ = Extending Surveyor =
3
3
 
4
- require 'models/survey_extensions' # Extended the survey model
5
-
6
- SurveyorHelper class_eval and instance methods can be modified. Include the following in config/initializers/surveyor.rb:
4
+ * Any of surveyor model class_eval, class methods, and instance methods may be modified.
5
+ * SurveyorHelper class_eval and instance methods may be modified.
6
+ * SurveyorController class_eval, class methods, instance methods, and actions can be modified. Action methods should be specified separately in the Actions submodule.
7
7
 
8
- require 'helpers/surveyor_helper_extensions' # Extend the surveyor helper
8
+ Samples files have been generated at:
9
9
 
10
- SurveyorController class_eval, class methods, instance methods, and actions can be modified. Action methods should be specified separately in the Actions submodule. Set the following option in config/initializers/surveyor.rb Surveyor::Config block:
10
+ * app/models/survey_extensions.rb
11
+ * app/helpers/surveyor_helper_extensions.rb
12
+ * app/controllers/surveyor_controller_extensions.rb
13
+
14
+ To activate, add the config['extend'] array in config/initializers/surveyor.rb:
11
15
 
12
- config['extend_controller'] = true
16
+ config['extend'] = %w(survey surveyor_helper surveyor_controller)
17
+
@@ -4,6 +4,7 @@ module SurveyExtensions
4
4
  base.send(:include, InstanceMethods)
5
5
  base.class_eval do
6
6
  # Same as typing in the class
7
+
7
8
  end
8
9
  end
9
10
 
@@ -11,8 +12,13 @@ module SurveyExtensions
11
12
  end
12
13
 
13
14
  module InstanceMethods
15
+ # def title
16
+ # foo
17
+ # end
18
+ # def foo
19
+ # "bar"
20
+ # end
14
21
  end
15
22
  end
16
23
 
17
- # Add module to Survey
18
- Survey.send(:include, SurveyExtensions)
24
+ # Add "survey" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
@@ -25,4 +25,4 @@ module SurveyorControllerExtensions
25
25
  end
26
26
  end
27
27
 
28
- # Set config['extend_controller'] = true in config/initializers/surveyor.rb to activate these extensions
28
+ # Add "surveyor_controller" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
@@ -4,7 +4,7 @@
4
4
  <head>
5
5
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
6
  <title>Survey: <%= controller.action_name %></title>
7
- <%= surveyor_includes # calls surveyor_javascripts + surveyor_stylesheets %>
7
+ <%= surveyor_includes %>
8
8
  </head>
9
9
  <body>
10
10
  <div id="flash"><%= flash[:notice] %></div>
@@ -14,5 +14,4 @@ module SurveyorHelperExtensions
14
14
  end
15
15
  end
16
16
 
17
- # Add module to SurveyorHelper
18
- SurveyorHelper.send(:include, SurveyorHelperExtensions)
17
+ # Add "surveyor_helper" to config['extend'] array in config/initializers/surveyor.rb to activate these extensions
@@ -201,7 +201,7 @@ body {
201
201
  list-style-type: none; }
202
202
  #surveyor .question_group li.repeater {
203
203
  display: block;
204
- clear: both; }
204
+ clear: left; }
205
205
  #surveyor .question_group li.repeater .question {
206
206
  float: left; }
207
207
  #surveyor .question_group li.repeater ol {
@@ -1,12 +1,10 @@
1
+ # Loaded once. Restart your app (even in development) to apply changes made here
1
2
  Surveyor::Config.run do |config|
2
- config['default.relative_url_root'] = nil # "surveys/" # should end with '/'
3
+ config['default.relative_url_root'] = nil # "surveys"
3
4
  config['default.title'] = nil # "You can take these surveys:"
4
5
  config['default.layout'] = nil # "surveyor_default"
5
6
  config['default.index'] = nil # "/surveys" # or :index_path_method
6
7
  config['default.finish'] = nil # "/surveys" # or :finish_path_method
7
8
  config['use_restful_authentication'] = false # set to true to use restful authentication
8
- config['extend_controller'] = false # set to true to extend SurveyorController
9
- end
10
-
11
- # require 'models/survey_extensions' # Extended the survey model
12
- # require 'helpers/surveyor_helper_extensions' # Extend the surveyor helper
9
+ config['extend'] = %w() # %w(survey surveyor_helper surveyor_controller)
10
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Init hook code here
data/spec/factories.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # http://github.com/thoughtbot/factory_girl/tree/master
2
+ require 'rubygems'
3
+ require 'factory_girl'
2
4
 
3
5
  Factory.define :survey do |s|
4
6
  s.title {"Simple survey"}
@@ -138,4 +140,4 @@ Factory.define :validation_condition do |v|
138
140
  v.string_value {}
139
141
  v.response_other {}
140
142
  v.regexp {}
141
- end
143
+ end
@@ -19,9 +19,7 @@ end
19
19
 
20
20
  describe SurveySection, "with questions" do
21
21
  before(:each) do
22
- @survey = mock_model(Survey)
23
- @valid_attributes={:title => "Rhymes", :survey => @survey, :display_order => 4}
24
- @survey_section = SurveySection.create(@valid_attributes)
22
+ @survey_section = Factory(:survey_section, :title => "Rhymes", :display_order => 4)
25
23
  @q1 = @survey_section.questions.create(:text => "Peep", :display_order => 3)
26
24
  @q2 = @survey_section.questions.create(:text => "Little", :display_order => 1)
27
25
  @q3 = @survey_section.questions.create(:text => "Bo", :display_order => 2)
data/surveyor.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{surveyor}
8
- s.version = "0.9.10"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Chamberlain", "Mark Yoon"]
12
- s.date = %q{2010-01-20}
12
+ s.date = %q{2010-04-05}
13
13
  s.email = %q{yoon@northwestern.edu}
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  "app/views/surveyor/show.html.haml",
44
44
  "config/routes.rb",
45
45
  "features/step_definitions/surveyor_steps.rb",
46
- "features/step_definitions/webrat_steps.rb",
46
+ "features/step_definitions/web_steps.rb",
47
47
  "features/support/env.rb",
48
48
  "features/support/paths.rb",
49
49
  "features/surveyor.feature",
@@ -135,6 +135,7 @@ Gem::Specification.new do |s|
135
135
  "lib/surveyor/config.rb",
136
136
  "lib/tasks/surveyor_tasks.rake",
137
137
  "lib/xml_formatter.rb",
138
+ "rails/init.rb",
138
139
  "script/surveyor/answer.rb",
139
140
  "script/surveyor/base.rb",
140
141
  "script/surveyor/dependency.rb",
@@ -176,7 +177,7 @@ Gem::Specification.new do |s|
176
177
  s.homepage = %q{http://github.com/breakpointer/surveyor}
177
178
  s.rdoc_options = ["--charset=UTF-8"]
178
179
  s.require_paths = ["lib"]
179
- s.rubygems_version = %q{1.3.5}
180
+ s.rubygems_version = %q{1.3.6}
180
181
  s.summary = %q{A rails (gem) plugin to enable surveys in your application}
181
182
  s.test_files = [
182
183
  "spec/controllers/surveyor_controller_spec.rb",
@@ -209,3 +210,4 @@ Gem::Specification.new do |s|
209
210
  s.add_dependency(%q<haml>, [">= 0"])
210
211
  end
211
212
  end
213
+
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surveyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 10
8
+ - 0
9
+ version: 0.10.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Brian Chamberlain
@@ -10,19 +15,21 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-01-20 00:00:00 -06:00
18
+ date: 2010-04-05 00:00:00 -05:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: haml
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
- version:
31
+ type: :runtime
32
+ version_requirements: *id001
26
33
  description:
27
34
  email: yoon@northwestern.edu
28
35
  executables: []
@@ -60,7 +67,7 @@ files:
60
67
  - app/views/surveyor/show.html.haml
61
68
  - config/routes.rb
62
69
  - features/step_definitions/surveyor_steps.rb
63
- - features/step_definitions/webrat_steps.rb
70
+ - features/step_definitions/web_steps.rb
64
71
  - features/support/env.rb
65
72
  - features/support/paths.rb
66
73
  - features/surveyor.feature
@@ -152,6 +159,7 @@ files:
152
159
  - lib/surveyor/config.rb
153
160
  - lib/tasks/surveyor_tasks.rake
154
161
  - lib/xml_formatter.rb
162
+ - rails/init.rb
155
163
  - script/surveyor/answer.rb
156
164
  - script/surveyor/base.rb
157
165
  - script/surveyor/dependency.rb
@@ -202,18 +210,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
210
  requirements:
203
211
  - - ">="
204
212
  - !ruby/object:Gem::Version
213
+ segments:
214
+ - 0
205
215
  version: "0"
206
- version:
207
216
  required_rubygems_version: !ruby/object:Gem::Requirement
208
217
  requirements:
209
218
  - - ">="
210
219
  - !ruby/object:Gem::Version
220
+ segments:
221
+ - 0
211
222
  version: "0"
212
- version:
213
223
  requirements: []
214
224
 
215
225
  rubyforge_project:
216
- rubygems_version: 1.3.5
226
+ rubygems_version: 1.3.6
217
227
  signing_key:
218
228
  specification_version: 3
219
229
  summary: A rails (gem) plugin to enable surveys in your application
@@ -1,119 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
-
3
- # Commonly used webrat steps
4
- # http://github.com/brynary/webrat
5
-
6
- Given /^I am on (.+)$/ do |page_name|
7
- visit path_to(page_name)
8
- end
9
-
10
- When /^I go to (.+)$/ do |page_name|
11
- visit path_to(page_name)
12
- end
13
-
14
- When /^I press "([^\"]*)"$/ do |button|
15
- click_button(button)
16
- end
17
-
18
- When /^I follow "([^\"]*)"$/ do |link|
19
- click_link(link)
20
- end
21
-
22
- When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23
- fill_in(field, :with => value)
24
- end
25
-
26
- When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
27
- select(value, :from => field)
28
- end
29
-
30
- # Use this step in conjunction with Rail's datetime_select helper. For example:
31
- # When I select "December 25, 2008 10:00" as the date and time
32
- When /^I select "([^\"]*)" as the date and time$/ do |time|
33
- select_datetime(time)
34
- end
35
-
36
- # Use this step when using multiple datetime_select helpers on a page or
37
- # you want to specify which datetime to select. Given the following view:
38
- # <%= f.label :preferred %><br />
39
- # <%= f.datetime_select :preferred %>
40
- # <%= f.label :alternative %><br />
41
- # <%= f.datetime_select :alternative %>
42
- # The following steps would fill out the form:
43
- # When I select "November 23, 2004 11:20" as the "Preferred" date and time
44
- # And I select "November 25, 2004 10:30" as the "Alternative" date and time
45
- When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
46
- select_datetime(datetime, :from => datetime_label)
47
- end
48
-
49
- # Use this step in conjunction with Rail's time_select helper. For example:
50
- # When I select "2:20PM" as the time
51
- # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
52
- # will convert the 2:20PM to 14:20 and then select it.
53
- When /^I select "([^\"]*)" as the time$/ do |time|
54
- select_time(time)
55
- end
56
-
57
- # Use this step when using multiple time_select helpers on a page or you want to
58
- # specify the name of the time on the form. For example:
59
- # When I select "7:30AM" as the "Gym" time
60
- When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
61
- select_time(time, :from => time_label)
62
- end
63
-
64
- # Use this step in conjunction with Rail's date_select helper. For example:
65
- # When I select "February 20, 1981" as the date
66
- When /^I select "([^\"]*)" as the date$/ do |date|
67
- select_date(date)
68
- end
69
-
70
- # Use this step when using multiple date_select helpers on one page or
71
- # you want to specify the name of the date on the form. For example:
72
- # When I select "April 26, 1982" as the "Date of Birth" date
73
- When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
74
- select_date(date, :from => date_label)
75
- end
76
-
77
- When /^I check "([^\"]*)"$/ do |field|
78
- check(field)
79
- end
80
-
81
- When /^I uncheck "([^\"]*)"$/ do |field|
82
- uncheck(field)
83
- end
84
-
85
- When /^I choose "([^\"]*)"$/ do |field|
86
- choose(field)
87
- end
88
-
89
- When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
90
- attach_file(field, path)
91
- end
92
-
93
- Then /^I should see "([^\"]*)"$/ do |text|
94
- response.should contain(text)
95
- end
96
-
97
- Then /^I should not see "([^\"]*)"$/ do |text|
98
- response.should_not contain(text)
99
- end
100
-
101
- Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
102
- field_labeled(field).value.should =~ /#{value}/
103
- end
104
-
105
- Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
106
- field_labeled(field).value.should_not =~ /#{value}/
107
- end
108
-
109
- Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
110
- field_labeled(label).should be_checked
111
- end
112
-
113
- Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
114
- field_labeled(label).should_not be_checked
115
- end
116
-
117
- Then /^I should be on (.+)$/ do |page_name|
118
- URI.parse(current_url).path.should == path_to(page_name)
119
- end