Permalink
Browse files

initial capybara setup - petitions_creation migrated

  • Loading branch information...
1 parent 7b26fd7 commit 1c13e21bccda78cd76bc75b8621560f363c24ebd @vvgomes vvgomes committed Aug 26, 2012
Showing with 140 additions and 63 deletions.
  1. +1 −0 .rspec
  2. +21 −20 Gemfile
  3. +3 −0 Gemfile.lock
  4. +0 −4 Rakefile
  5. +51 −0 spec/requests/petitions_spec.rb
  6. +13 −36 spec/requests/users_spec.rb
  7. +18 −3 spec/spec_helper.rb
  8. +33 −0 spec/support/request_flows.rb
View
1 .rspec
@@ -1 +1,2 @@
--colour
+--require spec_helper
View
41 Gemfile
@@ -30,11 +30,24 @@ group :assets do
gem 'jquery-ui-rails'
end
-gem "haml"
+group :test, :development do
+ gem 'rspec-rails', '~> 2.6'
+ gem 'factory_girl_rails', '~> 3.0'
+ gem 'faker', '~> 1.0'
+ gem 'autotest'
+ gem 'simplecov', :require => false
+ gem 'selenium-webdriver'
+ gem 'hirb'
+ gem 'jslint_on_rails'
+ gem 'capybara'
+ gem 'database_cleaner'
+end
+
+gem 'haml'
gem 'jquery-rails'
gem 'simple_form'
-gem 'bootstrap-wysihtml5-rails', github: "mkurutin/bootstrap-wysihtml5-rails"
-gem "browser"
+gem 'bootstrap-wysihtml5-rails', github: 'mkurutin/bootstrap-wysihtml5-rails'
+gem 'browser'
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
@@ -48,18 +61,6 @@ gem 'bcrypt-ruby', '~> 3.0.0'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
#
-group :test, :development do
- gem "rspec-rails", "~> 2.6"
- gem "factory_girl_rails", "~> 3.0"
- gem "faker", "~> 1.0"
- gem "autotest"
- #gem "selenium-webdriver"
- gem "hirb"
- gem "jslint_on_rails"
- gem 'capybara'
-end
-
-gem 'simplecov', :require => false, :group => :test
gem 'newrelic_rpm'
gem 'unicorn'
@@ -69,7 +70,7 @@ gem 'foreman'
gem 'redis'
gem 'simple-random'
-gem 'aws-ses', "~> 0.4.4", :require => 'aws/ses'
+gem 'aws-ses', '~> 0.4.4', :require => 'aws/ses'
gem 'aws-sdk'
gem 'garb'
@@ -83,11 +84,11 @@ gem 'redis-rails'
gem 'dkim'
gem 'sanitize'
gem 'rinku', :require => 'rails_rinku'
-gem "flot-rails"
+gem 'flot-rails'
gem 'nokogiri'
-gem "truncate_html"
-gem "airbrake"
-gem "fb_graph"
+gem 'truncate_html'
+gem 'airbrake'
+gem 'fb_graph'
gem 'facebook_share_widget', github: 'mkurutin/facebook_share_widget_rails'
gem 'memoist', github: 'matthewrudy/memoist'
gem 'resque'
View
@@ -108,6 +108,7 @@ GEM
compass-rails (1.0.3)
compass (>= 0.12.2, < 0.14)
crack (0.3.1)
+ database_cleaner (0.8.0)
diff-lcs (1.1.3)
dkim (0.2.0)
erubis (2.7.0)
@@ -318,6 +319,7 @@ DEPENDENCIES
capybara
coffee-rails (~> 3.2.1)
compass-rails
+ database_cleaner
dkim
facebook_share_widget!
factory_girl_rails (~> 3.0)
@@ -351,6 +353,7 @@ DEPENDENCIES
rspec-rails (~> 2.6)
sanitize
sass-rails (~> 3.2.3)
+ selenium-webdriver
simple-random
simple_form
simplecov
View
@@ -8,8 +8,4 @@ Victorykit::Application.load_tasks
unless Rails.env.production?
task :default => ['jslint'] #remember, these are *appended* to the existing default tasks
-
- namespace :spec do
- task :all => ['spec']
- end
end
@@ -0,0 +1,51 @@
+describe 'petitions' do
+ let(:email) { 'user@test.com' }
+ let(:pass) { 'pass' }
+
+ shared_examples 'an author' do
+
+ it 'should successfully create a petition' do
+ login email, pass do
+ visit '/petitions/new'
+ fill_in 'Title', with: 'I like Turtles'
+ fill_in 'Short summary', with: 'I love them'
+ fill_in 'Description', with: 'Turtles are awesome!'
+ click_button 'Create Petition'
+
+ page.current_path.should =~ /petitions\/\d+/
+ page.should have_content 'Petition was successfully created.'
+ page.should have_content 'I like Turtles'
+ page.should have_content 'Turtles are awesome!'
+ end
+ end
+
+ end
+
+ context 'a regular user' do
+ before { create(:user, email: email, password: pass) }
+
+ it_behaves_like 'an author'
+
+ it 'cannot send preview emails to herself' do
+ login email, pass do
+ visit '/petitions/new'
+ page.should_not have_content "Email a preview to #{email}"
+ end
+ end
+ end
+
+ context 'an admin user' do
+ before { create(:admin_user, email: email, password: pass) }
+
+ it_behaves_like 'an author'
+
+ it 'can send a preview email to herself' do
+ login email, pass do
+ visit '/petitions/new'
+ page.should have_content "Email a preview to #{email}"
+ end
+ end
+ end
+
+end
+
@@ -1,49 +1,26 @@
-require 'spec_helper'
-require 'capybara/rails'
-require 'capybara/rspec'
-
describe 'a user' do
- let(:email) { 'zombie@gmail.com' }
- let(:pass) { 'turtles' }
+ let(:email) { 'user@test.com' }
+ let(:pass) { 'pass' }
context 'joining the site' do
- it 'should sign in' do
- visit '/'
- click_link 'Sign Up or Log In'
-
- within '#new_user' do
- fill_in 'Email', with: email
- fill_in 'Password', with: pass
- fill_in 'Password confirmation', with: pass
- click_button 'Sign Up'
- end
-
- page.current_path.should eq '/'
- page.should have_content 'Log Out'
+ it 'should successfuly sign in' do
+ signin email, pass do
+ page.current_path.should eq '/'
+ page.should have_content 'Log Out'
+ end
end
end
context 'already registered' do
-
- before do
- [Petition, User].map(&:delete_all)
- create(:user, email: email, password: pass)
- end
+ before { create(:user, email: email, password: pass) }
- it 'should login' do
- visit '/'
- click_link 'Sign Up or Log In'
-
- within 'form[action="/sessions"]' do
- fill_in 'Email', with: email
- fill_in 'Password', with: pass
- click_button 'Log in'
- end
-
- page.current_path.should eq '/'
- page.should have_content 'Log Out'
+ it 'should successfuly login' do
+ login email, pass do
+ page.current_path.should eq '/'
+ page.should have_content 'Log Out'
+ end
end
end
View
@@ -7,6 +7,8 @@
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/mocks'
+require 'database_cleaner'
+
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@@ -26,13 +28,26 @@
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
- config.use_transactional_fixtures = true
-
+ #config.use_transactional_fixtures = true
+
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.include FactoryGirl::Syntax::Methods
+
+ config.before(:suite) do
+ DatabaseCleaner.strategy = :transaction
+ DatabaseCleaner.clean_with :truncation
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
end
def valid_session
@@ -94,4 +109,4 @@ def stub_bandit_class bandit_class
def guard_against_spins bandit_class
bandit_class.any_instance.stub(:spin!).and_raise("Should not reach this point. Ensure you have stubbed whatever is calling this.")
-end
+end
@@ -0,0 +1,33 @@
+require 'capybara/rails'
+require 'capybara/rspec'
+
+def signin email, pass
+ visit '/'
+ click_link 'Sign Up or Log In'
+ within '#new_user' do
+ fill_in 'Email', with: email
+ fill_in 'Password', with: pass
+ fill_in 'Password confirmation', with: pass
+ click_button 'Sign Up'
+ end
+ yield
+ logout
+end
+
+def login email, pass
+ visit '/'
+ click_link 'Sign Up or Log In'
+ within 'form[action="/sessions"]' do
+ fill_in 'Email', with: email
+ fill_in 'Password', with: pass
+ click_button 'Log in'
+ end
+ yield
+ logout
+end
+
+def logout
+ click_link 'Log Out'
+end
+
+

0 comments on commit 1c13e21

Please sign in to comment.