jakewendt-surveyor 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +285 -0
  3. data/Rakefile +54 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/surveyor_controller.rb +142 -0
  6. data/app/helpers/survey_form_builder.rb +37 -0
  7. data/app/helpers/surveyor_helper.rb +67 -0
  8. data/app/models/answer.rb +23 -0
  9. data/app/models/dependency.rb +50 -0
  10. data/app/models/dependency_condition.rb +47 -0
  11. data/app/models/question.rb +54 -0
  12. data/app/models/question_group.rb +33 -0
  13. data/app/models/response.rb +94 -0
  14. data/app/models/response_set.rb +316 -0
  15. data/app/models/survey.rb +172 -0
  16. data/app/models/survey_section.rb +18 -0
  17. data/app/models/validation.rb +38 -0
  18. data/app/models/validation_condition.rb +47 -0
  19. data/app/views/layouts/surveyor_default.html.erb +13 -0
  20. data/app/views/partials/_answer.html.haml +58 -0
  21. data/app/views/partials/_question.html.haml +80 -0
  22. data/app/views/partials/_question_group.html.haml +39 -0
  23. data/app/views/surveyor/edit.html.haml +38 -0
  24. data/app/views/surveyor/new.html.haml +16 -0
  25. data/app/views/surveyor/show.html.haml +12 -0
  26. data/config/routes.rb +11 -0
  27. data/features/step_definitions/surveyor_steps.rb +7 -0
  28. data/features/step_definitions/web_steps.rb +273 -0
  29. data/features/support/env.rb +57 -0
  30. data/features/support/paths.rb +25 -0
  31. data/features/surveyor.feature +11 -0
  32. data/generators/extend_surveyor/extend_surveyor_generator.rb +22 -0
  33. data/generators/extend_surveyor/templates/EXTENDING_SURVEYOR +17 -0
  34. data/generators/extend_surveyor/templates/extensions/survey_extensions.rb +24 -0
  35. data/generators/extend_surveyor/templates/extensions/surveyor_controller_extensions.rb +28 -0
  36. data/generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb +13 -0
  37. data/generators/extend_surveyor/templates/extensions/surveyor_helper_extensions.rb +17 -0
  38. data/generators/surveyor/surveyor_generator.rb +67 -0
  39. data/generators/surveyor/templates/README +10 -0
  40. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
  41. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
  42. data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
  43. data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
  44. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
  45. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
  46. data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
  47. data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
  48. data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
  49. data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
  50. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
  51. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
  52. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
  53. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
  54. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
  55. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
  56. data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
  57. data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
  58. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
  59. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
  60. data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
  61. data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
  62. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
  63. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
  64. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
  65. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
  66. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
  67. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
  68. data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
  69. data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
  70. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
  71. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
  72. data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
  73. data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
  74. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
  75. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
  76. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
  77. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
  78. data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
  79. data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
  80. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
  81. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
  82. data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
  83. data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
  84. data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
  85. data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
  86. data/generators/surveyor/templates/assets/javascripts/surveyor.js +47 -0
  87. data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
  88. data/generators/surveyor/templates/assets/stylesheets/reset.css +50 -0
  89. data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +243 -0
  90. data/generators/surveyor/templates/assets/stylesheets/surveyor.css +235 -0
  91. data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
  92. data/generators/surveyor/templates/initializers/haml.rb +8 -0
  93. data/generators/surveyor/templates/initializers/surveyor.rb +10 -0
  94. data/generators/surveyor/templates/migrate/add_correct_answer_id_to_questions.rb +9 -0
  95. data/generators/surveyor/templates/migrate/add_display_order_to_surveys.rb +9 -0
  96. data/generators/surveyor/templates/migrate/add_index_to_response_sets.rb +9 -0
  97. data/generators/surveyor/templates/migrate/add_index_to_surveys.rb +9 -0
  98. data/generators/surveyor/templates/migrate/add_manual_numbering.rb +11 -0
  99. data/generators/surveyor/templates/migrate/add_unique_indicies.rb +17 -0
  100. data/generators/surveyor/templates/migrate/create_answers.rb +37 -0
  101. data/generators/surveyor/templates/migrate/create_dependencies.rb +22 -0
  102. data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
  103. data/generators/surveyor/templates/migrate/create_question_groups.rb +27 -0
  104. data/generators/surveyor/templates/migrate/create_questions.rb +36 -0
  105. data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
  106. data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
  107. data/generators/surveyor/templates/migrate/create_survey_sections.rb +29 -0
  108. data/generators/surveyor/templates/migrate/create_surveys.rb +31 -0
  109. data/generators/surveyor/templates/migrate/create_validation_conditions.rb +32 -0
  110. data/generators/surveyor/templates/migrate/create_validations.rb +20 -0
  111. data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +218 -0
  112. data/generators/surveyor/templates/tasks/surveyor.rb +4 -0
  113. data/generators/test_surveyor/templates/TESTING_SURVEYOR +0 -0
  114. data/generators/test_surveyor/templates/environments/cucumber.rb +21 -0
  115. data/generators/test_surveyor/test_surveyor_generator.rb +15 -0
  116. data/jakewendt-surveyor.gemspec +212 -0
  117. data/lib/fixtures_extensions.rb +6 -0
  118. data/lib/jakewendt-surveyor.rb +1 -0
  119. data/lib/surveyor.rb +44 -0
  120. data/lib/surveyor/acts_as_response.rb +33 -0
  121. data/lib/surveyor/config.rb +45 -0
  122. data/lib/tasks/surveyor_tasks.rake +33 -0
  123. data/lib/xml_formatter.rb +12 -0
  124. data/rails/init.rb +1 -0
  125. data/script/surveyor/answer.rb +54 -0
  126. data/script/surveyor/base.rb +77 -0
  127. data/script/surveyor/dependency.rb +13 -0
  128. data/script/surveyor/dependency_condition.rb +40 -0
  129. data/script/surveyor/parser.rb +207 -0
  130. data/script/surveyor/question.rb +37 -0
  131. data/script/surveyor/question_group.rb +26 -0
  132. data/script/surveyor/specs/answer_spec.rb +29 -0
  133. data/script/surveyor/specs/question_spec.rb +63 -0
  134. data/script/surveyor/specs/spec_helper.rb +7 -0
  135. data/script/surveyor/specs/survey_section_spec.rb +23 -0
  136. data/script/surveyor/specs/validation_condition_spec.rb +20 -0
  137. data/script/surveyor/specs/validation_spec.rb +20 -0
  138. data/script/surveyor/survey.rb +35 -0
  139. data/script/surveyor/survey_section.rb +21 -0
  140. data/script/surveyor/validation.rb +21 -0
  141. data/script/surveyor/validation_condition.rb +21 -0
  142. data/script/surveyor/whr_dsl.tmproj +244 -0
  143. data/spec/controllers/surveyor_controller_spec.rb +193 -0
  144. data/spec/factories.rb +145 -0
  145. data/spec/lib/surveyor_spec.rb +44 -0
  146. data/spec/models/answer_spec.rb +29 -0
  147. data/spec/models/dependency_condition_spec.rb +321 -0
  148. data/spec/models/dependency_spec.rb +81 -0
  149. data/spec/models/question_group_spec.rb +35 -0
  150. data/spec/models/question_spec.rb +75 -0
  151. data/spec/models/response_set_spec.rb +245 -0
  152. data/spec/models/response_spec.rb +76 -0
  153. data/spec/models/survey_section_spec.rb +32 -0
  154. data/spec/models/survey_spec.rb +71 -0
  155. data/spec/models/validation_condition_spec.rb +105 -0
  156. data/spec/models/validation_spec.rb +59 -0
  157. data/spec/rcov.opts +2 -0
  158. data/spec/spec.opts +4 -0
  159. data/spec/spec_helper.rb +12 -0
  160. metadata +254 -0
@@ -0,0 +1,38 @@
1
+ #surveyor
2
+ - form_tag(update_my_survey_path, :method => :put, :id => "survey_form", :class => @survey.custom_class) do
3
+ = hidden_field_tag :current_section_id, @section.id
4
+ - unless @sections.size < 3
5
+ #menu
6
+ Sections:
7
+ %ul
8
+ - @sections.each do |s|
9
+ %li{:class => ("active" if s == @section)}= menu_button_for(s)
10
+ #header
11
+ .title= @survey.title
12
+ .previous_section= previous_section
13
+ - unless @dependents.empty?
14
+ #dependents
15
+ .title Follow-up questions from your answers on the previous page
16
+ -# @dependents.each_with_index do |question, index|
17
+ = dependency_explanation_helper(question, @response_set)
18
+ = render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set, :number => "D#{index+1}"})
19
+ - div_for @section, :class => @section.custom_class do
20
+ %span.title= @section.title
21
+ .questions
22
+ - group_questions ||= []
23
+ - @questions.each_with_index do |question, index|
24
+ - if question.is_a?(Array) && index.nil?
25
+ -#
26
+ -# jruby-1.5.0 does each_with_index WRONG
27
+ -#
28
+ = question, index = *question
29
+ - unless question.part_of_group?
30
+ = render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set})
31
+ - else # gather up the group questions
32
+ - group_questions << question
33
+ - if (index + 1 >= @questions.size) or (question.question_group_id != @questions[index + 1].question_group_id)
34
+ - # this is the last question of the section, or the group
35
+ = render(:partial => question.question_group.custom_renderer || "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
36
+ - group_questions = []
37
+ .next_section= next_section
38
+
@@ -0,0 +1,16 @@
1
+ #surveyor
2
+ #header
3
+ .title= surveyor_config['default.title'] || "You can take these surveys:"
4
+ %br
5
+ #survey_list
6
+ %ul
7
+ - unless @surveys.empty?
8
+ - @surveys.each do |survey|
9
+ %li
10
+ - form_tag(take_survey_path(:survey_code => survey.access_code)) do
11
+ = survey.title
12
+ &nbsp;
13
+ = submit_tag("Take it" )
14
+ - else
15
+ %li
16
+ No surveys
@@ -0,0 +1,12 @@
1
+ #surveyor
2
+ - @survey.sections.each do |section|
3
+ - div_for section do
4
+ .title= section.title
5
+ .questions
6
+ - @section.questions.each_with_index do |question, index|
7
+ - if question.part_of_group?
8
+ - if (index + 1 >= @section.questions.size) or (question.question_group_id != @section.questions[index + 1].question_group_id)
9
+ - # skip to the last question of the section, or the last question of the group
10
+ = render(:partial => "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set})
11
+ - else
12
+ = render(:partial => "/partials/question", :locals => {:question => question, :response_set => @response_set})
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ root = Surveyor::Config['default.relative_url_root'] || "surveys"
3
+ root = (root << "/").gsub(/\/+/, "/")
4
+ map.with_options :controller => 'surveyor' do |s|
5
+ s.available_surveys "#{root}", :conditions => {:method => :get}, :action => "new" # GET survey list
6
+ s.take_survey "#{root}:survey_code", :conditions => {:method => :post}, :action => "create" # Only POST of survey to create
7
+ s.view_my_survey "#{root}:survey_code/:response_set_code.:format", :conditions => {:method => :get}, :action => "show", :format => "html" # GET viewable/printable? survey
8
+ s.edit_my_survey "#{root}:survey_code/:response_set_code/take", :conditions => {:method => :get}, :action => "edit" # GET editable survey
9
+ s.update_my_survey "#{root}:survey_code/:response_set_code", :conditions => {:method => :put}, :action => "update" # PUT edited survey
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ Given /^I am a banana$/ do
2
+ @me = "banana"
3
+ end
4
+
5
+ Then /^I should be a banana$/ do
6
+ @me.should == "banana"
7
+ end
@@ -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
@@ -0,0 +1,57 @@
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
+ ENV["RAILS_ENV"] ||= "cucumber"
8
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
9
+
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'
14
+
15
+ require 'webrat'
16
+ require 'webrat/core/matchers'
17
+
18
+ Webrat.configure do |config|
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
+ end
22
+
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
@@ -0,0 +1,25 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+ # Add more mappings here.
15
+ # Here is an example that pulls values out of the Regexp:
16
+ #
17
+ # when /^(.*)'s profile page$/i
18
+ # user_profile_path(User.find_by_login($1))
19
+
20
+ else
21
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
22
+ "Now, go and add a mapping in #{__FILE__}"
23
+ end
24
+ end
25
+ end