ports FactoryGirl usage to current schema

pull/6827/head
Jens Ulferts 12 years ago
parent a74868a682
commit 69afb09e70
  1. 56
      spec/controllers/costlog_controller_spec.rb
  2. 6
      spec/factories/cost_entry_factory.rb
  3. 10
      spec/factories/cost_rate_factory.rb
  4. 10
      spec/factories/cost_type_factory.rb
  5. 8
      spec/factories/default_hourly_rate_factory.rb
  6. 8
      spec/factories/hourly_rate_factory.rb
  7. 10
      spec/factories/labor_budget_item_factory.rb
  8. 8
      spec/factories/rate_factory.rb
  9. 14
      spec/factories/varibale_cost_object_factory.rb
  10. 30
      spec/models/cost_entry_spec.rb
  11. 6
      spec/models/default_hourly_rate_spec.rb
  12. 6
      spec/models/hourly_rate_spec.rb
  13. 14
      spec/models/labor_budget_item_spec.rb
  14. 2
      spec/models/rate_spec.rb
  15. 18
      spec/models/time_entry_spec.rb
  16. 24
      spec/models/user_deletion_spec.rb
  17. 6
      spec/models/user_spec.rb
  18. 12
      spec/models/variable_cost_object_spec.rb
  19. 8
      spec/plugin_spec_helper.rb

@ -2,27 +2,27 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb")
describe CostlogController do
include Cost::PluginSpecHelper
let (:project) { Factory.build(:project_with_trackers) }
let (:issue) { Factory.build(:issue, :project => project,
let (:project) { FactoryGirl.build(:project_with_trackers) }
let (:issue) { FactoryGirl.build(:issue, :project => project,
:author => user,
:tracker => project.trackers.first) }
let (:user) { Factory.build(:user) }
let (:user2) { Factory.build(:user) }
let (:controller) { Factory.build(:role, :permissions => [:log_costs, :edit_cost_entries]) }
let (:cost_type) { Factory.build(:cost_type) }
let (:cost_entry) { Factory.build(:cost_entry, :issue => issue,
let (:user) { FactoryGirl.build(:user) }
let (:user2) { FactoryGirl.build(:user) }
let (:controller) { FactoryGirl.build(:role, :permissions => [:log_costs, :edit_cost_entries]) }
let (:cost_type) { FactoryGirl.build(:cost_type) }
let (:cost_entry) { FactoryGirl.build(:cost_entry, :issue => issue,
:project => project,
:spent_on => Date.today,
:overridden_costs => 400,
:units => 100,
:user => user,
:comments => "") }
let(:issue_status) { Factory.create(:issue_status, :is_default => true) }
let(:issue_status) { FactoryGirl.create(:issue_status, :is_default => true) }
def grant_current_user_permissions user, permissions
member = Factory.build(:member, :project => project,
member = FactoryGirl.build(:member, :project => project,
:principal => user)
member.roles << Factory.build(:role, :permissions => permissions)
member.roles << FactoryGirl.build(:role, :permissions => permissions)
member.principal = user
member.save!
user.reload # in order to refresh the member/membership associations
@ -167,7 +167,7 @@ describe CostlogController do
before do
grant_current_user_permissions user, [:edit_cost_entries]
cost_entry.user = Factory.create(:user)
cost_entry.user = FactoryGirl.create(:user)
cost_entry.save(false)
end
@ -187,7 +187,7 @@ describe CostlogController do
before do
grant_current_user_permissions user, [:edit_own_cost_entries]
cost_entry.user = Factory.create(:user)
cost_entry.user = FactoryGirl.create(:user)
cost_entry.save(false)
end
@ -207,8 +207,8 @@ describe CostlogController do
before do
grant_current_user_permissions user, [:edit_cost_entries]
cost_entry.project = Factory.create(:project_with_trackers)
cost_entry.issue = Factory.create(:issue, :project => cost_entry.project,
cost_entry.project = FactoryGirl.create(:project_with_trackers)
cost_entry.issue = FactoryGirl.create(:issue, :project => cost_entry.project,
:tracker => cost_entry.project.trackers.first,
:author => user)
cost_entry.save!
@ -248,7 +248,7 @@ describe CostlogController do
let(:expected_cost_type) { cost_type }
let(:expected_units) { units }
let(:user2) { Factory.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:date) { "2012-04-03".to_date }
let(:overridden_costs) { 500.00 }
let(:units) { 5.0 }
@ -338,7 +338,7 @@ describe CostlogController do
let(:expected_cost_type) { nil }
before do
Factory.create(:cost_type, :default => true)
FactoryGirl.create(:cost_type, :default => true)
grant_current_user_permissions user, [:log_costs]
params["cost_entry"]["cost_type_id"] = 1
@ -354,7 +354,7 @@ describe CostlogController do
let(:expected_cost_type) { nil }
before do
Factory.create(:cost_type, :default => true)
FactoryGirl.create(:cost_type, :default => true)
grant_current_user_permissions user, [:log_costs]
params["cost_entry"].delete("cost_type_id")
@ -419,8 +419,8 @@ describe CostlogController do
describe "WHEN the user is allowed to create cost_entries
WHEN the id of an issue not included in the provided project is provided" do
let(:project2) { Factory.create(:project_with_trackers) }
let(:issue2) { Factory.create(:issue, :project => project2,
let(:project2) { FactoryGirl.create(:project_with_trackers) }
let(:issue2) { FactoryGirl.create(:issue, :project => project2,
:tracker => project2.trackers.first,
:author => user) }
let(:expected_issue) { issue2 }
@ -529,13 +529,13 @@ describe CostlogController do
overridden_costs
spent_on" do
let(:expected_issue) { Factory.create(:issue, :project => project,
let(:expected_issue) { FactoryGirl.create(:issue, :project => project,
:tracker => project.trackers.first,
:author => user) }
let(:expected_user) { Factory.create(:user) }
let(:expected_user) { FactoryGirl.create(:user) }
let(:expected_spent_on) { cost_entry.spent_on + 4.days }
let(:expected_units) { cost_entry.units + 20 }
let(:expected_cost_type) { Factory.create(:cost_type) }
let(:expected_cost_type) { FactoryGirl.create(:cost_type) }
let(:expected_overridden_costs) { cost_entry.overridden_costs + 300 }
before do
@ -580,7 +580,7 @@ describe CostlogController do
WHEN updating the user
WHEN the new user isn't a member of the project" do
let(:user2) { Factory.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:expected_user) { user2 }
before do
@ -596,8 +596,8 @@ describe CostlogController do
WHEN updating the issue
WHEN the new issue isn't an issue of the current project" do
let(:project2) { Factory.create(:project_with_trackers) }
let(:issue2) { Factory.create(:issue, :project => project2,
let(:project2) { FactoryGirl.create(:project_with_trackers) }
let(:issue2) { FactoryGirl.create(:issue, :project => project2,
:tracker => project2.trackers.first) }
let(:expected_issue) { issue2 }
@ -630,7 +630,7 @@ describe CostlogController do
WHEN updating the cost_type
WHEN the new cost_type is deleted" do
let(:expected_cost_type) { Factory.create(:cost_type, :deleted_at => Date.today) }
let(:expected_cost_type) { FactoryGirl.create(:cost_type, :deleted_at => Date.today) }
before do
grant_current_user_permissions user, [:edit_cost_entries]
@ -660,7 +660,7 @@ describe CostlogController do
WHEN updating own cost entry
WHEN updating the user" do
let(:user3) { Factory.create(:user) }
let(:user3) { FactoryGirl.create(:user) }
before do
grant_current_user_permissions user, [:edit_own_cost_entries]
@ -675,7 +675,7 @@ describe CostlogController do
WHEN updating foreign cost_entry
WHEN updating someting" do
let(:user3) { Factory.create(:user) }
let(:user3) { FactoryGirl.create(:user) }
before do
grant_current_user_permissions user3, [:edit_own_cost_entries]

@ -1,3 +1,5 @@
Factory.define :cost_entry do |ce|
ce.association :cost_type, :factory => :cost_type
FactoryGirl.define do
factory :cost_entry do
association :cost_type, :factory => :cost_type
end
end

@ -1,5 +1,7 @@
Factory.define :cost_rate do |r|
r.association :cost_type, :factory => :cost_type
r.valid_from Date.today
r.rate 50.0
FactoryGirl.define do
factory :cost_rate do
association :cost_type, :factory => :cost_type
valid_from Date.today
rate 50.0
end
end

@ -1,6 +1,8 @@
Factory.define :cost_type do |ct|
ct.sequence(:name) { |n| "ct no. #{n}" }
ct.unit "singular_unit"
ct.unit_plural "plural_unit"
FactoryGirl.define do
factory :cost_type do
sequence(:name) { |n| "ct no. #{n}" }
unit "singular_unit"
unit_plural "plural_unit"
end
end

@ -1,4 +1,6 @@
Factory.define :default_hourly_rate do |r|
r.valid_from Date.today
r.rate 50.0
FactoryGirl.define do
factory :default_hourly_rate do
valid_from Date.today
rate 50.0
end
end

@ -1,4 +1,6 @@
Factory.define :hourly_rate do |r|
r.valid_from Date.today
r.rate 50.0
FactoryGirl.define do
factory :hourly_rate do
valid_from Date.today
rate 50.0
end
end

@ -1,5 +1,7 @@
Factory.define :labor_budget_item do |i|
i.association :user, :factory => :user
i.association :cost_object, :factory => :variable_cost_object
i.hours 0.0
FactoryGirl.define do
factory :labor_budget_item do
association :user, :factory => :user
association :cost_object, :factory => :variable_cost_object
hours 0.0
end
end

@ -1,4 +1,6 @@
Factory.define :rate do |r|
r.valid_from Date.today
r.rate 50.0
FactoryGirl.define do
factory :rate do
valid_from Date.today
rate 50.0
end
end

@ -1,7 +1,9 @@
Factory.define :variable_cost_object do |m|
m.association :project, :factory => :project
m.sequence(:subject) { |n| "Cost Object No. #{n}" }
m.sequence(:description) { |n| "I am a Cost Object No. #{n}" }
m.association :author, :factory => :user
m.fixed_date Time.now
FactoryGirl.define do
factory :variable_cost_object do
association :project, :factory => :project
sequence(:subject) { |n| "Cost Object No. #{n}" }
sequence(:description) { |n| "I am a Cost Object No. #{n}" }
association :author, :factory => :user
fixed_date Time.now
end
end

@ -4,20 +4,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../plugin_spec_helper')
describe CostEntry do
include Cost::PluginSpecHelper
let(:project) { Factory.create(:project_with_trackers) }
let(:project2) { Factory.create(:project_with_trackers) }
let(:issue) { Factory.create(:issue, :project => project,
let(:project) { FactoryGirl.create(:project_with_trackers) }
let(:project2) { FactoryGirl.create(:project_with_trackers) }
let(:issue) { FactoryGirl.create(:issue, :project => project,
:tracker => project.trackers.first,
:author => user) }
let(:issue2) { Factory.create(:issue, :project => project2,
let(:issue2) { FactoryGirl.create(:issue, :project => project2,
:tracker => project2.trackers.first,
:author => user) }
let(:user) { Factory.create(:user) }
let(:user2) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:klass) { CostEntry }
let(:cost_entry) do
member
Factory.build(:cost_entry, :cost_type => cost_type,
FactoryGirl.build(:cost_entry, :cost_type => cost_type,
:project => project,
:issue => issue,
:spent_on => date,
@ -27,7 +27,7 @@ describe CostEntry do
end
let(:cost_entry2) do
Factory.build(:cost_entry, :cost_type => cost_type,
FactoryGirl.build(:cost_entry, :cost_type => cost_type,
:project => project,
:issue => issue,
:spent_on => date,
@ -37,7 +37,7 @@ describe CostEntry do
end
let(:cost_type) do
cost_type = Factory.create(:cost_type)
cost_type = FactoryGirl.create(:cost_type)
[first_rate, second_rate, third_rate].each do |rate|
rate.cost_type = cost_type
rate.save!
@ -45,16 +45,16 @@ describe CostEntry do
cost_type.reload
cost_type
end
let(:first_rate) { Factory.build(:cost_rate, :valid_from => 6.days.ago,
let(:first_rate) { FactoryGirl.build(:cost_rate, :valid_from => 6.days.ago,
:rate => 10.0) }
let(:second_rate) { Factory.build(:cost_rate, :valid_from => 4.days.ago,
let(:second_rate) { FactoryGirl.build(:cost_rate, :valid_from => 4.days.ago,
:rate => 100.0) }
let(:third_rate) { Factory.build(:cost_rate, :valid_from => 2.days.ago,
let(:third_rate) { FactoryGirl.build(:cost_rate, :valid_from => 2.days.ago,
:rate => 1000.0) }
let(:member) { Factory.create(:member, :project => project,
let(:member) { FactoryGirl.create(:member, :project => project,
:roles => [role],
:principal => user) }
let(:role) { Factory.create(:role, :permissions => []) }
let(:role) { FactoryGirl.create(:role, :permissions => []) }
let(:units) { 5.0 }
let(:date) { Date.today }
@ -112,7 +112,7 @@ describe CostEntry do
describe "instance" do
describe :costs do
let(:fourth_rate) { Factory.build(:cost_rate, :valid_from => 1.days.ago,
let(:fourth_rate) { FactoryGirl.build(:cost_rate, :valid_from => 1.days.ago,
:rate => 10000.0,
:cost_type => cost_type) }

@ -1,9 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe DefaultHourlyRate do
let(:project) { Factory.create(:project) }
let(:user) { Factory.create(:user) }
let(:rate) { Factory.build(:default_hourly_rate, :project => project,
let(:project) { FactoryGirl.create(:project) }
let(:user) { FactoryGirl.create(:user) }
let(:rate) { FactoryGirl.build(:default_hourly_rate, :project => project,
:user => user) }
describe :user do

@ -1,9 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe HourlyRate do
let(:project) { Factory.create(:project) }
let(:user) { Factory.create(:user) }
let(:rate) { Factory.build(:hourly_rate, :project => project,
let(:project) { FactoryGirl.create(:project) }
let(:user) { FactoryGirl.create(:user) }
let(:rate) { FactoryGirl.build(:hourly_rate, :project => project,
:user => user) }
describe :user do

@ -2,16 +2,16 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe LaborBudgetItem do
include Cost::PluginSpecHelper
let(:item) { Factory.build(:labor_budget_item, :cost_object => cost_object) }
let(:cost_object) { Factory.build(:variable_cost_object, :project => project) }
let(:user) { Factory.create(:user) }
let(:user2) { Factory.create(:user) }
let(:rate) { Factory.create(:hourly_rate, :user => user,
let(:item) { FactoryGirl.build(:labor_budget_item, :cost_object => cost_object) }
let(:cost_object) { FactoryGirl.build(:variable_cost_object, :project => project) }
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:rate) { FactoryGirl.create(:hourly_rate, :user => user,
:valid_from => Date.today - 4.days,
:rate => 400.0,
:project => project) }
let(:project) { Factory.create(:valid_project) }
let(:project2) { Factory.create(:valid_project) }
let(:project) { FactoryGirl.create(:valid_project) }
let(:project2) { FactoryGirl.create(:valid_project) }
describe :calculated_costs do
let(:default_costs) { "0.0".to_f }

@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Rate do
let(:rate) { Factory.build(:rate) }
let(:rate) { FactoryGirl.build(:rate) }
describe :valid? do
describe "WHEN no rate is supplied" do

@ -2,15 +2,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe TimeEntry do
include Cost::PluginSpecHelper
let(:project) { Factory.create(:project_with_trackers) }
let(:project2) { Factory.create(:project_with_trackers) }
let(:issue) { Factory.create(:issue, :project => project,
let(:project) { FactoryGirl.create(:project_with_trackers) }
let(:project2) { FactoryGirl.create(:project_with_trackers) }
let(:issue) { FactoryGirl.create(:issue, :project => project,
:tracker => project.trackers.first,
:author => user) }
let(:user) { Factory.create(:user) }
let(:user2) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:time_entry) do
Factory.build(:time_entry, :project => project,
FactoryGirl.build(:time_entry, :project => project,
:issue => issue,
:spent_on => date,
:hours => hours,
@ -21,7 +21,7 @@ describe TimeEntry do
end
let(:time_entry2) do
Factory.build(:time_entry, :project => project,
FactoryGirl.build(:time_entry, :project => project,
:issue => issue,
:spent_on => date,
:hours => hours,
@ -31,8 +31,8 @@ describe TimeEntry do
:comments => "lorem")
end
let(:date) { Date.today }
let(:activity) { Factory.build(:time_entry_activity) }
let(:rate) { Factory.build(:cost_rate) }
let(:activity) { FactoryGirl.build(:time_entry_activity) }
let(:rate) { FactoryGirl.build(:cost_rate) }
let(:hours) { 5.0 }
before(:each) do

@ -1,10 +1,10 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe User, "#destroy" do
let(:user) { Factory.create(:user) }
let(:user2) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:substitute_user) { DeletedUser.first }
let(:project) { Factory.create(:valid_project) }
let(:project) { FactoryGirl.create(:valid_project) }
before do
user
@ -92,7 +92,7 @@ describe User, "#destroy" do
describe "WHEN the user updated a cost object" do
let(:associations) { [:author] }
let(:associated_instance) { Factory.build(:variable_cost_object) }
let(:associated_instance) { FactoryGirl.build(:variable_cost_object) }
let(:associated_class) { CostObject }
it_should_behave_like "updated journalized associated object"
@ -100,14 +100,14 @@ describe User, "#destroy" do
describe "WHEN the user created a cost object" do
let(:associations) { [:author] }
let(:associated_instance) { Factory.build(:variable_cost_object) }
let(:associated_instance) { FactoryGirl.build(:variable_cost_object) }
let(:associated_class) { CostObject }
it_should_behave_like "created journalized associated object"
end
describe "WHEN the user has a labor_budget_item associated" do
let(:item) { Factory.build(:labor_budget_item, :user => user) }
let(:item) { FactoryGirl.build(:labor_budget_item, :user => user) }
before do
item.save!
@ -120,8 +120,8 @@ describe User, "#destroy" do
end
describe "WHEN the user has a cost entry" do
let(:issue) { Factory.create(:valid_issue) }
let(:entry) { Factory.build(:cost_entry, :user => user,
let(:issue) { FactoryGirl.create(:valid_issue) }
let(:entry) { FactoryGirl.build(:cost_entry, :user => user,
:project => issue.project,
:units => 100.0,
:spent_on => Date.today,
@ -129,9 +129,9 @@ describe User, "#destroy" do
:comments => "") }
before do
Factory.create(:member, :project => issue.project,
FactoryGirl.create(:member, :project => issue.project,
:user => user,
:roles => [Factory.build(:role)])
:roles => [FactoryGirl.build(:role)])
entry.save!
user.destroy
@ -143,7 +143,7 @@ describe User, "#destroy" do
end
describe "WHEN the user is assigned an hourly rate" do
let(:hourly_rate) { Factory.build(:hourly_rate, :user => user,
let(:hourly_rate) { FactoryGirl.build(:hourly_rate, :user => user,
:project => project) }
before do
@ -156,7 +156,7 @@ describe User, "#destroy" do
end
describe "WHEN the user is assigned a default hourly rate" do
let(:default_hourly_rate) { Factory.build(:default_hourly_rate, :user => user,
let(:default_hourly_rate) { FactoryGirl.build(:default_hourly_rate, :user => user,
:project => project) }
before do

@ -4,9 +4,9 @@ require File.dirname(__FILE__) + '/../plugin_spec_helper'
describe User do
include Cost::PluginSpecHelper
let(:klass) { User }
let(:user) { Factory.build(:user) }
let(:project) { Factory.build(:valid_project) }
let(:project2) { Factory.build(:valid_project) }
let(:user) { FactoryGirl.build(:user) }
let(:project) { FactoryGirl.build(:valid_project) }
let(:project2) { FactoryGirl.build(:valid_project) }
describe :allowed_to do
describe "WITH querying for a non existent permission" do

@ -1,16 +1,16 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe VariableCostObject do
let(:cost_object) { Factory.build(:variable_cost_object) }
let(:tracker) { Factory.create(:tracker_feature) }
let(:project) { Factory.create(:project_with_trackers) }
let(:user) { Factory.create(:user) }
let(:cost_object) { FactoryGirl.build(:variable_cost_object) }
let(:tracker) { FactoryGirl.create(:tracker_feature) }
let(:project) { FactoryGirl.create(:project_with_trackers) }
let(:user) { FactoryGirl.create(:user) }
describe 'recreate initial journal' do
before do
User.current = user
@variable_cost_object = Factory.create(:variable_cost_object , :project => project,
@variable_cost_object = FactoryGirl.create(:variable_cost_object , :project => project,
:author => user)
@initial_journal = @variable_cost_object.journals.first
@ -31,7 +31,7 @@ describe VariableCostObject do
end
describe "destroy" do
let(:issue) { Factory.create(:valid_issue) }
let(:issue) { FactoryGirl.create(:valid_issue) }
before do
cost_object.author = user

@ -1,11 +1,11 @@
module Cost
module PluginSpecHelper
def is_member(project, user, permissions = [])
role = Factory.create(:role, :permissions => permissions)
role = ::FactoryGirl.create(:role, :permissions => permissions)
Factory.create(:member, :project => project,
:principal => user,
:roles => [role])
::FactoryGirl.create(:member, :project => project,
:principal => user,
:roles => [role])
end
end
end

Loading…
Cancel
Save