2011-10-08 23:36:38 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "Admin::Users" do
|
|
|
|
before { login_as :admin }
|
|
|
|
|
|
|
|
describe "GET /admin/users" do
|
2011-10-26 15:46:25 +02:00
|
|
|
before do
|
2011-10-08 23:36:38 +02:00
|
|
|
visit admin_users_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be ok" do
|
|
|
|
current_path.should == admin_users_path
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should have users list" do
|
2011-10-08 23:36:38 +02:00
|
|
|
page.should have_content(@user.email)
|
|
|
|
page.should have_content(@user.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "GET /admin/users/new" do
|
|
|
|
before do
|
2011-10-08 23:36:38 +02:00
|
|
|
@password = "123ABC"
|
|
|
|
visit new_admin_user_path
|
2012-08-11 00:07:50 +02:00
|
|
|
fill_in "user_name", with: "Big Bang"
|
2012-11-23 21:25:28 +01:00
|
|
|
fill_in "user_username", with: "bang"
|
2012-08-11 00:07:50 +02:00
|
|
|
fill_in "user_email", with: "bigbang@mail.com"
|
|
|
|
fill_in "user_password", with: @password
|
|
|
|
fill_in "user_password_confirmation", with: @password
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should create new user" do
|
2011-10-08 23:36:38 +02:00
|
|
|
expect { click_button "Save" }.to change {User.count}.by(1)
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should create user with valid data" do
|
2011-10-08 23:36:38 +02:00
|
|
|
click_button "Save"
|
|
|
|
user = User.last
|
|
|
|
user.name.should == "Big Bang"
|
|
|
|
user.email.should == "bigbang@mail.com"
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should call send mail" do
|
2013-01-09 07:14:05 +01:00
|
|
|
Notify.should_receive(:new_user_email)
|
2012-06-20 18:29:10 +02:00
|
|
|
|
|
|
|
User.observers.enable :user_observer do
|
2012-06-12 20:27:03 +02:00
|
|
|
click_button "Save"
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should send valid email to user with email & password" do
|
2012-06-20 18:29:10 +02:00
|
|
|
User.observers.enable :user_observer do
|
2013-01-09 07:14:05 +01:00
|
|
|
click_button "Save"
|
2012-06-12 20:27:03 +02:00
|
|
|
user = User.last
|
|
|
|
email = ActionMailer::Base.deliveries.last
|
|
|
|
email.subject.should have_content("Account was created")
|
|
|
|
email.body.should have_content(user.email)
|
|
|
|
email.body.should have_content(@password)
|
2012-05-21 22:05:12 +02:00
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "GET /admin/users/:id" do
|
|
|
|
before do
|
2011-10-08 23:36:38 +02:00
|
|
|
visit admin_users_path
|
2011-11-22 08:55:01 +01:00
|
|
|
click_link "#{@user.name}"
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should have user info" do
|
2011-10-08 23:36:38 +02:00
|
|
|
page.should have_content(@user.email)
|
|
|
|
page.should have_content(@user.name)
|
2011-11-19 10:22:52 +01:00
|
|
|
page.should have_content(@user.projects_limit)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "GET /admin/users/:id/edit" do
|
|
|
|
before do
|
2012-11-06 04:31:55 +01:00
|
|
|
@simple_user = create(:user)
|
2011-10-08 23:36:38 +02:00
|
|
|
visit admin_users_path
|
|
|
|
click_link "edit_user_#{@simple_user.id}"
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should have user edit page" do
|
2011-10-08 23:36:38 +02:00
|
|
|
page.should have_content("Name")
|
|
|
|
page.should have_content("Password")
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Update user" do
|
2011-10-26 15:46:25 +02:00
|
|
|
before do
|
2012-08-11 00:07:50 +02:00
|
|
|
fill_in "user_name", with: "Big Bang"
|
|
|
|
fill_in "user_email", with: "bigbang@mail.com"
|
2011-10-08 23:36:38 +02:00
|
|
|
check "user_admin"
|
|
|
|
click_button "Save"
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should show page with new data" do
|
2011-10-08 23:36:38 +02:00
|
|
|
page.should have_content("bigbang@mail.com")
|
|
|
|
page.should have_content("Big Bang")
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should change user entry" do
|
2011-10-08 23:36:38 +02:00
|
|
|
@simple_user.reload
|
|
|
|
@simple_user.name.should == "Big Bang"
|
|
|
|
@simple_user.is_admin?.should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-11 18:56:18 +01:00
|
|
|
|
2012-11-06 04:31:55 +01:00
|
|
|
describe "Add new project" do
|
|
|
|
before do
|
|
|
|
@new_project = create(:project)
|
2012-02-11 18:56:18 +01:00
|
|
|
visit admin_user_path(@user)
|
|
|
|
end
|
|
|
|
|
2012-11-06 04:31:55 +01:00
|
|
|
it "should create new user" do
|
2012-08-11 00:07:50 +02:00
|
|
|
select @new_project.name, from: "project_ids"
|
2012-02-11 18:56:18 +01:00
|
|
|
expect { click_button "Add" }.to change { UsersProject.count }.by(1)
|
|
|
|
page.should have_content @new_project.name
|
|
|
|
current_path.should == admin_user_path(@user)
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|