* bumping capybara to 2.x
This commit is contained in:
parent
4f3cd44fdd
commit
e1c61884a1
3
Gemfile
3
Gemfile
|
|
@ -66,8 +66,9 @@ group :assets do
|
|||
end
|
||||
|
||||
group :test, :cucumber do
|
||||
gem 'capybara', '1.1.2'
|
||||
gem 'capybara'
|
||||
gem 'capybara-screenshot'
|
||||
gem "show_me_the_cookies"
|
||||
gem 'cucumber-rails' #, '1.3.0', :require => false
|
||||
gem 'factory_girl_rails', '4.1.0'
|
||||
gem 'database_cleaner', '0.7.0'
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ class ArtifactsController < ApplicationController
|
|||
|
||||
product = "#{product}/#{os}"
|
||||
|
||||
logger.debug "version check from #{product} with version #{client_version}"
|
||||
|
||||
if !client_version.nil? && client_version.start_with?("Compiled")
|
||||
render :text => "You have a developer version. Upgrades are manual."
|
||||
return
|
||||
end
|
||||
|
||||
unless ArtifactUpdate::PRODUCTS.include? product
|
||||
render :text => "Unknown product type"
|
||||
return
|
||||
|
|
@ -21,7 +28,7 @@ class ArtifactsController < ApplicationController
|
|||
@artifact = ArtifactUpdate.find_by_product_and_environment(product, ArtifactUpdate::DEFAULT_ENVIRONMENT)
|
||||
|
||||
if @artifact.nil?
|
||||
@log.error "no product was found for #{product} and environment: #{ArtifactUpdate::DEFAULT_ENVIRONMENT}"
|
||||
logger.error "no product was found for #{product} and environment: #{ArtifactUpdate::DEFAULT_ENVIRONMENT}"
|
||||
render :text => "No product available"
|
||||
return
|
||||
elsif @artifact.version == client_version
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Authentication" do
|
||||
|
||||
subject { page }
|
||||
|
||||
describe "signin page" do
|
||||
before { visit signin_path }
|
||||
|
||||
it { should have_selector('h1', text: 'sign in or register') }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "signin" do
|
||||
before { visit signin_path }
|
||||
|
||||
describe "with invalid information" do
|
||||
before { click_button "SIGN IN" }
|
||||
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
|
||||
|
||||
#describe "after visiting another page" do
|
||||
#before { click_link "Home" }
|
||||
#it { should_not have_selector('div.alert.alert-error') }
|
||||
#end
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "SIGN IN"
|
||||
end
|
||||
|
||||
# Successful sign-in goes to the client
|
||||
it { should have_selector('title', text: "Jamkazam") }
|
||||
it { should have_selector('h1', text: "Jamkazam") }
|
||||
end
|
||||
end
|
||||
|
||||
describe "authorization" do
|
||||
|
||||
describe "for non-signed-in users" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
describe "when attempting to visit a protected page" do
|
||||
before do
|
||||
visit edit_user_path(user)
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "SIGN IN"
|
||||
end
|
||||
|
||||
describe "after signing in" do
|
||||
|
||||
it "should render the desired protected page" do
|
||||
page.should have_selector('title', text: 'Edit user')
|
||||
end
|
||||
|
||||
describe "when signing in again" do
|
||||
before do
|
||||
visit signin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "SIGN IN"
|
||||
end
|
||||
|
||||
it "should render the signed-in client page" do
|
||||
# it now goes to /music_sessions
|
||||
page.should have_selector('title', text: "Jamkazam")
|
||||
page.should have_selector('h1', text: "Jamkazam")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "in the Users controller" do
|
||||
|
||||
describe "visiting the edit page" do
|
||||
before { visit edit_user_path(user) }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "visiting user index" do
|
||||
before { visit users_path }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "as wrong user" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
|
||||
before { sign_in user }
|
||||
|
||||
describe "visiting Users#edit page" do
|
||||
before { visit edit_user_path(wrong_user) }
|
||||
it { should have_selector('title', text: full_title('')) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Static pages" do
|
||||
|
||||
subject { page }
|
||||
|
||||
|
||||
describe "Home page" do
|
||||
before { visit '/oldhome' }
|
||||
|
||||
it { should have_selector('h1', text: 'Jam') }
|
||||
it { should have_selector('title', text: full_title('')) }
|
||||
it { should_not have_selector 'title', text: '| Home' }
|
||||
|
||||
describe "for signed-in users" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
sign_in user
|
||||
visit root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Help page" do
|
||||
before { visit help_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Help') }
|
||||
it { should have_selector('title', text: full_title('Help')) }
|
||||
end
|
||||
|
||||
describe "About page" do
|
||||
before { visit about_path }
|
||||
|
||||
it { should have_selector('h1', text: 'About') }
|
||||
it { should have_selector('title', text: full_title('About Us')) }
|
||||
end
|
||||
|
||||
describe "Contact page" do
|
||||
before { visit contact_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Contact') }
|
||||
it { should have_selector('title', text: full_title('Contact')) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "User pages" do
|
||||
|
||||
subject { page }
|
||||
|
||||
describe "index" do
|
||||
|
||||
before do
|
||||
sign_in FactoryGirl.create(:user)
|
||||
|
||||
FactoryGirl.create(:user, first_name: "Bob", last_name: "Smith", email: "bob@example.com")
|
||||
FactoryGirl.create(:user, first_name: "Ben", last_name: "Smith", email: "ben@example.com")
|
||||
visit users_path
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: 'All users') }
|
||||
|
||||
describe "pagination" do
|
||||
|
||||
before(:all) { 30.times { FactoryGirl.create(:user) } }
|
||||
after(:all) { User.delete_all }
|
||||
|
||||
let(:first_page) { User.paginate(page: 1) }
|
||||
let(:second_page) { User.paginate(page: 2) }
|
||||
|
||||
it { should have_link('Next') }
|
||||
its(:html) { should match('>2</a>') }
|
||||
|
||||
it "should list each user" do
|
||||
User.all[0..2].each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
it "should list the first page of users" do
|
||||
first_page.each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
it "should not list the second page of users" do
|
||||
second_page.each do |user|
|
||||
page.should_not have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "showing the second page" do
|
||||
before { visit users_path(page: 2) }
|
||||
|
||||
it "should list the second page of users" do
|
||||
second_page.each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete links" do
|
||||
|
||||
it { should_not have_link('delete') }
|
||||
|
||||
describe "as an admin user" do
|
||||
let(:admin) { FactoryGirl.create(:admin) }
|
||||
before do
|
||||
sign_in admin
|
||||
visit users_path
|
||||
end
|
||||
|
||||
it { should have_link('delete', href: user_path(User.first)) }
|
||||
it "should be able to delete another user" do
|
||||
expect { click_link('delete') }.to change(User, :count).by(-1)
|
||||
end
|
||||
it { should_not have_link('delete', href: user_path(admin)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "profile page" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
before { visit user_path(user) }
|
||||
|
||||
it { should have_selector('h1', text: user.name) }
|
||||
it { should have_selector('title', text: user.name) }
|
||||
end
|
||||
|
||||
describe "signup page" do
|
||||
before { visit signup_path }
|
||||
|
||||
it { should have_selector('h1', text: 'create a jamkazam account') }
|
||||
it { should have_selector('title', text: full_title('Sign up')) }
|
||||
end
|
||||
|
||||
describe "signup" do
|
||||
|
||||
before { visit signup_path }
|
||||
|
||||
let(:submit) { "CREATE ACCOUNT" }
|
||||
|
||||
describe "with invalid information" do
|
||||
it "should not create a user" do
|
||||
expect { click_button submit }.not_to change(User, :count)
|
||||
end
|
||||
|
||||
describe "error messages" do
|
||||
before { click_button submit }
|
||||
|
||||
it { should have_selector('title', text: 'Sign up') }
|
||||
it { should have_content('error') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
before do
|
||||
fill_in "First Name", with: "Example"
|
||||
fill_in "Last Name", with: "User"
|
||||
fill_in "Name", with: "Example User"
|
||||
fill_in "Email", with: "user@example.com"
|
||||
fill_in "Password", with: "foobar"
|
||||
fill_in "Verify Password", with: "foobar"
|
||||
end
|
||||
|
||||
it "should create a user" do
|
||||
expect { click_button submit }.to change(User, :count).by(1)
|
||||
end
|
||||
|
||||
describe "after saving the user" do
|
||||
before { click_button submit }
|
||||
|
||||
let(:user) { User.find_by_email('user@example.com') }
|
||||
|
||||
it { should have_selector('title', text: "Confirmation Email Sent") }
|
||||
it { should have_selector('div.alert.alert-success', text: 'check your email') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
sign_in user
|
||||
visit edit_user_path(user)
|
||||
end
|
||||
|
||||
describe "page" do
|
||||
it { should have_selector('h1', text: "Update your profile") }
|
||||
it { should have_selector('title', text: "Edit user") }
|
||||
it { should have_link('change', href: 'http://gravatar.com/emails') }
|
||||
end
|
||||
|
||||
|
||||
describe "with valid information" do
|
||||
let(:new_first_name) { "New" }
|
||||
let(:new_last_name) { "Name" }
|
||||
let(:new_email) { "new@example.com" }
|
||||
before do
|
||||
fill_in "First Name", with: new_first_name
|
||||
fill_in "Last Name", with: new_last_name
|
||||
fill_in "Email", with: new_email
|
||||
fill_in "Password", with: user.password
|
||||
fill_in "Confirm Password", with: user.password
|
||||
click_button "Save changes"
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: new_first_name) }
|
||||
it { should have_selector('title', text: new_last_name) }
|
||||
it { should have_selector('div.alert.alert-success') }
|
||||
specify { user.reload.first_name.should == new_first_name }
|
||||
specify { user.reload.last_name.should == new_last_name }
|
||||
specify { user.reload.email.should == new_email }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
include ApplicationHelper
|
||||
|
||||
def cookie_jar
|
||||
Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
||||
end
|
||||
|
||||
def sign_in(user)
|
||||
visit signin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "SIGN IN"
|
||||
# Sign in when not using Capybara as well.
|
||||
cookies[:remember_token] = user.remember_token
|
||||
end
|
||||
cookie_jar[:remember_token] = user.remember_token
|
||||
end
|
||||
Loading…
Reference in New Issue