forked from zmoazeni/harvested
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converting user and user assignment cuke
- Loading branch information
Showing
9 changed files
with
119 additions
and
12 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
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
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,103 @@ | ||
require 'spec_helper' | ||
|
||
describe 'harvest users' do | ||
it "allows adding, updating, and removing users" do | ||
cassette("users") do | ||
user = harvest.users.create(Harvest::User.new( | ||
"first_name" => "Edgar", | ||
"last_name" => "Ruth", | ||
"email" => "edgar@ruth.com", | ||
"password" => "mypassword", | ||
"timezone" => "cst", | ||
"admin" => "false", | ||
"telephone" => "444-4444" | ||
)) | ||
user.id.should_not be_blank | ||
|
||
user.first_name = "Joey" | ||
user = harvest.users.update(user) | ||
user.first_name.should == "Joey" | ||
|
||
id = harvest.users.delete(user) | ||
harvest.users.all.map(&:id).should_not include(id) | ||
end | ||
end | ||
|
||
it "allows activating and deactivating users" do | ||
cassette("users2") do | ||
user = harvest.users.create(Harvest::User.new( | ||
"first_name" => "John", | ||
"last_name" => "Ruth", | ||
"email" => "john@ruth.com", | ||
"password" => "mypassword", | ||
"timezone" => "cst", | ||
"admin" => "false", | ||
"telephone" => "444-4444" | ||
)) | ||
user.should be_active | ||
|
||
user = harvest.users.deactivate(user) | ||
user.should_not be_active | ||
|
||
user = harvest.users.activate(user) | ||
user.should be_active | ||
end | ||
end | ||
|
||
it "allows password resets" do | ||
cassette("users3") do | ||
user = harvest.users.create(Harvest::User.new( | ||
"first_name" => "Timmy", | ||
"last_name" => "Ruth", | ||
"email" => "timmy@ruth.com", | ||
"password" => "mypassword", | ||
"timezone" => "cst", | ||
"admin" => "false", | ||
"telephone" => "444-4444" | ||
)) | ||
user.should be_active | ||
|
||
harvest.users.reset_password(user) # nothing else to assert | ||
end | ||
end | ||
|
||
context "assignments" do | ||
it "allows adding, updating, and removing users from projects" do | ||
cassette('users4') do | ||
client = harvest.clients.create(Harvest::Client.new( | ||
"name" => "Joe's Steam Cleaning w/Users", | ||
"details" => "Building API Widgets across the country") | ||
) | ||
|
||
project = harvest.projects.create(Harvest::Project.new( | ||
"name" => "Test Project w/User", | ||
"active" => true, | ||
"notes" => "project to test the api", | ||
"client_id" => client.id | ||
)) | ||
|
||
user = harvest.users.create(Harvest::User.new( | ||
"first_name" => "Sally", | ||
"last_name" => "Ruth", | ||
"email" => "sally@ruth.com", | ||
"password" => "mypassword", | ||
"timezone" => "cst", | ||
"admin" => "false", | ||
"telephone" => "444-4444" | ||
)) | ||
|
||
|
||
assignment = harvest.user_assignments.create(Harvest::UserAssignment.new("project" => project, "user" => user)) | ||
|
||
assignment.hourly_rate = 100 | ||
assignment = harvest.user_assignments.update(assignment) | ||
assignment.hourly_rate.should == 100.0 | ||
|
||
harvest.user_assignments.delete(assignment) | ||
all_assignments = harvest.user_assignments.all(project) | ||
all_assignments.size.should == 2 | ||
all_assignments.select {|a| a.active? }.size.should == 1 # includes the default user | ||
end | ||
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