shakespeare 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ Feb 15 2010
2
+ - - - - - -
3
+ - Added find_by_url to pages
4
+ - Added url methods to generate / validate URLs
data/Rakefile CHANGED
@@ -1,43 +1,43 @@
1
- require 'rake'
2
- require 'spec/rake/spectask'
3
-
4
- desc 'Default: run specs.'
5
- task :default => :spec
6
-
7
- desc 'Run the specs'
8
- Spec::Rake::SpecTask.new(:spec) do |t|
9
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
- t.spec_files = FileList['spec/**/*_spec.rb']
11
- end
12
-
13
- PKG_FILES = FileList[
14
- '[a-zA-Z]*',
15
- 'app/**/*',
16
- 'generators/**/*',
17
- 'config/*',
18
- 'lib/**/*',
19
- 'rails/**/*',
20
- 'spec/**/*',
21
- 'features/**/*'
22
- ]
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |s|
27
- s.name = "shakespeare"
28
- s.version = "0.1.1"
29
- s.author = "Paul Campbell"
30
- s.email = "paul@rslw.com"
31
- s.homepage = "http://www.github.com/paulca/shakespeare"
32
- s.platform = Gem::Platform::RUBY
33
- s.summary = "A Rails drop in CMS."
34
- s.files = PKG_FILES.to_a
35
- s.require_path = "lib"
36
- s.has_rdoc = false
37
- s.extra_rdoc_files = ["README.md"]
38
- end
39
- rescue LoadError
40
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
41
- end
42
-
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc 'Run the specs'
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
+ t.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ PKG_FILES = FileList[
14
+ '[a-zA-Z]*',
15
+ 'app/**/*',
16
+ 'generators/**/*',
17
+ 'config/*',
18
+ 'lib/**/*',
19
+ 'rails/**/*',
20
+ 'spec/**/*',
21
+ 'features/**/*'
22
+ ]
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |s|
27
+ s.name = "shakespeare"
28
+ s.version = "0.2.0"
29
+ s.author = "Paul Campbell"
30
+ s.email = "paul@rslw.com"
31
+ s.homepage = "http://www.github.com/paulca/shakespeare"
32
+ s.platform = Gem::Platform::RUBY
33
+ s.summary = "A Rails drop in CMS."
34
+ s.files = PKG_FILES.to_a
35
+ s.require_path = "lib"
36
+ s.has_rdoc = false
37
+ s.extra_rdoc_files = ["README.md"]
38
+ end
39
+ rescue LoadError
40
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
41
+ end
42
+
43
43
  Jeweler::GemcutterTasks.new
@@ -1,47 +1,47 @@
1
- class Admin::PagesController < ApplicationController
2
-
3
-
4
- Shakespeare::Settings.before_filters.each do |filter|
5
- before_filter filter
6
- end
7
- before_filter :protect_in_production if Shakespeare::Settings.before_filters.empty?
8
-
9
- layout Shakespeare::Settings.layout
10
-
11
- def index
12
- @pages = Page.all
13
- end
14
-
15
- def new
16
- @page = Page.new
17
- end
18
-
19
- def create
20
- @page = Page.new(params[:page])
21
- if @page.save
22
- redirect_to admin_pages_path
23
- else
24
- render :new
25
- end
26
- end
27
-
28
- def edit
29
- @page = Page.find(params[:id])
30
- end
31
-
32
- def update
33
- @page = Page.find(params[:id])
34
- if @page.update_attributes(params[:page])
35
- redirect_to admin_pages_path
36
- else
37
- render :edit
38
- end
39
- end
40
-
41
- def destroy
42
- @page = Page.find(params[:id])
43
- @page.destroy
44
- redirect_to admin_pages_path
45
- end
46
-
1
+ class Admin::PagesController < ApplicationController
2
+
3
+
4
+ Shakespeare::Settings.before_filters.each do |filter|
5
+ before_filter filter
6
+ end
7
+ before_filter :protect_in_production if Shakespeare::Settings.before_filters.empty?
8
+
9
+ layout Shakespeare::Settings.layout
10
+
11
+ def index
12
+ @pages = Page.all
13
+ end
14
+
15
+ def new
16
+ @page = Page.new
17
+ end
18
+
19
+ def create
20
+ @page = Page.new(params[:page])
21
+ if @page.save
22
+ redirect_to admin_pages_path
23
+ else
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def edit
29
+ @page = Page.find_by_url(params[:id])
30
+ end
31
+
32
+ def update
33
+ @page = Page.find_by_url(params[:id])
34
+ if @page.update_attributes(params[:page])
35
+ redirect_to admin_pages_path
36
+ else
37
+ render :edit
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ @page = Page.find_by_url(params[:id])
43
+ @page.destroy
44
+ redirect_to admin_pages_path
45
+ end
46
+
47
47
  end
@@ -1,5 +1,5 @@
1
- class PagesController < ApplicationController
2
- def show
3
- @page = Page.find(params[:id])
4
- end
1
+ class PagesController < ApplicationController
2
+ def show
3
+ @page = Page.find_by_url(params[:id])
4
+ end
5
5
  end
data/app/models/page.rb CHANGED
@@ -1,10 +1,27 @@
1
- class Page < ActiveRecord::Base
2
-
3
- def robots
4
- out = []
5
- out << 'noindex' if noindex?
6
- out << 'nofollow' if nofollow?
7
- out.join(', ')
8
- end
9
-
1
+ class Page < ActiveRecord::Base
2
+
3
+ validates_presence_of :title
4
+ validates_format_of :url, :with => /\s*/, :if => Proc.new { |p| !p.url.blank? }
5
+
6
+ before_validation :set_url
7
+
8
+ def robots
9
+ out = []
10
+ out << 'noindex' if noindex?
11
+ out << 'nofollow' if nofollow?
12
+ out.join(', ')
13
+ end
14
+
15
+ def to_param
16
+ url
17
+ end
18
+
19
+ def clean_url
20
+ title.to_s.downcase.gsub(/[^a-z0-9\s]/, '').gsub(/\s/,'-')
21
+ end
22
+
23
+ def set_url
24
+ self.url ||= clean_url
25
+ end
26
+
10
27
  end
@@ -1,38 +1,38 @@
1
- <% form_for [:admin, @page] do |f| -%>
2
-
3
- <%= f.error_messages %>
4
-
5
- <fieldset>
6
- <%= f.label :url, "URL" %> <%= f.text_field :url %> <em>This can be an existing controller_name/action_name combo, or a completely new URL.</em> <br />
7
- </fieldset>
8
-
9
- <fieldset>
10
- <%= f.label :title, "Title" %>
11
- <%= f.text_field :title %> <br />
12
- <fieldset>
13
- <legend>Robots</legend>
14
-
15
- <%= f.check_box :noindex %>
16
- <%= f.label :noindex, "No-Index", :class => 'inline' %>
17
-
18
- <%= f.check_box :nofollow %>
19
- <%= f.label :nofollow, "No-follow", :class => 'inline' %>
20
-
21
- <%= f.check_box :enable_canonical %>
22
- <%= f.label :enable_canonical, "Set Canonical Tag?", :class => 'inline' %>
23
-
24
- <%= f.label :canonical, "Canonical URL" %>
25
- <%= f.text_field :canonical %> <br />
26
-
27
-
28
- <%= f.label :description, "Description" %> <%= f.text_area :description, :class => "small-text" %> <br />
29
- <%= f.label :keywords, "Keywords" %> <%= f.text_field :keywords %> <br />
30
- </fieldset>
31
-
32
- <fieldset>
33
- <%= f.label :content, "Content" %> <%= f.text_area :content %> <br />
34
- </fieldset>
35
-
36
-
37
- <%= f.submit "Save" %> or <%= link_to "Cancel", admin_pages_path %>
1
+ <% form_for [:admin, @page] do |f| -%>
2
+
3
+ <%= f.error_messages %>
4
+
5
+ <fieldset>
6
+ <%= f.label :url, "URL" %> <%= f.text_field :url %> <em>This can be an existing controller_name/action_name combo, or a completely new URL.</em> <br />
7
+ </fieldset>
8
+
9
+ <fieldset>
10
+ <%= f.label :title, "Title" %>
11
+ <%= f.text_field :title %> <br />
12
+ <fieldset>
13
+ <legend>Robots</legend>
14
+
15
+ <%= f.check_box :noindex %>
16
+ <%= f.label :noindex, "No-Index", :class => 'inline' %>
17
+
18
+ <%= f.check_box :nofollow %>
19
+ <%= f.label :nofollow, "No-follow", :class => 'inline' %>
20
+
21
+ <%= f.check_box :enable_canonical %>
22
+ <%= f.label :enable_canonical, "Set Canonical Tag?", :class => 'inline' %>
23
+
24
+ <%= f.label :canonical, "Canonical URL" %>
25
+ <%= f.text_field :canonical %> <br />
26
+
27
+
28
+ <%= f.label :description, "Description" %> <%= f.text_area :description, :class => "small-text" %> <br />
29
+ <%= f.label :keywords, "Keywords" %> <%= f.text_field :keywords %> <br />
30
+ </fieldset>
31
+
32
+ <fieldset>
33
+ <%= f.label :content, "Content" %> <%= f.text_area :content %> <br />
34
+ </fieldset>
35
+
36
+
37
+ <%= f.submit "Save" %> or <%= link_to "Cancel", admin_pages_path %>
38
38
  <% end -%>
data/config/routes.rb CHANGED
@@ -1,8 +1,8 @@
1
- ActionController::Routing::Routes.draw do |map|
2
-
3
- map.resources :pages
4
-
5
- map.namespace :admin do |admin|
6
- admin.resources :pages
7
- end
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :pages, :requirements => {:id => /.*/}
4
+
5
+ map.namespace :admin do |admin|
6
+ admin.resources :pages, :requirements => {:id => /.*/}
7
+ end
8
8
  end
@@ -1,38 +1,39 @@
1
- Feature: Managing Pages
2
- In order to update the site
3
- As an admin
4
- I want to add, edit and delete pages
5
-
6
- Scenario: I'm on the admin layout
7
- When I am on the pages admin page
8
- Then I should see "Admin"
9
-
10
- Scenario: New Page
11
- Given I am on the pages admin page
12
- When I follow "Add a New Page"
13
- And I fill in "Title" with "Harry and the Hendersons"
14
- And I fill in "Keywords" with "80s, movie"
15
- And I check "No-index"
16
- And I check "No-follow"
17
- And I check "Set Canonical Tag?"
18
- And I fill in "Canonical URL" with "http://hendersons.com"
19
- And I press "Save"
20
- Then I should see "Harry and the Hendersons"
21
-
22
- Scenario: Edit Page
23
- Given a page titled "Harry and the Hendersons"
24
- And I am on the pages admin page
25
- When I follow "Edit"
26
- And I fill in "Title" with "Three Men and a Baby"
27
- And I press "Save"
28
- Then I should see "Three Men and a Baby"
29
- And I should not see "Harry and the Hendersons"
30
-
31
- Scenario: Delete Page
32
- Given a page titled "The Departed"
33
- When I am on the pages admin page
34
- Then I should see "The Departed"
35
-
36
- When I follow "Delete"
37
- Then I should not see "The Departed"
1
+ Feature: Managing Pages
2
+ In order to update the site
3
+ As an admin
4
+ I want to add, edit and delete pages
5
+
6
+ Scenario: I'm on the admin layout
7
+ When I am on the pages admin page
8
+ Then I should see "Admin"
9
+
10
+ Scenario: New Page
11
+ Given I am on the pages admin page
12
+ When I follow "Add a New Page"
13
+ And I fill in "Title" with "Harry and the Hendersons"
14
+ And I fill in "Keywords" with "80s, movie"
15
+ And I check "No-Index"
16
+ And I check "No-follow"
17
+ And I check "Set Canonical Tag?"
18
+ And I fill in "Canonical URL" with "http://hendersons.com"
19
+ And I press "Save"
20
+ Then I should see "Harry and the Hendersons"
21
+
22
+ Scenario: Edit Page
23
+ Given a page titled "Harry and the Hendersons"
24
+ And I am on the pages admin page
25
+ When I follow "Edit"
26
+ And I fill in "Title" with "Three Men and a Baby"
27
+ And I press "Save"
28
+ Then I should see "Three Men and a Baby"
29
+ And I should not see "Harry and the Hendersons"
30
+
31
+ @emulate_rails_javascript
32
+ Scenario: Delete Page
33
+ Given a page titled "The Departed"
34
+ When I am on the pages admin page
35
+ Then I should see "The Departed"
36
+
37
+ When I follow "Delete"
38
+ Then I should not see "The Departed"
38
39
 
@@ -1,12 +1,12 @@
1
- Feature: Public Pages
2
- In order to find out more information
3
- As a user
4
- I want to be able to see what's on a page
5
-
6
- Scenario: A public page
7
- Given a page titled "Mr. MacAllister's Christmas"
8
- And page "Mr. MacAllister's Christmas" has content "I was Home Alone"
9
-
10
- When I am on the page for "Mr. MacAllister's Christmas"
11
-
1
+ Feature: Public Pages
2
+ In order to find out more information
3
+ As a user
4
+ I want to be able to see what's on a page
5
+
6
+ Scenario: A public page
7
+ Given a page titled "Mr. MacAllister's Christmas"
8
+ And page "Mr. MacAllister's Christmas" has content "I was Home Alone"
9
+
10
+ When I am on the page for "Mr. MacAllister's Christmas"
11
+
12
12
  Then I should see "I was Home Alone"
@@ -1,7 +1,7 @@
1
- Given /^a page titled "([^\"]*)"$/ do |title|
2
- Page.make(:title => title)
3
- end
4
-
5
- Given /^page "([^\"]*)" has content "([^\"]*)"$/ do |title, content|
6
- Page.find_by_title(title).update_attribute(:content, content)
1
+ Given /^a page titled "([^\"]*)"$/ do |title|
2
+ Page.make(:title => title)
3
+ end
4
+
5
+ Given /^page "([^\"]*)" has content "([^\"]*)"$/ do |title, content|
6
+ Page.find_by_title(title).update_attribute(:content, content)
7
7
  end
@@ -1,259 +1,192 @@
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 File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
9
-
10
- # Commonly used webrat steps
11
- # http://github.com/brynary/webrat
12
-
13
- Given /^(?:|I )am on (.+)$/ do |page_name|
14
- visit path_to(page_name)
15
- end
16
-
17
- When /^(?:|I )go to (.+)$/ do |page_name|
18
- visit path_to(page_name)
19
- end
20
-
21
- When /^(?:|I )press "([^\"]*)"$/ do |button|
22
- click_button(button)
23
- end
24
-
25
- When /^(?:|I )follow "([^\"]*)"$/ do |link|
26
- click_link(link)
27
- end
28
-
29
- When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
30
- click_link_within(parent, link)
31
- end
32
-
33
- When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
34
- fill_in(field, :with => value)
35
- end
36
-
37
- When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
38
- fill_in(field, :with => value)
39
- end
40
-
41
- # Use this to fill in an entire form with data from a table. Example:
42
- #
43
- # When I fill in the following:
44
- # | Account Number | 5002 |
45
- # | Expiry date | 2009-11-01 |
46
- # | Note | Nice guy |
47
- # | Wants Email? | |
48
- #
49
- # TODO: Add support for checkbox, select og option
50
- # based on naming conventions.
51
- #
52
- When /^(?:|I )fill in the following:$/ do |fields|
53
- fields.rows_hash.each do |name, value|
54
- When %{I fill in "#{name}" with "#{value}"}
55
- end
56
- end
57
-
58
- When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
59
- select(value, :from => field)
60
- end
61
-
62
- # Use this step in conjunction with Rail's datetime_select helper. For example:
63
- # When I select "December 25, 2008 10:00" as the date and time
64
- When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
65
- select_datetime(time)
66
- end
67
-
68
- # Use this step when using multiple datetime_select helpers on a page or
69
- # you want to specify which datetime to select. Given the following view:
70
- # <%= f.label :preferred %><br />
71
- # <%= f.datetime_select :preferred %>
72
- # <%= f.label :alternative %><br />
73
- # <%= f.datetime_select :alternative %>
74
- # The following steps would fill out the form:
75
- # When I select "November 23, 2004 11:20" as the "Preferred" date and time
76
- # And I select "November 25, 2004 10:30" as the "Alternative" date and time
77
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
78
- select_datetime(datetime, :from => datetime_label)
79
- end
80
-
81
- # Use this step in conjunction with Rail's time_select helper. For example:
82
- # When I select "2:20PM" as the time
83
- # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
84
- # will convert the 2:20PM to 14:20 and then select it.
85
- When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
86
- select_time(time)
87
- end
88
-
89
- # Use this step when using multiple time_select helpers on a page or you want to
90
- # specify the name of the time on the form. For example:
91
- # When I select "7:30AM" as the "Gym" time
92
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
93
- select_time(time, :from => time_label)
94
- end
95
-
96
- # Use this step in conjunction with Rail's date_select helper. For example:
97
- # When I select "February 20, 1981" as the date
98
- When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
99
- select_date(date)
100
- end
101
-
102
- # Use this step when using multiple date_select helpers on one page or
103
- # you want to specify the name of the date on the form. For example:
104
- # When I select "April 26, 1982" as the "Date of Birth" date
105
- When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
106
- select_date(date, :from => date_label)
107
- end
108
-
109
- When /^(?:|I )check "([^\"]*)"$/ do |field|
110
- check(field)
111
- end
112
-
113
- When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
114
- uncheck(field)
115
- end
116
-
117
- When /^(?:|I )choose "([^\"]*)"$/ do |field|
118
- choose(field)
119
- end
120
-
121
- # Adds support for validates_attachment_content_type. Without the mime-type getting
122
- # passed to attach_file() you will get a "Photo file is not one of the allowed file types."
123
- # error message
124
- When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
125
- type = path.split(".")[1]
126
-
127
- case type
128
- when "jpg"
129
- type = "image/jpg"
130
- when "jpeg"
131
- type = "image/jpeg"
132
- when "png"
133
- type = "image/png"
134
- when "gif"
135
- type = "image/gif"
136
- end
137
-
138
- attach_file(field, path, type)
139
- end
140
-
141
- Then /^(?:|I )should see "([^\"]*)"$/ do |text|
142
- if defined?(Spec::Rails::Matchers)
143
- response.should contain(text)
144
- else
145
- assert_contain text
146
- end
147
- end
148
-
149
- Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
150
- within(selector) do |content|
151
- if defined?(Spec::Rails::Matchers)
152
- content.should contain(text)
153
- else
154
- assert content.include?(text)
155
- end
156
- end
157
- end
158
-
159
- Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
160
- regexp = Regexp.new(regexp)
161
- if defined?(Spec::Rails::Matchers)
162
- response.should contain(regexp)
163
- else
164
- assert_contain regexp
165
- end
166
- end
167
-
168
- Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
169
- within(selector) do |content|
170
- regexp = Regexp.new(regexp)
171
- if defined?(Spec::Rails::Matchers)
172
- content.should contain(regexp)
173
- else
174
- assert content =~ regexp
175
- end
176
- end
177
- end
178
-
179
- Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
180
- if defined?(Spec::Rails::Matchers)
181
- response.should_not contain(text)
182
- else
183
- assert_not_contain text
184
- end
185
- end
186
-
187
- Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
188
- within(selector) do |content|
189
- if defined?(Spec::Rails::Matchers)
190
- content.should_not contain(text)
191
- else
192
- assert !content.include?(text)
193
- end
194
- end
195
- end
196
-
197
- Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
198
- regexp = Regexp.new(regexp)
199
- if defined?(Spec::Rails::Matchers)
200
- response.should_not contain(regexp)
201
- else
202
- assert_not_contain regexp
203
- end
204
- end
205
-
206
- Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
207
- within(selector) do |content|
208
- regexp = Regexp.new(regexp)
209
- if defined?(Spec::Rails::Matchers)
210
- content.should_not contain(regexp)
211
- else
212
- assert content !~ regexp
213
- end
214
- end
215
- end
216
-
217
- Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
218
- if defined?(Spec::Rails::Matchers)
219
- field_labeled(field).value.should =~ /#{value}/
220
- else
221
- assert_match(/#{value}/, field_labeled(field).value)
222
- end
223
- end
224
-
225
- Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
226
- if defined?(Spec::Rails::Matchers)
227
- field_labeled(field).value.should_not =~ /#{value}/
228
- else
229
- assert_no_match(/#{value}/, field_labeled(field).value)
230
- end
231
- end
232
-
233
- Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
234
- if defined?(Spec::Rails::Matchers)
235
- field_labeled(label).should be_checked
236
- else
237
- assert field_labeled(label).checked?
238
- end
239
- end
240
-
241
- Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
242
- if defined?(Spec::Rails::Matchers)
243
- field_labeled(label).should_not be_checked
244
- else
245
- assert !field_labeled(label).checked?
246
- end
247
- end
248
-
249
- Then /^(?:|I )should be on (.+)$/ do |page_name|
250
- if defined?(Spec::Rails::Matchers)
251
- URI.parse(current_url).path.should == path_to(page_name)
252
- else
253
- assert_equal path_to(page_name), URI.parse(current_url).path
254
- end
255
- end
256
-
257
- Then /^show me the page$/ do
258
- save_and_open_page
259
- end
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
+ module WithinHelpers
12
+ def with_scope(locator)
13
+ locator ? within(locator) { yield } : yield
14
+ end
15
+ end
16
+ World(WithinHelpers)
17
+
18
+ Given /^(?:|I )am on (.+)$/ do |page_name|
19
+ visit path_to(page_name)
20
+ end
21
+
22
+ When /^(?:|I )go to (.+)$/ do |page_name|
23
+ visit path_to(page_name)
24
+ end
25
+
26
+ When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
27
+ with_scope(selector) do
28
+ click_button(button)
29
+ end
30
+ end
31
+
32
+ When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
33
+ with_scope(selector) do
34
+ click_link(link)
35
+ end
36
+ end
37
+
38
+ When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
39
+ with_scope(selector) do
40
+ fill_in(field, :with => value)
41
+ end
42
+ end
43
+
44
+ When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
45
+ with_scope(selector) do
46
+ fill_in(field, :with => value)
47
+ end
48
+ end
49
+
50
+ # Use this to fill in an entire form with data from a table. Example:
51
+ #
52
+ # When I fill in the following:
53
+ # | Account Number | 5002 |
54
+ # | Expiry date | 2009-11-01 |
55
+ # | Note | Nice guy |
56
+ # | Wants Email? | |
57
+ #
58
+ # TODO: Add support for checkbox, select og option
59
+ # based on naming conventions.
60
+ #
61
+ When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
62
+ with_scope(selector) do
63
+ fields.rows_hash.each do |name, value|
64
+ When %{I fill in "#{name}" with "#{value}"}
65
+ end
66
+ end
67
+ end
68
+
69
+ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
70
+ with_scope(selector) do
71
+ select(value, :from => field)
72
+ end
73
+ end
74
+
75
+ When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
76
+ with_scope(selector) do
77
+ check(field)
78
+ end
79
+ end
80
+
81
+ When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
82
+ with_scope(selector) do
83
+ uncheck(field)
84
+ end
85
+ end
86
+
87
+ When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
88
+ with_scope(selector) do
89
+ choose(field)
90
+ end
91
+ end
92
+
93
+ When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
94
+ with_scope(selector) do
95
+ attach_file(field, path)
96
+ end
97
+ end
98
+
99
+ Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
100
+ with_scope(selector) do
101
+ if defined?(Spec::Rails::Matchers)
102
+ page.should have_content(text)
103
+ else
104
+ assert page.has_content?(text)
105
+ end
106
+ end
107
+ end
108
+
109
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
110
+ regexp = Regexp.new(regexp)
111
+ with_scope(selector) do
112
+ if defined?(Spec::Rails::Matchers)
113
+ page.should have_xpath('//*', :text => regexp)
114
+ else
115
+ assert page.has_xpath?('//*', :text => regexp)
116
+ end
117
+ end
118
+ end
119
+
120
+ Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
121
+ with_scope(selector) do
122
+ if defined?(Spec::Rails::Matchers)
123
+ page.should have_no_content(text)
124
+ else
125
+ assert page.has_no_content?(text)
126
+ end
127
+ end
128
+ end
129
+
130
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
131
+ regexp = Regexp.new(regexp)
132
+ with_scope(selector) do
133
+ if defined?(Spec::Rails::Matchers)
134
+ page.shoul have_not_xpath('//*', :text => regexp)
135
+ else
136
+ assert page.has_not_xpath?('//*', :text => regexp)
137
+ end
138
+ end
139
+ end
140
+
141
+ Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
142
+ with_scope(selector) do
143
+ if defined?(Spec::Rails::Matchers)
144
+ find_field(field).value.should =~ /#{value}/
145
+ else
146
+ assert_match(/#{value}/, field_labeled(field).value)
147
+ end
148
+ end
149
+ end
150
+
151
+ Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
152
+ with_scope(selector) do
153
+ if defined?(Spec::Rails::Matchers)
154
+ find_field(field).value.should_not =~ /#{value}/
155
+ else
156
+ assert_no_match(/#{value}/, find_field(field).value)
157
+ end
158
+ end
159
+ end
160
+
161
+ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
162
+ with_scope(selector) do
163
+ if defined?(Spec::Rails::Matchers)
164
+ find_field(label)['checked'].should == 'checked'
165
+ else
166
+ assert field_labeled(label)['checked'] == 'checked'
167
+ end
168
+ end
169
+ end
170
+
171
+ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
172
+ with_scope(selector) do
173
+ if defined?(Spec::Rails::Matchers)
174
+ find_field(label)['checked'].should_not == 'checked'
175
+ else
176
+ assert field_labeled(label)['checked'] != 'checked'
177
+ end
178
+ end
179
+ end
180
+
181
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
182
+ current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
183
+ if defined?(Spec::Rails::Matchers)
184
+ current_path.should == path_to(page_name)
185
+ else
186
+ assert_equal path_to(page_name), current_path
187
+ end
188
+ end
189
+
190
+ Then /^show me the page$/ do
191
+ save_and_open_page
192
+ end