diff --git a/examples/user_assignments.rb b/examples/user_assignments.rb index 08d1db0..9077f45 100644 --- a/examples/user_assignments.rb +++ b/examples/user_assignments.rb @@ -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) diff --git a/lib/harvest/base.rb b/lib/harvest/base.rb index 4bed570..41aebb7 100644 --- a/lib/harvest/base.rb +++ b/lib/harvest/base.rb @@ -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) diff --git a/lib/harvest/user.rb b/lib/harvest/user.rb index feeb9c6..d489a1d 100644 --- a/lib/harvest/user.rb +++ b/lib/harvest/user.rb @@ -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 diff --git a/spec/functional/account_spec.rb b/spec/functional/account_spec.rb index d232581..e55cd9c 100644 --- a/spec/functional/account_spec.rb +++ b/spec/functional/account_spec.rb @@ -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 diff --git a/spec/functional/clients_spec.rb b/spec/functional/clients_spec.rb index a6cc151..29793ef 100644 --- a/spec/functional/clients_spec.rb +++ b/spec/functional/clients_spec.rb @@ -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( diff --git a/spec/functional/project_spec.rb b/spec/functional/project_spec.rb index 42824ba..3fd0f6a 100644 --- a/spec/functional/project_spec.rb +++ b/spec/functional/project_spec.rb @@ -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( diff --git a/spec/functional/tasks_spec.rb b/spec/functional/tasks_spec.rb index dddd2df..2d80786 100644 --- a/spec/functional/tasks_spec.rb +++ b/spec/functional/tasks_spec.rb @@ -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( diff --git a/spec/functional/users_spec.rb b/spec/functional/users_spec.rb new file mode 100644 index 0000000..d4c13e7 --- /dev/null +++ b/spec/functional/users_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b90d16..6e0998c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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