Test cost entries created for varying user/project

pull/6827/head
Hagen Schink 10 years ago
parent b7699ac993
commit e59e6ef05c
  1. 103
      spec/lib/api/v3/cost_types/cost_type_representer_spec.rb

@ -20,23 +20,86 @@
require 'spec_helper'
describe ::API::V3::CostTypes::CostTypeRepresenter do
let(:project) { FactoryGirl.build(:project, id: 999) }
let(:user) { FactoryGirl.build(:user,
member_in_project: project,
created_on: 1.day.ago,
updated_on: Date.today) }
let(:work_package) { FactoryGirl.build(:work_package,
project: project) }
let(:cost_type) { FactoryGirl.build(:cost_type) }
let!(:cost_entry) { FactoryGirl.build(:cost_entry,
work_package: nil,
project: project,
units: 3,
spent_on: Date.today,
user: user,
comments: "Entry 1") }
let(:representer) { described_class.new(cost_type, work_package: work_package) }
let(:project1) { FactoryGirl.create(:project) }
let(:project2) { FactoryGirl.create(:project) }
let(:role) {
FactoryGirl.create(:role, permissions: [:view_work_package, :view_own_cost_entries])
}
let(:user1) {
FactoryGirl.create(:user,
member_in_projects: [project1, project2],
member_through_role: role,
created_on: 1.day.ago,
updated_on: Date.today)
}
let(:user2) {
FactoryGirl.create(:user,
member_in_projects: [project1, project2],
member_through_role: role,
created_on: 1.day.ago,
updated_on: Date.today)
}
let(:work_package1) { FactoryGirl.create(:work_package, project: project1) }
let(:work_package2) { FactoryGirl.create(:work_package, project: project2) }
let(:cost_type1) { FactoryGirl.create(:cost_type) }
let(:cost_type2) { FactoryGirl.create(:cost_type) }
let!(:cost_entry11) {
FactoryGirl.create(:cost_entry,
cost_type: cost_type1,
work_package: work_package1,
project: project1,
units: 3,
spent_on: Date.today,
user_id: user1.id,
comments: 'Entry 1')
}
let!(:cost_entry12) {
FactoryGirl.create(:cost_entry,
cost_type: cost_type2,
work_package: work_package1,
project: project1,
units: 3,
spent_on: Date.today,
user_id: user1.id,
comments: 'Entry 2')
}
let!(:cost_entry13) {
FactoryGirl.create(:cost_entry,
cost_type: cost_type1,
work_package: work_package1,
project: project1,
units: 3,
spent_on: Date.today,
user_id: user2.id,
comments: 'Entry 3')
}
let!(:cost_entry21) {
FactoryGirl.create(:cost_entry,
cost_type: cost_type1,
work_package: work_package2,
project: project2,
units: 3,
spent_on: Date.today,
user: user1,
comments: 'Entry 1')
}
let!(:cost_entry22) {
FactoryGirl.create(:cost_entry,
cost_type: cost_type2,
work_package: work_package2,
project: project2,
units: 3,
spent_on: Date.today,
user: user1,
comments: 'Entry 2')
}
let(:representer) do
described_class.new(cost_type1,
{ unit: 'tonne', unit_plural: 'tonnes' },
work_package: work_package1,
current_user: user1)
end
context 'generation' do
subject(:generated) { representer.to_json }
@ -52,5 +115,11 @@ describe ::API::V3::CostTypes::CostTypeRepresenter do
it { should have_json_path('unit') }
it { should have_json_path('unitPlural') }
end
describe 'units' do
it 'shows only cost entries of type cost_type1 for user1 in project project1' do
should be_json_eql(cost_entry11.units.to_json).at_path('units')
end
end
end
end

Loading…
Cancel
Save