Permalink
Browse files

Tests are junk. Need help

  • Loading branch information...
1 parent 077590f commit 1a7ec459b9bc0c660752c8c5bd4f37caa61e20e9 @emacadie emacadie committed Mar 27, 2012
View
4 app/helpers/sessions_helper.rb
@@ -4,6 +4,10 @@ def current_user
@current_user ||= User.find_by_id(session[:user])
end
+ def sign_in(user)
+ session[:user] = user.id
+ end
+
def current_user?
current_user.present?
end
View
27 spec/controllers/countries_controller_spec.rb
@@ -34,32 +34,33 @@ def valid_attributes
def valid_session
{}
end
-begin
+# begin
describe "GET index" do
it "assigns all countries as @countries" do
country = Country.create! valid_attributes
visit countries_path
# page { should have_text 'Only admins can see this page' }
+ # puts page.html
page.html {should have_text 'Listing countries'}
end
end
-end
-begin
+# end
+# begin
describe 'index as admin' do
- it 'dislays if logged in as admin' do
- @user = User.new(name: "Example User", email: "lsllsl@example.com",
-
- password: "hello", password_confirmation: "hello", classification: 'administrator' )
- # let(:user) { FactoryGirl.create(:adminuser) }
- visit(login_url @user)
- # page {should have_text 'Listing countries'}
- puts page.html
- page { should have_text 'Only admins can see this page' }
+ it 'displays if logged in as admin' do
+ @user = User.new(name: "Example User", email: "lsllsl@example.com",
+
+ password: "hello", password_confirmation: "hello", classification: 'administrator' )
+ # let(:user) { FactoryGirl.create(:adminuser) }
+ visit(login_url @user)
+ # page {should have_text 'Listing countries'}
+ puts page.html
+ page { should have_text 'Only admins can see this page' }
end
end
-end
+# end
=begin
describe "GET show" do
it "assigns the requested country as @country" do
View
5 spec/controllers/users_controller_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe UsersController do
+ subject { page }
before (:each) do
@user = FactoryGirl.create(:user)
@@ -10,8 +11,10 @@
describe "GET 'show'" do
it "should be successful" do
- get :show, :id => @user.id
+ puts @user.to_s
+ get :manage, :id => @user.id
response.should be_success
+ # puts page.html
end
it "should find the right user" do
View
239 spec/requests/users_spec.rb
@@ -4,169 +4,29 @@
subject { page }
- describe "index" do
-=begin
- before do
- sign_in FactoryGirl.create(:adminuser)
- FactoryGirl.create(:user, name: "Bob", email: "bob@example.com")
- FactoryGirl.create(:user, name: "Ben", email: "ben@example.com")
- visit users_path
- end
-=end
- # it { should have_selector('title', text: 'All users') }
-=begin
- 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') }
- it { should have_link('2') }
-
- 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
-
- 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
+ describe "signup page" do
+ before { visit login_path }
- it { should_not have_link('delete', href: user_path(admin)) }
- end
- end
-=end
+ it { should have_selector('h1', text: 'Sign In') }
+ it { should have_selector('title', text: ('Digital Schoolhouse')) }
end
-=begin
+=begin
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
- let!(:m1) { FactoryGirl.create(:micropost, user: user, content: "Foo") }
- let!(:m2) { FactoryGirl.create(:micropost, user: user, content: "Bar") }
-
- before { visit user_path(user) }
-
+ before { visit users_path(user) }
+
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
-
- describe "microposts" do
- it { should have_content(m1.content) }
- it { should have_content(m2.content) }
- it { should have_content(user.microposts.count) }
- end
-
- it { should have_selector('h1', text: user.name) }
- it { should have_selector('title', text: user.name) }
-
- describe "follow/unfollow buttons" do
- let(:other_user) { FactoryGirl.create(:user) }
- before { sign_in user }
-
- describe "following a user" do
- before { visit user_path(other_user) }
-
- it "should increment the followed user count" do
- expect do
- click_button "Follow"
- end.to change(user.followed_users, :count).by(1)
- end
-
- it "should increment the other user's followers count" do
- expect do
- click_button "Follow"
- end.to change(other_user.followers, :count).by(1)
- end
-
- describe "toggling the button" do
- before { click_button "Follow" }
- it { should have_selector('input', value: 'Unfollow') }
- end
- end
-
- describe "unfollowing a user" do
- before do
- user.follow!(other_user)
- visit user_path(other_user)
- end
-
- it "should decrement the followed user count" do
- expect do
- click_button "Unfollow"
- end.to change(user.followed_users, :count).by(-1)
- end
-
- it "should decrement the other user's followers count" do
- expect do
- click_button "Unfollow"
- end.to change(other_user.followers, :count).by(-1)
- end
-
- describe "toggling the button" do
- before { click_button "Unfollow" }
- it { should have_selector('input', value: 'Follow') }
- end
- end
- end
+
end
-=end
- describe "signup page" do
- before { visit login_path }
-
- it { should have_selector('h1', text: 'Sign In') }
- # puts it
- # it { should have_selector('title', text: full_title('Sign up')) }
- end
-
-=begin
+=end
describe "signup" do
before { visit signup_path }
describe "with invalid information" do
it "should not create a user" do
- expect { click_button "Create my account" }.not_to change(User, :count)
- end
-
- describe "error messages" do
- before { click_button "Create my account" }
-
- it { should have_selector('title', text: 'Sign up') }
- it { should have_content('error') }
+ expect { click_button "Sign up" }.not_to change(User, :count)
end
end
@@ -179,31 +39,29 @@
end
it "should create a user" do
- expect do
- click_button "Create my account"
- end.to change(User, :count).by(1)
+ expect { click_button "Sign up" }.to change(User, :count).by(1)
end
-
+
describe "after saving the user" do
- before { click_button "Create my account" }
+ before { click_button "Sign up" }
let(:user) { User.find_by_email('user@example.com') }
it { should have_selector('title', text: user.name) }
- it { should have_selector('div.alert.alert-success', text: 'Welcome') }
+ it { should have_selector('div.flash.success', text: 'Welcome') }
it { should have_link('Sign out') }
end
+
end
end
-=end
-
-=begin
+
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") }
@@ -228,41 +86,58 @@
end
it { should have_selector('title', text: new_name) }
- it { should have_selector('div.alert.alert-success') }
+ it { should have_selector('div.flash.success') }
it { should have_link('Sign out', :href => signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
end
-=end
-=begin
- describe "following/followers" do
- let(:user) { FactoryGirl.create(:user) }
- let(:other_user) { FactoryGirl.create(:user) }
- before { user.follow!(other_user) }
+
+ describe "index" do
- describe "followed users" do
- before do
- sign_in user
- visit following_user_path(user)
- end
+ let(:user) { FactoryGirl.create(:user) }
- it { should have_selector('title', text: full_title('Following')) }
- it { should have_selector('h3', text: 'Following') }
- it { should have_link(other_user.name, href: user_path(other_user)) }
+ before do
+ sign_in user
+ visit users_path
end
- describe "followers" do
- before do
- sign_in other_user
- visit followers_user_path(other_user)
+ it { should have_selector('title', text: 'All users') }
+
+ describe "pagination" do
+ before(:all) { 30.times { FactoryGirl.create(:user) } }
+ after(:all) { User.delete_all }
+
+ it { should have_link('Next') }
+ it { should have_link('2') }
+
+ 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_not have_link('delete') }
- it { should have_selector('title', text: full_title('Followers')) }
- it { should have_selector('h3', text: 'Followers') }
- it { should have_link(user.name, href: user_path(user)) }
+ 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
-=end
+
end
View
8 spec/support/utilities.rb
@@ -0,0 +1,8 @@
+def sign_in(user)
+ visit login_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.
+ session[:user] = user.id
+end

0 comments on commit 1a7ec45

Please sign in to comment.