noodall-components-general-content 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +190 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/models/general_content.rb +9 -0
- data/app/views/admin/components/_general_content.html.erb +38 -0
- data/app/views/components/_general_content.html.erb +6 -0
- data/cucumber.yml +8 -0
- data/features/general_content_component.feature +18 -0
- data/features/step_definitions/cms_node_steps.rb +9 -0
- data/features/step_definitions/component_steps.rb +35 -0
- data/features/step_definitions/web_steps.rb +219 -0
- data/features/support/env.rb +50 -0
- data/features/support/paths.rb +58 -0
- data/lib/noodall-components-general-content.rb +1 -0
- data/lib/noodall/components/general_content/engine.rb +11 -0
- data/lib/noodall/components/general_content/version.rb +7 -0
- data/noodall-components-general-content.gemspec +22 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +22 -0
- data/spec/dummy/app/helpers/application_helper.rb +3 -0
- data/spec/dummy/app/models/page_a.rb +8 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/admin/nodes/_page_a.html.erb +47 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/nodes/page_a.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +12 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/dragonfly.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/mongo_mapper.rb +13 -0
- data/spec/dummy/config/initializers/noodall.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +175 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/asset.rb +6 -0
- data/spec/factories/node.rb +6 -0
- data/spec/files/beef.png +0 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/noodall_component_gallery_spec.rb +7 -0
- data/spec/spec_helper.rb +30 -0
- metadata +148 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem "rails", "3.0.1"
|
6
|
+
gem 'noodall-ui', :path => "~/Gems/noodall-ui"
|
7
|
+
gem "capybara", ">= 0.3.9"
|
8
|
+
gem "rspec-rails", ">= 2.0.0.beta"
|
9
|
+
gem 'database_cleaner'
|
10
|
+
gem 'cucumber-rails'
|
11
|
+
gem 'launchy' # So you can do Then show me the page
|
12
|
+
gem 'rmagick', :require => 'RMagick'
|
13
|
+
gem 'dragonfly', '~> 0.7.6'
|
14
|
+
gem 'factory_girl', '~> 1.3.2'
|
15
|
+
gem "faker", "~> 0.3.1"
|
16
|
+
|
17
|
+
|
18
|
+
if RUBY_VERSION < '1.9'
|
19
|
+
gem "ruby-debug", ">= 0.10.3"
|
20
|
+
end
|
21
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
noodall-components-general-content (0.0.1)
|
5
|
+
|
6
|
+
PATH
|
7
|
+
remote: /Users/steve/Gems/noodall-ui
|
8
|
+
specs:
|
9
|
+
noodall-ui (0.0.2)
|
10
|
+
dynamic_form
|
11
|
+
noodall-core
|
12
|
+
thoughtbot-sortable_table (= 0.0.6)
|
13
|
+
will_paginate (~> 3.0.pre2)
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: http://rubygems.org/
|
17
|
+
specs:
|
18
|
+
abstract (1.0.0)
|
19
|
+
actionmailer (3.0.1)
|
20
|
+
actionpack (= 3.0.1)
|
21
|
+
mail (~> 2.2.5)
|
22
|
+
actionpack (3.0.1)
|
23
|
+
activemodel (= 3.0.1)
|
24
|
+
activesupport (= 3.0.1)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
erubis (~> 2.6.6)
|
27
|
+
i18n (~> 0.4.1)
|
28
|
+
rack (~> 1.2.1)
|
29
|
+
rack-mount (~> 0.6.12)
|
30
|
+
rack-test (~> 0.5.4)
|
31
|
+
tzinfo (~> 0.3.23)
|
32
|
+
activemodel (3.0.1)
|
33
|
+
activesupport (= 3.0.1)
|
34
|
+
builder (~> 2.1.2)
|
35
|
+
i18n (~> 0.4.1)
|
36
|
+
activerecord (3.0.1)
|
37
|
+
activemodel (= 3.0.1)
|
38
|
+
activesupport (= 3.0.1)
|
39
|
+
arel (~> 1.0.0)
|
40
|
+
tzinfo (~> 0.3.23)
|
41
|
+
activeresource (3.0.1)
|
42
|
+
activemodel (= 3.0.1)
|
43
|
+
activesupport (= 3.0.1)
|
44
|
+
activesupport (3.0.1)
|
45
|
+
arel (1.0.1)
|
46
|
+
activesupport (~> 3.0.0)
|
47
|
+
bson (1.1.1)
|
48
|
+
builder (2.1.2)
|
49
|
+
canable (0.1.1)
|
50
|
+
capybara (0.4.0)
|
51
|
+
celerity (>= 0.7.9)
|
52
|
+
culerity (>= 0.2.4)
|
53
|
+
mime-types (>= 1.16)
|
54
|
+
nokogiri (>= 1.3.3)
|
55
|
+
rack (>= 1.0.0)
|
56
|
+
rack-test (>= 0.5.4)
|
57
|
+
selenium-webdriver (>= 0.0.27)
|
58
|
+
xpath (~> 0.1.2)
|
59
|
+
celerity (0.8.2)
|
60
|
+
childprocess (0.1.3)
|
61
|
+
ffi (~> 0.6.3)
|
62
|
+
columnize (0.3.1)
|
63
|
+
configuration (1.1.0)
|
64
|
+
cucumber (0.9.3)
|
65
|
+
builder (~> 2.1.2)
|
66
|
+
diff-lcs (~> 1.1.2)
|
67
|
+
gherkin (~> 2.2.9)
|
68
|
+
json (~> 1.4.6)
|
69
|
+
term-ansicolor (~> 1.0.5)
|
70
|
+
cucumber-rails (0.3.2)
|
71
|
+
cucumber (>= 0.8.0)
|
72
|
+
culerity (0.2.12)
|
73
|
+
database_cleaner (0.6.0)
|
74
|
+
diff-lcs (1.1.2)
|
75
|
+
dragonfly (0.7.7)
|
76
|
+
rack
|
77
|
+
dynamic_form (1.1.3)
|
78
|
+
erubis (2.6.6)
|
79
|
+
abstract (>= 1.0.0)
|
80
|
+
factory_girl (1.3.2)
|
81
|
+
faker (0.3.1)
|
82
|
+
ffi (0.6.3)
|
83
|
+
rake (>= 0.8.7)
|
84
|
+
gherkin (2.2.9)
|
85
|
+
json (~> 1.4.6)
|
86
|
+
term-ansicolor (~> 1.0.5)
|
87
|
+
i18n (0.4.2)
|
88
|
+
jnunemaker-validatable (1.8.4)
|
89
|
+
activesupport (>= 2.3.4)
|
90
|
+
json (1.4.6)
|
91
|
+
json_pure (1.4.6)
|
92
|
+
launchy (0.3.7)
|
93
|
+
configuration (>= 0.0.5)
|
94
|
+
rake (>= 0.8.1)
|
95
|
+
linecache (0.43)
|
96
|
+
mail (2.2.9)
|
97
|
+
activesupport (>= 2.3.6)
|
98
|
+
i18n (~> 0.4.1)
|
99
|
+
mime-types (~> 1.16)
|
100
|
+
treetop (~> 1.4.8)
|
101
|
+
mime-types (1.16)
|
102
|
+
mongo (1.1.1)
|
103
|
+
bson (>= 1.1.1)
|
104
|
+
mongo_mapper (0.8.6)
|
105
|
+
activesupport (>= 2.3.4)
|
106
|
+
jnunemaker-validatable (~> 1.8.4)
|
107
|
+
plucky (~> 0.3.6)
|
108
|
+
nokogiri (1.4.3.1)
|
109
|
+
noodall-core (0.1.2)
|
110
|
+
canable (= 0.1.1)
|
111
|
+
mongo_mapper (~> 0.8.6)
|
112
|
+
ramdiv-mongo_mapper_acts_as_tree (= 0.1.1)
|
113
|
+
ruby-stemmer
|
114
|
+
plucky (0.3.6)
|
115
|
+
mongo (~> 1.1)
|
116
|
+
polyglot (0.3.1)
|
117
|
+
rack (1.2.1)
|
118
|
+
rack-mount (0.6.13)
|
119
|
+
rack (>= 1.0.0)
|
120
|
+
rack-test (0.5.6)
|
121
|
+
rack (>= 1.0)
|
122
|
+
rails (3.0.1)
|
123
|
+
actionmailer (= 3.0.1)
|
124
|
+
actionpack (= 3.0.1)
|
125
|
+
activerecord (= 3.0.1)
|
126
|
+
activeresource (= 3.0.1)
|
127
|
+
activesupport (= 3.0.1)
|
128
|
+
bundler (~> 1.0.0)
|
129
|
+
railties (= 3.0.1)
|
130
|
+
railties (3.0.1)
|
131
|
+
actionpack (= 3.0.1)
|
132
|
+
activesupport (= 3.0.1)
|
133
|
+
rake (>= 0.8.4)
|
134
|
+
thor (~> 0.14.0)
|
135
|
+
rake (0.8.7)
|
136
|
+
ramdiv-mongo_mapper_acts_as_tree (0.1.1)
|
137
|
+
mongo_mapper (>= 0.6.8)
|
138
|
+
rmagick (2.13.1)
|
139
|
+
rspec (2.0.1)
|
140
|
+
rspec-core (~> 2.0.1)
|
141
|
+
rspec-expectations (~> 2.0.1)
|
142
|
+
rspec-mocks (~> 2.0.1)
|
143
|
+
rspec-core (2.0.1)
|
144
|
+
rspec-expectations (2.0.1)
|
145
|
+
diff-lcs (>= 1.1.2)
|
146
|
+
rspec-mocks (2.0.1)
|
147
|
+
rspec-core (~> 2.0.1)
|
148
|
+
rspec-expectations (~> 2.0.1)
|
149
|
+
rspec-rails (2.0.1)
|
150
|
+
rspec (~> 2.0.0)
|
151
|
+
ruby-debug (0.10.3)
|
152
|
+
columnize (>= 0.1)
|
153
|
+
ruby-debug-base (~> 0.10.3.0)
|
154
|
+
ruby-debug-base (0.10.3)
|
155
|
+
linecache (>= 0.3)
|
156
|
+
ruby-stemmer (0.8.2)
|
157
|
+
rubyzip (0.9.4)
|
158
|
+
selenium-webdriver (0.0.29)
|
159
|
+
childprocess (>= 0.0.7)
|
160
|
+
ffi (~> 0.6.3)
|
161
|
+
json_pure
|
162
|
+
rubyzip
|
163
|
+
term-ansicolor (1.0.5)
|
164
|
+
thor (0.14.3)
|
165
|
+
thoughtbot-sortable_table (0.0.6)
|
166
|
+
treetop (1.4.8)
|
167
|
+
polyglot (>= 0.3.1)
|
168
|
+
tzinfo (0.3.23)
|
169
|
+
will_paginate (3.0.pre2)
|
170
|
+
xpath (0.1.2)
|
171
|
+
nokogiri (~> 1.3)
|
172
|
+
|
173
|
+
PLATFORMS
|
174
|
+
ruby
|
175
|
+
|
176
|
+
DEPENDENCIES
|
177
|
+
bundler (>= 1.0.0)
|
178
|
+
capybara (>= 0.3.9)
|
179
|
+
cucumber-rails
|
180
|
+
database_cleaner
|
181
|
+
dragonfly (~> 0.7.6)
|
182
|
+
factory_girl (~> 1.3.2)
|
183
|
+
faker (~> 0.3.1)
|
184
|
+
launchy
|
185
|
+
noodall-components-general-content!
|
186
|
+
noodall-ui!
|
187
|
+
rails (= 3.0.1)
|
188
|
+
rmagick
|
189
|
+
rspec-rails (>= 2.0.0.beta)
|
190
|
+
ruby-debug (>= 0.10.3)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2010 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
require 'rspec/core'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
Rspec::Core::RakeTask.new(:spec)
|
13
|
+
|
14
|
+
require 'cucumber/rake/task'
|
15
|
+
|
16
|
+
namespace :cucumber do
|
17
|
+
Cucumber::Rake::Task.new(:ok, 'Run features that should pass') do |t|
|
18
|
+
t.fork = true # You may get faster startup if you set this to false
|
19
|
+
t.profile = 'default'
|
20
|
+
end
|
21
|
+
|
22
|
+
Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|
|
23
|
+
t.fork = true # You may get faster startup if you set this to false
|
24
|
+
t.profile = 'wip'
|
25
|
+
end
|
26
|
+
|
27
|
+
Cucumber::Rake::Task.new(:rerun, 'Record failing features and run only them if any exist') do |t|
|
28
|
+
t.fork = true # You may get faster startup if you set this to false
|
29
|
+
t.profile = 'rerun'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Run all features'
|
33
|
+
task :all => [:ok, :wip]
|
34
|
+
end
|
35
|
+
desc 'Alias for cucumber:ok'
|
36
|
+
task :cucumber => 'cucumber:ok'
|
37
|
+
|
38
|
+
task :default => :cucumber
|
39
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<%= fields_for :node do |f| %>
|
2
|
+
<%= f.fields_for slot_name, component do |f| %>
|
3
|
+
<%= f.hidden_field :_type %>
|
4
|
+
<%= error_messages_for :object => component %>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<%= f.label :title %><br />
|
8
|
+
<span class="input-wrap"><%= f.text_field :title %></span>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p class="file-selectable">
|
12
|
+
<% unless component.asset.nil? %>
|
13
|
+
<span class="file-detail"><%= component.asset.image? ? image_tag( component.asset.url('70x70#', :jpg) ) : asset_icon(component.asset) %></span>
|
14
|
+
<% end -%>
|
15
|
+
<span class="select-file">Select File</span>
|
16
|
+
(<span class="types">Images</span>)
|
17
|
+
<%= f.hidden_field :asset_id, :class => "asset_id" %>
|
18
|
+
</p>
|
19
|
+
|
20
|
+
<p>
|
21
|
+
<%= f.label :content %><br />
|
22
|
+
<span class="input-wrap"><%= f.text_area :content, :cols => 40, :rows => 4, :class => 'lite-editor' %></span>
|
23
|
+
</p>
|
24
|
+
<p>
|
25
|
+
<%= f.label :link %><br />
|
26
|
+
<span class="input-wrap">
|
27
|
+
<%= f.text_field :link %><br/>
|
28
|
+
<span class="link-node">Content</span> |
|
29
|
+
<span class="link-asset">Asset</span>
|
30
|
+
</span>
|
31
|
+
</p>
|
32
|
+
<p>
|
33
|
+
<%= f.label :link_label %><br />
|
34
|
+
<span class="input-wrap"><%= f.text_field :link_label %></span>
|
35
|
+
</p>
|
36
|
+
|
37
|
+
<% end
|
38
|
+
end %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<div id="<%= slot_code %>" class="component general-content <%= 'double' if expand %> <%= additional_classes %>">
|
2
|
+
<h2><%= component.title %></h2>
|
3
|
+
<%= link_to(image_tag(component.asset.url('200x108#', :jpg)), component.link) unless component.asset.nil? %>
|
4
|
+
<div><%= component.content %></div>
|
5
|
+
<%= link_to component.link_label, component.link, :class => "more" %>
|
6
|
+
</div>
|
data/cucumber.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
|
5
|
+
%>
|
6
|
+
default: <%= std_opts %> features
|
7
|
+
wip: --tags @wip:3 --wip features
|
8
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: General Content Component
|
2
|
+
In order to add information on a page a website editor will be able to add text and images to content within component slots
|
3
|
+
|
4
|
+
@javascript
|
5
|
+
Scenario: Add a General Content component
|
6
|
+
Given I am editing content
|
7
|
+
When I click a "Small" component slot
|
8
|
+
And select the "General Content" component
|
9
|
+
And fill in the following within the component:
|
10
|
+
| Title | Big Promotion |
|
11
|
+
#| Content | A really big thing is happening! | TinyMCE
|
12
|
+
| Link | http://wearebeef.co.uk |
|
13
|
+
And I select an image from the asset library
|
14
|
+
And I press "Save" within the component
|
15
|
+
And I press "Publish"
|
16
|
+
And I visit the content page
|
17
|
+
Then I should see "Big Promotion"
|
18
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
When /^(?:|I )click a "([^"]*)" component slot$/ do |slot_name|
|
2
|
+
@_slot_type = slot_name.downcase
|
3
|
+
within('ol#slot-list') do
|
4
|
+
click_link "#{slot_name} Slot"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
When /^(?:|I )select the "([^\"]+)" component$/ do |component_name|
|
9
|
+
within "#fancybox-inner" do
|
10
|
+
select component_name, :from => 'Select the type of component'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^(?:|I )fill in the following within the component:$/ do |fields|
|
15
|
+
within "#fancybox-inner" do
|
16
|
+
fields.rows_hash.each do |name, value|
|
17
|
+
When %{I fill in "#{name}" with "#{value}"}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^(?:|I )press "([^"]*)" within the component$/ do |button|
|
23
|
+
within "#fancybox-inner" do
|
24
|
+
click_button(button)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
When /^(?:|I )select an image from the asset library$/ do
|
29
|
+
asset = Factory(:asset, :title => "My Image")
|
30
|
+
within "#fancybox-inner" do
|
31
|
+
page.find(:css, 'span.select-file').click
|
32
|
+
click_link "Add"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,219 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
require 'cgi'
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
11
|
+
|
12
|
+
module WithinHelpers
|
13
|
+
def with_scope(locator)
|
14
|
+
locator ? within(locator) { yield } : yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
World(WithinHelpers)
|
18
|
+
|
19
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
20
|
+
visit path_to(page_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
24
|
+
visit path_to(page_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
|
28
|
+
with_scope(selector) do
|
29
|
+
click_button(button)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
|
34
|
+
with_scope(selector) do
|
35
|
+
click_link(link)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
|
40
|
+
with_scope(selector) do
|
41
|
+
fill_in(field, :with => value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
|
46
|
+
with_scope(selector) do
|
47
|
+
fill_in(field, :with => value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Use this to fill in an entire form with data from a table. Example:
|
52
|
+
#
|
53
|
+
# When I fill in the following:
|
54
|
+
# | Account Number | 5002 |
|
55
|
+
# | Expiry date | 2009-11-01 |
|
56
|
+
# | Note | Nice guy |
|
57
|
+
# | Wants Email? | |
|
58
|
+
#
|
59
|
+
# TODO: Add support for checkbox, select og option
|
60
|
+
# based on naming conventions.
|
61
|
+
#
|
62
|
+
When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
|
63
|
+
with_scope(selector) do
|
64
|
+
fields.rows_hash.each do |name, value|
|
65
|
+
When %{I fill in "#{name}" with "#{value}"}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
|
71
|
+
with_scope(selector) do
|
72
|
+
select(value, :from => field)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
77
|
+
with_scope(selector) do
|
78
|
+
check(field)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
83
|
+
with_scope(selector) do
|
84
|
+
uncheck(field)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
|
89
|
+
with_scope(selector) do
|
90
|
+
choose(field)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
|
95
|
+
with_scope(selector) do
|
96
|
+
attach_file(field, path)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Then /^(?:|I )should see JSON:$/ do |expected_json|
|
101
|
+
require 'json'
|
102
|
+
expected = JSON.pretty_generate(JSON.parse(expected_json))
|
103
|
+
actual = JSON.pretty_generate(JSON.parse(response.body))
|
104
|
+
expected.should == actual
|
105
|
+
end
|
106
|
+
|
107
|
+
Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
108
|
+
with_scope(selector) do
|
109
|
+
if page.respond_to? :should
|
110
|
+
page.should have_content(text)
|
111
|
+
else
|
112
|
+
assert page.has_content?(text)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
118
|
+
regexp = Regexp.new(regexp)
|
119
|
+
with_scope(selector) do
|
120
|
+
if page.respond_to? :should
|
121
|
+
page.should have_xpath('//*', :text => regexp)
|
122
|
+
else
|
123
|
+
assert page.has_xpath?('//*', :text => regexp)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
129
|
+
with_scope(selector) do
|
130
|
+
if page.respond_to? :should
|
131
|
+
page.should have_no_content(text)
|
132
|
+
else
|
133
|
+
assert page.has_no_content?(text)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
139
|
+
regexp = Regexp.new(regexp)
|
140
|
+
with_scope(selector) do
|
141
|
+
if page.respond_to? :should
|
142
|
+
page.should have_no_xpath('//*', :text => regexp)
|
143
|
+
else
|
144
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
|
150
|
+
with_scope(selector) do
|
151
|
+
field = find_field(field)
|
152
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
153
|
+
if field_value.respond_to? :should
|
154
|
+
field_value.should =~ /#{value}/
|
155
|
+
else
|
156
|
+
assert_match(/#{value}/, field_value)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
|
162
|
+
with_scope(selector) do
|
163
|
+
field = find_field(field)
|
164
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
165
|
+
if field_value.respond_to? :should_not
|
166
|
+
field_value.should_not =~ /#{value}/
|
167
|
+
else
|
168
|
+
assert_no_match(/#{value}/, field_value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
|
174
|
+
with_scope(selector) do
|
175
|
+
field_checked = find_field(label)['checked']
|
176
|
+
if field_checked.respond_to? :should
|
177
|
+
field_checked.should be_true
|
178
|
+
else
|
179
|
+
assert field_checked
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
|
185
|
+
with_scope(selector) do
|
186
|
+
field_checked = find_field(label)['checked']
|
187
|
+
if field_checked.respond_to? :should
|
188
|
+
field_checked.should be_false
|
189
|
+
else
|
190
|
+
assert !field_checked
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
196
|
+
current_path = URI.parse(current_url).path
|
197
|
+
if current_path.respond_to? :should
|
198
|
+
current_path.should == path_to(page_name)
|
199
|
+
else
|
200
|
+
assert_equal path_to(page_name), current_path
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
205
|
+
query = URI.parse(current_url).query
|
206
|
+
actual_params = query ? CGI.parse(query) : {}
|
207
|
+
expected_params = {}
|
208
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
209
|
+
|
210
|
+
if actual_params.respond_to? :should
|
211
|
+
actual_params.should == expected_params
|
212
|
+
else
|
213
|
+
assert_equal expected_params, actual_params
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
Then /^show me the page$/ do
|
218
|
+
save_and_open_page
|
219
|
+
end
|