Permalink
Browse files

Converting user and user assignment cuke

  • Loading branch information...
1 parent 52aafb5 commit 9f0afc50587df99ed3908ae80b8e42c2047bd06c @zmoazeni zmoazeni committed Jun 4, 2011
@@ -16,7 +16,7 @@
harvest.projects.create_task(project, 'Bottling Glue')
-user = Harvest::User.new(:first_name => 'Jane', :last_name => 'Doe', :email => 'jane@doe.com', :timezone => :est, :password => 'secure', :password_confirmation => 'secure')
+user = Harvest::User.new(:first_name => 'Jane', :last_name => 'Doe', :email => 'jane@doe.com', :timezone => :est, :password => 'secure')
user = harvest.users.create(user)
user_assignment = Harvest::UserAssignment.new(:user_id => user.id, :project_id => project.id)
View
@@ -133,7 +133,7 @@ def tasks
#
# harvest.users.find(100) # Returns the user with id = 100
#
- # user = Harvest::User.new(:first_name => 'Edgar', :last_name => 'Ruth', :email => 'edgar@ruth.com', :password => 'mypassword', :password_confirmation => 'mypassword', :timezone => :cst, :admin => false, :telephone => '444-4444')
+ # user = Harvest::User.new(:first_name => 'Edgar', :last_name => 'Ruth', :email => 'edgar@ruth.com', :password => 'mypassword', :timezone => :cst, :admin => false, :telephone => '444-4444')
# saved_user = harvest.users.create(user) # returns a saved version of Harvest::User
#
# user = harvest.users.find(205)
View
@@ -9,7 +9,6 @@ module Harvest
# [+last_name+] the last name for the user
# [+telephone+] the telephone for the user
# [+department] the department for the user
- # [+password|password_confirmation+] the password for the user (only used on create.)
# [+has_access_to_all_future_projects+] whether the user should be added to future projects by default
# [+hourly_rate+] what the default hourly rate for the user is
# [+admin?+] whether the user is an admin
@@ -33,7 +32,6 @@ class User < BaseModel
element :department, String
element :timezone, String
element :password, String
- element :password_confirmation, String, :tag => 'password-confirmation'
alias_method :active?, :active
alias_method :admin?, :admin
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'account information', :clean => true do
+describe 'account information' do
it 'returns the rate limit when requested' do
cassette('account') do
harvest.account.rate_limit_status.max_calls.should == 100
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'harvest clients', :clean => true do
+describe 'harvest clients' do
it 'allows adding, updating and removing clients' do
cassette("client") do
client = harvest.clients.create(Harvest::Client.new(
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'harvest projects', :clean => true do
+describe 'harvest projects' do
it 'allows adding, updating and removing projects' do
cassette('project1') do
client = harvest.clients.create(Harvest::Client.new(
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'harvest tasks', :clean => true do
+describe 'harvest tasks' do
it 'allows adding, updating and removing tasks' do
cassette('tasks') do
task = harvest.tasks.create(Harvest::Task.new(
@@ -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
View
@@ -29,11 +29,17 @@
def cassette(*args)
if ENV['NO_CACHE'] == "true"
- yield
- else
- VCR.use_cassette(*args) do
- yield
+ last = args.pop
+ if last && last.is_a?(Hash)
+ last[:record] = :all
+ args << last
+ else
+ args << {:record => :all}
end
end
+
+ VCR.use_cassette(*args) do
+ yield
+ end
end
end

0 comments on commit 9f0afc5

Please sign in to comment.