bobby 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -6,30 +6,22 @@ gem 'rails', '3.0.0.beta4'
6
6
  # Bundle edge Rails instead:
7
7
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
8
8
 
9
- gem 'sqlite3-ruby', :require => 'sqlite3'
10
-
11
- # Use unicorn as the web server
12
- # gem 'unicorn'
13
-
14
- # Deploy with Capistrano
15
- # gem 'capistrano'
9
+ #
10
+ # gems used exclusively in development
11
+ group :development do
16
12
 
17
- # To use debugger
18
- # gem 'ruby-debug'
19
-
20
- # Bundle the extra gems:
21
- # gem 'bj'
22
- # gem 'nokogiri', '1.4.1'
23
- # gem 'aws-s3', :require => 'aws/s3'
13
+ # To use debugger
14
+ gem 'ruby-debug'
24
15
 
25
- # Bundle gems for certain environments:
26
- # gem 'rspec', :group => :test
27
- # group :test do
28
- # gem 'webrat'
29
- # end
16
+ # keeping SQLqueries slim and N+1 queries to a minimum
17
+ gem 'slim_scrooge'
18
+ #gem "ruby-growl" - not ready for Rails 3
19
+ #gem 'bullet' - not ready for Rails 3
30
20
 
21
+ # for development only !
22
+ #gem "rails-footnotes" - not ready for Rails 3
31
23
 
32
- #gem 'rails', :path => "./vendor/rails"
24
+ end
33
25
 
34
26
  gem "rspec-rails", ">= 2.0.0.beta.17"
35
27
  gem 'rspec'
@@ -38,4 +30,57 @@ gem 'cucumber'
38
30
  gem 'cucumber-rails'
39
31
  gem 'aruba', ">= 0.2.0", :require => nil
40
32
  gem 'jeweler'
41
- gem 'webrat'
33
+ gem 'capybara'
34
+
35
+ #
36
+ # gems used exclusively in testing
37
+ group :test do
38
+
39
+
40
+ end
41
+
42
+ # database interfaces to provide
43
+ # gem 'mysql'
44
+ gem 'sqlite3-ruby', :require => 'sqlite3'
45
+
46
+ # templating with HAML/SASS
47
+ gem 'haml'
48
+
49
+ # forms building help
50
+ gem "simple_form"
51
+
52
+ # handling state-machines on models
53
+ gem 'state_machine'
54
+
55
+ # administer users
56
+ gem "devise", "1.1.rc2"
57
+
58
+ # make sure only humans register
59
+ # gem "humanizer"
60
+
61
+ # managing resources in a DRY way
62
+ # gem 'inherited_resources', '1.1.2'
63
+
64
+ # handle generators not part of Rails 3
65
+ gem 'rails3-generators'
66
+
67
+ # provide a picture library for barcodes generation
68
+ # gem 'png'
69
+
70
+ # control barcodes generation with Barby
71
+ # gem 'barby'
72
+
73
+ # layered barcodes handling - requires barby and png
74
+ # gem 'brocade'
75
+
76
+ # make the database versioned
77
+ # gem 'paper_trail'
78
+
79
+ # Deploy with Capistrano
80
+ # gem 'capistrano'
81
+
82
+ # Bundle the extra gems:
83
+ # gem 'bj'
84
+ # gem 'nokogiri', '1.4.1'
85
+ # gem 'aws-s3', :require => 'aws/s3'
86
+
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
- require 'rubygems'
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
2
5
  require 'rake'
3
6
 
7
+ Rails::Application.load_tasks
8
+
9
+
10
+ require 'rubygems'
11
+
4
12
  begin
5
13
  require 'jeweler'
6
14
  Jeweler::Tasks.new do |gem|
@@ -20,17 +28,20 @@ rescue LoadError
20
28
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
29
  end
22
30
 
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_files = FileList['spec/**/*_spec.rb']
27
- end
28
-
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
31
+ #
32
+ # no such file to load -- spec/rake/spectask
33
+ #
34
+ # require 'spec/rake/spectask'
35
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
36
+ # spec.libs << 'lib' << 'spec'
37
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
38
+ # end
39
+ #
40
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
41
+ # spec.libs << 'lib' << 'spec'
42
+ # spec.pattern = 'spec/**/*_spec.rb'
43
+ # spec.rcov = true
44
+ # end
34
45
 
35
46
  task :spec => :check_dependencies
36
47
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
data/bobby.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bobby}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Enrique Phillips"]
@@ -26,13 +26,28 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bobby.gemspec",
29
- "features/bobby.feature",
30
- "features/step_definitions/bobby_steps.rb",
29
+ "features/manage_posts.feature",
30
+ "features/step_definitions/devise_steps.rb",
31
+ "features/step_definitions/post_steps.rb",
32
+ "features/step_definitions/web_steps.rb",
31
33
  "features/support/env.rb",
34
+ "features/support/paths.rb",
32
35
  "lib/bobby.rb",
36
+ "lib/tasks/.gitkeep",
37
+ "lib/tasks/cucumber.rake",
38
+ "lib/tasks/jquery_setup.rake",
33
39
  "spec/bobby_spec.rb",
40
+ "spec/controllers/posts_controller_spec.rb",
41
+ "spec/helpers/posts_helper_spec.rb",
42
+ "spec/models/post_spec.rb",
43
+ "spec/requests/posts_spec.rb",
44
+ "spec/routing/posts_routing_spec.rb",
34
45
  "spec/spec.opts",
35
- "spec/spec_helper.rb"
46
+ "spec/spec_helper.rb",
47
+ "spec/views/posts/edit.html.erb_spec.rb",
48
+ "spec/views/posts/index.html.erb_spec.rb",
49
+ "spec/views/posts/new.html.erb_spec.rb",
50
+ "spec/views/posts/show.html.erb_spec.rb"
36
51
  ]
37
52
  s.homepage = %q{http://github.com/ep-wac/Bobby}
38
53
  s.rdoc_options = ["--charset=UTF-8"]
@@ -41,9 +56,19 @@ Gem::Specification.new do |s|
41
56
  s.summary = %q{Have the Ol' Bobby Tit Head take his turns at watching over the access to actions on controllers and instances of models?}
42
57
  s.test_files = [
43
58
  "spec/bobby_spec.rb",
59
+ "spec/controllers/posts_controller_spec.rb",
60
+ "spec/helpers/posts_helper_spec.rb",
61
+ "spec/models/post_spec.rb",
62
+ "spec/requests/posts_spec.rb",
63
+ "spec/routing/posts_routing_spec.rb",
44
64
  "spec/spec_helper.rb",
65
+ "spec/views/posts/edit.html.erb_spec.rb",
66
+ "spec/views/posts/index.html.erb_spec.rb",
67
+ "spec/views/posts/new.html.erb_spec.rb",
68
+ "spec/views/posts/show.html.erb_spec.rb",
45
69
  "test/performance/browsing_test.rb",
46
- "test/test_helper.rb"
70
+ "test/test_helper.rb",
71
+ "test/unit/user_test.rb"
47
72
  ]
48
73
 
49
74
  if s.respond_to? :specification_version then
@@ -0,0 +1,29 @@
1
+ Feature: Manage posts as a logged in user
2
+ In order to demonstrate the features of the Bobby Gem and verify that Cucumber works
3
+ as a user I
4
+ wants to be able to add new posts
5
+
6
+ Background: Logged in
7
+ Given I am a new, authenticated user
8
+
9
+ Scenario: Register new post
10
+ Given I am on the new post page
11
+ When I fill in "Title" with "title 1"
12
+ And I fill in "Body" with "body 1"
13
+ And I press "Create"
14
+ Then I should see "title 1"
15
+ And I should see "body 1"
16
+
17
+ Scenario: Delete post
18
+ Given the following posts:
19
+ |title|body|
20
+ |title 1|body 1|
21
+ |title 2|body 2|
22
+ |title 3|body 3|
23
+ |title 4|body 4|
24
+ When I delete the 3rd post
25
+ Then I should see the following posts:
26
+ |Title|Body|
27
+ |title 1|body 1|
28
+ |title 2|body 2|
29
+ |title 4|body 4|
@@ -0,0 +1,22 @@
1
+ Given /^I am not authenticated$/ do
2
+ visit('/users/sign_out') # ensure that at least
3
+ end
4
+
5
+ Given /^I have one\s+user "([^\"]*)" with password "([^\"]*)" and login "([^\"]*)"$/ do |email, password, login|
6
+ User.new(:email => email,
7
+ :login => login,
8
+ :password => password,
9
+ :password_confirmation => password).save!
10
+ end
11
+
12
+ Given /^I am a new, authenticated user$/ do
13
+ email = 'testing@man.net'
14
+ login = 'Testing man'
15
+ password = 'secretpass'
16
+
17
+ Given %{I have one user "#{email}" with password "#{password}" and login "#{login}"}
18
+ And %{I go to login}
19
+ And %{I fill in "user_email" with "#{email}"}
20
+ And %{I fill in "user_password" with "#{password}"}
21
+ And %{I press "Sign in"}
22
+ end
@@ -0,0 +1,14 @@
1
+ Given /^the following posts:$/ do |posts|
2
+ Post.create!(posts.hashes)
3
+ end
4
+
5
+ When /^I delete the (\d+)(?:st|nd|rd|th) post$/ do |pos|
6
+ visit posts_path
7
+ within("table tr:nth-child(#{pos.to_i+1})") do
8
+ click_link "Destroy"
9
+ end
10
+ end
11
+
12
+ Then /^I should see the following posts:$/ do |expected_posts_table|
13
+ expected_posts_table.diff!(tableish('table tr', 'td,th'))
14
+ end
@@ -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
@@ -1,4 +1,58 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
- require 'bobby'
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.
3
6
 
4
- require 'spec/expectations'
7
+ ENV["RAILS_ENV"] ||= "test"
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/rspec'
12
+ require 'cucumber/rails/world'
13
+ require 'cucumber/rails/active_record'
14
+ require 'cucumber/web/tableish'
15
+
16
+ require 'capybara/rails'
17
+ require 'capybara/cucumber'
18
+ require 'capybara/session'
19
+ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
20
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
21
+ # order to ease the transition to Capybara we set the default here. If you'd
22
+ # prefer to use XPath just remove this line and adjust any selectors in your
23
+ # steps to use the XPath syntax.
24
+ Capybara.default_selector = :css
25
+
26
+ # If you set this to false, any error raised from within your app will bubble
27
+ # up to your step definition and out to cucumber unless you catch it somewhere
28
+ # on the way. You can make Rails rescue errors and render error pages on a
29
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
30
+ #
31
+ # If you set this to true, Rails will rescue all errors and render error
32
+ # pages, more or less in the same way your application would behave in the
33
+ # default production environment. It's not recommended to do this for all
34
+ # of your scenarios, as this makes it hard to discover errors in your application.
35
+ ActionController::Base.allow_rescue = false
36
+
37
+ # If you set this to true, each scenario will run in a database transaction.
38
+ # You can still turn off transactions on a per-scenario basis, simply tagging
39
+ # a feature or scenario with the @no-txn tag. If you are using Capybara,
40
+ # tagging with @culerity or @javascript will also turn transactions off.
41
+ #
42
+ # If you set this to false, transactions will be off for all scenarios,
43
+ # regardless of whether you use @no-txn or not.
44
+ #
45
+ # Beware that turning transactions off will leave data in your database
46
+ # after each scenario, which can lead to hard-to-debug failures in
47
+ # subsequent scenarios. If you do this, we recommend you create a Before
48
+ # block that will explicitly put your database in a known state.
49
+ Cucumber::Rails::World.use_transactional_fixtures = true
50
+ # How to clean your database when transactions are turned off. See
51
+ # http://github.com/bmabey/database_cleaner for more info.
52
+ if defined?(ActiveRecord::Base)
53
+ begin
54
+ require 'database_cleaner'
55
+ DatabaseCleaner.strategy = :truncation
56
+ rescue LoadError => ignore_if_database_cleaner_not_present
57
+ end
58
+ end
@@ -0,0 +1,39 @@
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 /login/
12
+ '/users/sign_in'
13
+
14
+ when /the home\s?page/
15
+ '/'
16
+ when /the new post page/
17
+ new_post_path
18
+
19
+
20
+ # Add more mappings here.
21
+ # Here is an example that pulls values out of the Regexp:
22
+ #
23
+ # when /^(.*)'s profile page$/i
24
+ # user_profile_path(User.find_by_login($1))
25
+
26
+ else
27
+ begin
28
+ page_name =~ /the (.*) page/
29
+ path_components = $1.split(/\s+/)
30
+ self.send(path_components.push('path').join('_').to_sym)
31
+ rescue Object => e
32
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
33
+ "Now, go and add a mapping in #{__FILE__}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ World(NavigationHelpers)
@@ -0,0 +1,53 @@
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
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
+
10
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
+
13
+ begin
14
+ require 'cucumber/rake/task'
15
+
16
+ namespace :cucumber do
17
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
+ t.fork = true # You may get faster startup if you set this to false
20
+ t.profile = 'default'
21
+ end
22
+
23
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
+ t.binary = vendored_cucumber_bin
31
+ t.fork = true # You may get faster startup if you set this to false
32
+ t.profile = 'rerun'
33
+ end
34
+
35
+ desc 'Run all features'
36
+ task :all => [:ok, :wip]
37
+ end
38
+ desc 'Alias for cucumber:ok'
39
+ task :cucumber => 'cucumber:ok'
40
+
41
+ task :default => :cucumber
42
+
43
+ task :features => :cucumber do
44
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
45
+ end
46
+ rescue LoadError
47
+ desc 'cucumber rake task not available (cucumber not installed)'
48
+ task :cucumber do
49
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,48 @@
1
+ # Rails 3 jQuery Install Rakefile
2
+ # by Aaron Kalin
3
+ # Compiled from http://www.railsinside.com/tips/451-howto-unobtrusive-javascript-with-rails-3.html
4
+ #
5
+ # Note: this assumes you use git, if not then use the optional usage
6
+ #
7
+ # Usage: rake install_query
8
+ #
9
+ # Optional usage: rake install_jquery[nogit]
10
+ #
11
+ # Install: drop this file into lib/tasks, then run rake install_jquery
12
+
13
+ desc "replace prototype with jQuery (via git)"
14
+ task :install_jquery, :nogit do |t, args|
15
+ puts "Ripping out Prototype"
16
+ # Prototype files to remove
17
+ proto = ["public/javascripts/prototype.js",
18
+ "public/javascripts/dragdrop.js",
19
+ "public/javascripts/effects.js",
20
+ "public/javascripts/controls.js"].join(" ")
21
+ # check for git
22
+ if args.nogit
23
+ remove = "rm"
24
+ else
25
+ remove = "git rm"
26
+ end
27
+ # Remove files
28
+ system "#{remove} #{proto}"
29
+
30
+ # Setup jQuery
31
+ puts "Downloading jQuery"
32
+ system "curl -L http://code.jquery.com/jquery-1.4.2.min.js > public/javascripts/jquery.js"
33
+ system "curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js > public/javascripts/rails.js"
34
+
35
+ # Install initializer
36
+ puts "Installing Initializer"
37
+ assetstring = %{
38
+ module ActionView::Helpers::AssetTagHelper
39
+ remove_const :JAVASCRIPT_DEFAULT_SOURCES
40
+ JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)
41
+
42
+ reset_javascript_include_default
43
+ end
44
+ }
45
+ File.open("config/initializers/jquery.rb", "w") do |f|
46
+ f.write assetstring
47
+ end
48
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe PostsController do
4
+
5
+ def mock_post(stubs={})
6
+ @mock_post ||= mock_model(Post, stubs).as_null_object
7
+ end
8
+
9
+ describe "GET index" do
10
+ it "assigns all posts as @posts" do
11
+ Post.stub(:all) { [mock_post] }
12
+ get :index
13
+ assigns(:posts).should eq([mock_post])
14
+ end
15
+ end
16
+
17
+ describe "GET show" do
18
+ it "assigns the requested post as @post" do
19
+ Post.stub(:find).with("37") { mock_post }
20
+ get :show, :id => "37"
21
+ assigns(:post).should be(mock_post)
22
+ end
23
+ end
24
+
25
+ describe "GET new" do
26
+ it "assigns a new post as @post" do
27
+ Post.stub(:new) { mock_post }
28
+ get :new
29
+ assigns(:post).should be(mock_post)
30
+ end
31
+ end
32
+
33
+ describe "GET edit" do
34
+ it "assigns the requested post as @post" do
35
+ Post.stub(:find).with("37") { mock_post }
36
+ get :edit, :id => "37"
37
+ assigns(:post).should be(mock_post)
38
+ end
39
+ end
40
+
41
+ describe "POST create" do
42
+
43
+ describe "with valid params" do
44
+ it "assigns a newly created post as @post" do
45
+ Post.stub(:new).with({'these' => 'params'}) { mock_post(:save => true) }
46
+ post :create, :post => {'these' => 'params'}
47
+ assigns(:post).should be(mock_post)
48
+ end
49
+
50
+ it "redirects to the created post" do
51
+ Post.stub(:new) { mock_post(:save => true) }
52
+ post :create, :post => {}
53
+ response.should redirect_to(post_url(mock_post))
54
+ end
55
+ end
56
+
57
+ describe "with invalid params" do
58
+ it "assigns a newly created but unsaved post as @post" do
59
+ Post.stub(:new).with({'these' => 'params'}) { mock_post(:save => false) }
60
+ post :create, :post => {'these' => 'params'}
61
+ assigns(:post).should be(mock_post)
62
+ end
63
+
64
+ it "re-renders the 'new' template" do
65
+ Post.stub(:new) { mock_post(:save => false) }
66
+ post :create, :post => {}
67
+ response.should render_template("new")
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe "PUT update" do
74
+
75
+ describe "with valid params" do
76
+ it "updates the requested post" do
77
+ Post.should_receive(:find).with("37") { mock_post }
78
+ mock_post.should_receive(:update_attributes).with({'these' => 'params'})
79
+ put :update, :id => "37", :post => {'these' => 'params'}
80
+ end
81
+
82
+ it "assigns the requested post as @post" do
83
+ Post.stub(:find) { mock_post(:update_attributes => true) }
84
+ put :update, :id => "1"
85
+ assigns(:post).should be(mock_post)
86
+ end
87
+
88
+ it "redirects to the post" do
89
+ Post.stub(:find) { mock_post(:update_attributes => true) }
90
+ put :update, :id => "1"
91
+ response.should redirect_to(post_url(mock_post))
92
+ end
93
+ end
94
+
95
+ describe "with invalid params" do
96
+ it "assigns the post as @post" do
97
+ Post.stub(:find) { mock_post(:update_attributes => false) }
98
+ put :update, :id => "1"
99
+ assigns(:post).should be(mock_post)
100
+ end
101
+
102
+ it "re-renders the 'edit' template" do
103
+ Post.stub(:find) { mock_post(:update_attributes => false) }
104
+ put :update, :id => "1"
105
+ response.should render_template("edit")
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ describe "DELETE destroy" do
112
+ it "destroys the requested post" do
113
+ Post.should_receive(:find).with("37") { mock_post }
114
+ mock_post.should_receive(:destroy)
115
+ delete :destroy, :id => "37"
116
+ end
117
+
118
+ it "redirects to the posts list" do
119
+ Post.stub(:find) { mock_post }
120
+ delete :destroy, :id => "1"
121
+ response.should redirect_to(posts_url)
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the PostsHelper. For example:
5
+ #
6
+ # describe PostsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe PostsHelper do
14
+ pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Post do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Posts" do
4
+ describe "GET /posts" do
5
+ it "works! (now write some real specs)" do
6
+ get posts_path
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe PostsController do
4
+ describe "routing" do
5
+
6
+ it "recognizes and generates #index" do
7
+ { :get => "/posts" }.should route_to(:controller => "posts", :action => "index")
8
+ end
9
+
10
+ it "recognizes and generates #new" do
11
+ { :get => "/posts/new" }.should route_to(:controller => "posts", :action => "new")
12
+ end
13
+
14
+ it "recognizes and generates #show" do
15
+ { :get => "/posts/1" }.should route_to(:controller => "posts", :action => "show", :id => "1")
16
+ end
17
+
18
+ it "recognizes and generates #edit" do
19
+ { :get => "/posts/1/edit" }.should route_to(:controller => "posts", :action => "edit", :id => "1")
20
+ end
21
+
22
+ it "recognizes and generates #create" do
23
+ { :post => "/posts" }.should route_to(:controller => "posts", :action => "create")
24
+ end
25
+
26
+ it "recognizes and generates #update" do
27
+ { :put => "/posts/1" }.should route_to(:controller => "posts", :action => "update", :id => "1")
28
+ end
29
+
30
+ it "recognizes and generates #destroy" do
31
+ { :delete => "/posts/1" }.should route_to(:controller => "posts", :action => "destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,3 +7,31 @@ require 'spec/autorun'
7
7
  Spec::Runner.configure do |config|
8
8
 
9
9
  end
10
+
11
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
12
+ # from the project root directory.
13
+ ENV["RAILS_ENV"] ||= 'test'
14
+ require File.expand_path("../../config/environment", __FILE__)
15
+ require 'rspec/rails'
16
+
17
+ # Requires supporting files with custom matchers and macros, etc,
18
+ # in ./support/ and its subdirectories.
19
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
20
+
21
+ RSpec.configure do |config|
22
+ # == Mock Framework
23
+ #
24
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
25
+ #
26
+ # config.mock_with :mocha
27
+ # config.mock_with :flexmock
28
+ # config.mock_with :rr
29
+ config.mock_with :rspec
30
+
31
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
32
+
33
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
34
+ # examples within a transaction, comment the following line or assign false
35
+ # instead of true.
36
+ config.use_transactional_fixtures = true
37
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/edit.html.erb" do
4
+ before(:each) do
5
+ @post = assign(:post, stub_model(Post,
6
+ :new_record? => false,
7
+ :title => "MyString",
8
+ :body => "MyText"
9
+ ))
10
+ end
11
+
12
+ it "renders the edit post form" do
13
+ render
14
+
15
+ rendered.should have_selector("form", :action => post_path(@post), :method => "post") do |form|
16
+ form.should have_selector("input#post_title", :name => "post[title]")
17
+ form.should have_selector("textarea#post_body", :name => "post[body]")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/index.html.erb" do
4
+ before(:each) do
5
+ assign(:posts, [
6
+ stub_model(Post,
7
+ :title => "Title",
8
+ :body => "MyText"
9
+ ),
10
+ stub_model(Post,
11
+ :title => "Title",
12
+ :body => "MyText"
13
+ )
14
+ ])
15
+ end
16
+
17
+ it "renders a list of posts" do
18
+ render
19
+ rendered.should have_selector("tr>td", :content => "Title".to_s, :count => 2)
20
+ rendered.should have_selector("tr>td", :content => "MyText".to_s, :count => 2)
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/new.html.erb" do
4
+ before(:each) do
5
+ assign(:post, stub_model(Post,
6
+ :new_record? => true,
7
+ :title => "MyString",
8
+ :body => "MyText"
9
+ ))
10
+ end
11
+
12
+ it "renders new post form" do
13
+ render
14
+
15
+ rendered.should have_selector("form", :action => posts_path, :method => "post") do |form|
16
+ form.should have_selector("input#post_title", :name => "post[title]")
17
+ form.should have_selector("textarea#post_body", :name => "post[body]")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "posts/show.html.erb" do
4
+ before(:each) do
5
+ @post = assign(:post, stub_model(Post,
6
+ :title => "Title",
7
+ :body => "MyText"
8
+ ))
9
+ end
10
+
11
+ it "renders attributes in <p>" do
12
+ render
13
+ rendered.should contain("Title".to_s)
14
+ rendered.should contain("MyText".to_s)
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Enrique Phillips
@@ -19,9 +19,10 @@ date: 2010-07-21 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rspec
22
+ type: :development
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ name: rspec
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ">="
@@ -32,12 +33,12 @@ dependencies:
32
33
  - 2
33
34
  - 9
34
35
  version: 1.2.9
35
- type: :development
36
- version_requirements: *id001
36
+ requirement: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: cucumber
38
+ type: :development
39
39
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ name: cucumber
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
43
44
  - - ">="
@@ -46,8 +47,7 @@ dependencies:
46
47
  segments:
47
48
  - 0
48
49
  version: "0"
49
- type: :development
50
- version_requirements: *id002
50
+ requirement: *id002
51
51
  description: |-
52
52
  Bobby is all about guarding the access to actions on controllers and model instances on your Rails projects, and requires you to setup some authentication
53
53
  regime in advance - like Devise, Authlogic et al - with a User model, and preferably a GroupUser and GroupUsersUsers models too.
@@ -68,15 +68,31 @@ files:
68
68
  - Rakefile
69
69
  - VERSION
70
70
  - bobby.gemspec
71
- - features/bobby.feature
72
- - features/step_definitions/bobby_steps.rb
71
+ - features/manage_posts.feature
72
+ - features/step_definitions/devise_steps.rb
73
+ - features/step_definitions/post_steps.rb
74
+ - features/step_definitions/web_steps.rb
73
75
  - features/support/env.rb
76
+ - features/support/paths.rb
74
77
  - lib/bobby.rb
78
+ - lib/tasks/.gitkeep
79
+ - lib/tasks/cucumber.rake
80
+ - lib/tasks/jquery_setup.rake
75
81
  - spec/bobby_spec.rb
82
+ - spec/controllers/posts_controller_spec.rb
83
+ - spec/helpers/posts_helper_spec.rb
84
+ - spec/models/post_spec.rb
85
+ - spec/requests/posts_spec.rb
86
+ - spec/routing/posts_routing_spec.rb
76
87
  - spec/spec.opts
77
88
  - spec/spec_helper.rb
89
+ - spec/views/posts/edit.html.erb_spec.rb
90
+ - spec/views/posts/index.html.erb_spec.rb
91
+ - spec/views/posts/new.html.erb_spec.rb
92
+ - spec/views/posts/show.html.erb_spec.rb
78
93
  - test/performance/browsing_test.rb
79
94
  - test/test_helper.rb
95
+ - test/unit/user_test.rb
80
96
  has_rdoc: true
81
97
  homepage: http://github.com/ep-wac/Bobby
82
98
  licenses: []
@@ -113,6 +129,16 @@ specification_version: 3
113
129
  summary: Have the Ol' Bobby Tit Head take his turns at watching over the access to actions on controllers and instances of models?
114
130
  test_files:
115
131
  - spec/bobby_spec.rb
132
+ - spec/controllers/posts_controller_spec.rb
133
+ - spec/helpers/posts_helper_spec.rb
134
+ - spec/models/post_spec.rb
135
+ - spec/requests/posts_spec.rb
136
+ - spec/routing/posts_routing_spec.rb
116
137
  - spec/spec_helper.rb
138
+ - spec/views/posts/edit.html.erb_spec.rb
139
+ - spec/views/posts/index.html.erb_spec.rb
140
+ - spec/views/posts/new.html.erb_spec.rb
141
+ - spec/views/posts/show.html.erb_spec.rb
117
142
  - test/performance/browsing_test.rb
118
143
  - test/test_helper.rb
144
+ - test/unit/user_test.rb
@@ -1,9 +0,0 @@
1
- Feature: something something
2
- In order to something something
3
- A user something something
4
- something something something
5
-
6
- Scenario: something something
7
- Given inspiration
8
- When I create a sweet new gem
9
- Then everyone should see how awesome I am