forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds testing for the admin page and admin role.
Initial user gets admin role. Admin users can set admin properties. The only admin property is user account creation toggle.
- Loading branch information
Showing
8 changed files
with
175 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ | |
|
||
%br | ||
|
||
%input{:type => :submit, :value => :save} | ||
%input{:type => :submit, :id => :submit, :value => :save} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'require_relative' if RUBY_VERSION[0,3] == '1.8' | ||
require_relative 'acceptance_helper' | ||
|
||
describe "admin" do | ||
include AcceptanceHelper | ||
|
||
it "creates the first user account as an admin" do | ||
u = User.first(:username => "new_user") | ||
assert u.nil? | ||
|
||
visit '/login' | ||
|
||
fill_in 'username', :with => 'new_user' | ||
fill_in 'password', :with => 'mypassword' | ||
click_button 'Log in' | ||
|
||
u = User.first(:username => "new_user") | ||
refute u.nil? | ||
assert u.admin | ||
end | ||
|
||
it "redirects first user to admin page after signup" do | ||
u = User.first(:username => "new_user") | ||
assert u.nil? | ||
|
||
visit '/login' | ||
|
||
fill_in 'username', :with => 'new_user' | ||
fill_in 'password', :with => 'mypassword' | ||
click_button 'Log in' | ||
|
||
assert_match /\/admin$/, page.current_url | ||
end | ||
|
||
it "admin page is accessible by admin users" do | ||
existing_user = Fabricate(:user, :admin => true, :username => "taken") | ||
log_in_username(existing_user) | ||
|
||
visit '/admin' | ||
|
||
assert_match /\/admin$/, page.current_url | ||
end | ||
|
||
it "admin page is not accessible by non-admin users" do | ||
existing_user = Fabricate(:user, :admin => false, :username => "taken") | ||
log_in("taken") | ||
|
||
visit '/admin' | ||
|
||
refute_match /\/admin$/, page.current_url | ||
end | ||
|
||
it "admin page allows you to turn on multiuser setting" do | ||
existing_user = Fabricate(:user, :admin => true, :username => "taken") | ||
log_in_username(existing_user) | ||
|
||
visit '/admin' | ||
|
||
check 'multiuser' | ||
click_button 'submit' | ||
|
||
assert Admin.first.multiuser == true | ||
end | ||
|
||
it "admin page allows you to turn off multiuser setting" do | ||
existing_user = Fabricate(:user, :admin => true, :username => "taken") | ||
log_in_username(existing_user) | ||
|
||
visit '/admin' | ||
|
||
uncheck :multiuser | ||
click_button :submit | ||
|
||
assert Admin.first.multiuser == false | ||
end | ||
|
||
it "admin page allows you to see the current multiuser setting" do | ||
Admin.create(:multiuser => true) | ||
|
||
existing_user = Fabricate(:user, :admin => true, :username => "taken") | ||
log_in_username(existing_user) | ||
|
||
visit '/admin' | ||
|
||
assert find('#multiuser').checked? == "checked" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# encoding: UTF-8 | ||
require_relative '../test_helper' | ||
require "webmock" | ||
include WebMock::API | ||
|
||
describe Admin do | ||
include TestHelper | ||
|
||
describe "can_create_user?" do | ||
it "must not allow user creation when there are Users and multiuser is false" do | ||
u = Fabricate(:user) | ||
refute Admin.new(:multiuser => false).can_create_user? | ||
end | ||
|
||
it "must allow user creation when there are Users and multiuser is true" do | ||
u = Fabricate(:user) | ||
assert Admin.new(:multiuser => true).can_create_user? | ||
end | ||
|
||
it "must allow user creation when there aren't Users and multiuser is false" do | ||
assert Admin.new(:multiuser => false).can_create_user? | ||
end | ||
|
||
it "must allow user creation when there aren't Users and multiuser is true" do | ||
assert Admin.new(:multiuser => true).can_create_user? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters