|
|
|
@ -17,30 +17,34 @@ |
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
|
|
#++ |
|
|
|
|
|
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") |
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') |
|
|
|
|
|
|
|
|
|
describe CostlogController, type: :controller do |
|
|
|
|
include Cost::PluginSpecHelper |
|
|
|
|
let (:project) { FactoryGirl.create(:project_with_types) } |
|
|
|
|
let (:work_package) { FactoryGirl.create(:work_package, project: project, |
|
|
|
|
author: user, |
|
|
|
|
type: project.types.first) } |
|
|
|
|
let (:work_package) { |
|
|
|
|
FactoryGirl.create(:work_package, project: project, |
|
|
|
|
author: user, |
|
|
|
|
type: project.types.first) |
|
|
|
|
} |
|
|
|
|
let (:user) { FactoryGirl.create(:user) } |
|
|
|
|
let (:user2) { FactoryGirl.create(: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, work_package: work_package, |
|
|
|
|
project: project, |
|
|
|
|
spent_on: Date.today, |
|
|
|
|
overridden_costs: 400, |
|
|
|
|
units: 100, |
|
|
|
|
user: user, |
|
|
|
|
comments: "") } |
|
|
|
|
let (:cost_entry) { |
|
|
|
|
FactoryGirl.build(:cost_entry, work_package: work_package, |
|
|
|
|
project: project, |
|
|
|
|
spent_on: Date.today, |
|
|
|
|
overridden_costs: 400, |
|
|
|
|
units: 100, |
|
|
|
|
user: user, |
|
|
|
|
comments: '') |
|
|
|
|
} |
|
|
|
|
let(:work_package_status) { FactoryGirl.create(:work_package_status, is_default: true) } |
|
|
|
|
|
|
|
|
|
def grant_current_user_permissions user, permissions |
|
|
|
|
def grant_current_user_permissions(user, permissions) |
|
|
|
|
member = FactoryGirl.build(:member, project: project, |
|
|
|
|
principal: user) |
|
|
|
|
principal: user) |
|
|
|
|
member.roles << FactoryGirl.build(:role, permissions: permissions) |
|
|
|
|
member.principal = user |
|
|
|
|
member.save! |
|
|
|
@ -52,7 +56,7 @@ describe CostlogController, type: :controller do |
|
|
|
|
allow(@controller.flash).to receive(:sweep) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "assigns" do |
|
|
|
|
shared_examples_for 'assigns' do |
|
|
|
|
it { expect(assigns(:cost_entry).project).to eq(expected_project) } |
|
|
|
|
it { expect(assigns(:cost_entry).work_package).to eq(expected_work_package) } |
|
|
|
|
it { expect(assigns(:cost_entry).user).to eq(expected_user) } |
|
|
|
@ -71,8 +75,8 @@ describe CostlogController, type: :controller do |
|
|
|
|
User.current = nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "GET new" do |
|
|
|
|
let(:params) { { "work_package_id" => work_package.id.to_s } } |
|
|
|
|
describe 'GET new' do |
|
|
|
|
let(:params) { { 'work_package_id' => work_package.id.to_s } } |
|
|
|
|
|
|
|
|
|
let(:expected_project) { project } |
|
|
|
|
let(:expected_work_package) { work_package } |
|
|
|
@ -82,17 +86,17 @@ describe CostlogController, type: :controller do |
|
|
|
|
let(:expected_overridden_costs) { nil } |
|
|
|
|
let(:expected_units) { nil } |
|
|
|
|
|
|
|
|
|
shared_examples_for "successful new" do |
|
|
|
|
shared_examples_for 'successful new' do |
|
|
|
|
before do |
|
|
|
|
get :new, params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it { expect(response).to be_success } |
|
|
|
|
it_should_behave_like "assigns" |
|
|
|
|
it_should_behave_like 'assigns' |
|
|
|
|
it { expect(response).to render_template('edit') } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "forbidden new" do |
|
|
|
|
shared_examples_for 'forbidden new' do |
|
|
|
|
before do |
|
|
|
|
get :new, params |
|
|
|
|
end |
|
|
|
@ -100,12 +104,12 @@ describe CostlogController, type: :controller do |
|
|
|
|
it { expect(response.response_code).to eq(403) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN user allowed to create new cost_entry" do |
|
|
|
|
describe 'WHEN user allowed to create new cost_entry' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful new" |
|
|
|
|
it_should_behave_like 'successful new' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN user allowed to create new cost_entry |
|
|
|
@ -119,34 +123,34 @@ describe CostlogController, type: :controller do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful new" |
|
|
|
|
it_should_behave_like 'successful new' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN user is allowed to create new own cost_entry" do |
|
|
|
|
describe 'WHEN user is allowed to create new own cost_entry' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_own_costs] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful new" |
|
|
|
|
it_should_behave_like 'successful new' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN user is not allowed to create new cost_entries" do |
|
|
|
|
describe 'WHEN user is not allowed to create new cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden new" |
|
|
|
|
it_should_behave_like 'forbidden new' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "GET edit" do |
|
|
|
|
let(:params) { { "id" => cost_entry.id.to_s } } |
|
|
|
|
describe 'GET edit' do |
|
|
|
|
let(:params) { { 'id' => cost_entry.id.to_s } } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
cost_entry.save(validate: false) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "successful edit" do |
|
|
|
|
shared_examples_for 'successful edit' do |
|
|
|
|
before do |
|
|
|
|
get :edit, params |
|
|
|
|
end |
|
|
|
@ -157,7 +161,7 @@ describe CostlogController, type: :controller do |
|
|
|
|
it { expect(response).to render_template('edit') } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "forbidden edit" do |
|
|
|
|
shared_examples_for 'forbidden edit' do |
|
|
|
|
before do |
|
|
|
|
get :edit, params |
|
|
|
|
end |
|
|
|
@ -165,12 +169,12 @@ describe CostlogController, type: :controller do |
|
|
|
|
it { expect(response.response_code).to eq(403) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit cost_entries" do |
|
|
|
|
describe 'WHEN the user is allowed to edit cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful edit" |
|
|
|
|
it_should_behave_like 'successful edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit cost_entries |
|
|
|
@ -182,15 +186,15 @@ describe CostlogController, type: :controller do |
|
|
|
|
cost_entry.save(validate: false) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful edit" |
|
|
|
|
it_should_behave_like 'successful edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit own cost_entries" do |
|
|
|
|
describe 'WHEN the user is allowed to edit own cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_own_cost_entries] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful edit" |
|
|
|
|
it_should_behave_like 'successful edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit own cost_entries |
|
|
|
@ -202,15 +206,15 @@ describe CostlogController, type: :controller do |
|
|
|
|
cost_entry.save(validate: false) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden edit" |
|
|
|
|
it_should_behave_like 'forbidden edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is not allowed to edit cost_entries" do |
|
|
|
|
describe 'WHEN the user is not allowed to edit cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden edit" |
|
|
|
|
it_should_behave_like 'forbidden edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit cost_entries |
|
|
|
@ -220,12 +224,12 @@ describe CostlogController, type: :controller do |
|
|
|
|
|
|
|
|
|
cost_entry.project = FactoryGirl.create(:project_with_types) |
|
|
|
|
cost_entry.work_package = FactoryGirl.create(:work_package, project: cost_entry.project, |
|
|
|
|
type: cost_entry.project.types.first, |
|
|
|
|
author: user) |
|
|
|
|
type: cost_entry.project.types.first, |
|
|
|
|
author: user) |
|
|
|
|
cost_entry.save! |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden edit" |
|
|
|
|
it_should_behave_like 'forbidden edit' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to edit cost_entries |
|
|
|
@ -233,7 +237,7 @@ describe CostlogController, type: :controller do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["id"] = (cost_entry.id + 1).to_s |
|
|
|
|
params['id'] = (cost_entry.id + 1).to_s |
|
|
|
|
|
|
|
|
|
get :edit, params |
|
|
|
|
end |
|
|
|
@ -242,15 +246,17 @@ describe CostlogController, type: :controller do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "POST create" do |
|
|
|
|
let (:params) { { "project_id" => project.id.to_s, |
|
|
|
|
"cost_entry" => { "user_id" => user.id.to_s, |
|
|
|
|
"work_package_id" => (work_package.present? ? work_package.id.to_s : "") , |
|
|
|
|
"units" => units.to_s, |
|
|
|
|
"cost_type_id" => (cost_type.present? ? cost_type.id.to_s : "" ), |
|
|
|
|
"comments" => "lorem", |
|
|
|
|
"spent_on" => date.to_s, |
|
|
|
|
"overridden_costs" => overridden_costs.to_s } } } |
|
|
|
|
describe 'POST create' do |
|
|
|
|
let (:params) { |
|
|
|
|
{ 'project_id' => project.id.to_s, |
|
|
|
|
'cost_entry' => { 'user_id' => user.id.to_s, |
|
|
|
|
'work_package_id' => (work_package.present? ? work_package.id.to_s : ''), |
|
|
|
|
'units' => units.to_s, |
|
|
|
|
'cost_type_id' => (cost_type.present? ? cost_type.id.to_s : ''), |
|
|
|
|
'comments' => 'lorem', |
|
|
|
|
'spent_on' => date.to_s, |
|
|
|
|
'overridden_costs' => overridden_costs.to_s } } |
|
|
|
|
} |
|
|
|
|
let(:expected_project) { project } |
|
|
|
|
let(:expected_work_package) { work_package } |
|
|
|
|
let(:expected_user) { user } |
|
|
|
@ -260,7 +266,7 @@ describe CostlogController, type: :controller do |
|
|
|
|
let(:expected_units) { units } |
|
|
|
|
|
|
|
|
|
let(:user2) { FactoryGirl.create(:user) } |
|
|
|
|
let(:date) { "2012-04-03".to_date } |
|
|
|
|
let(:date) { '2012-04-03'.to_date } |
|
|
|
|
let(:overridden_costs) { 500.00 } |
|
|
|
|
let(:units) { 5.0 } |
|
|
|
|
|
|
|
|
@ -268,30 +274,29 @@ describe CostlogController, type: :controller do |
|
|
|
|
cost_type.save! if cost_type.present? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "successful create" do |
|
|
|
|
shared_examples_for 'successful create' do |
|
|
|
|
before do |
|
|
|
|
post :create, params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# is this really usefull, shouldn't it redirect to the creating work_package by default? |
|
|
|
|
it { expect(response).to redirect_to(controller: "costlog", action: "index", project_id: project) } |
|
|
|
|
it { expect(response).to redirect_to(controller: 'costlog', action: 'index', project_id: project) } |
|
|
|
|
it { expect(assigns(:cost_entry)).not_to be_new_record } |
|
|
|
|
it_should_behave_like "assigns" |
|
|
|
|
it_should_behave_like 'assigns' |
|
|
|
|
it { expect(flash[:notice]).to eql I18n.t(:notice_successful_create) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shared_examples_for "invalid create" do |
|
|
|
|
shared_examples_for 'invalid create' do |
|
|
|
|
before do |
|
|
|
|
post :create, params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it { expect(response).to be_success } |
|
|
|
|
it_should_behave_like "assigns" |
|
|
|
|
it_should_behave_like 'assigns' |
|
|
|
|
it { expect(flash[:notice]).to be_nil } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "forbidden create" do |
|
|
|
|
shared_examples_for 'forbidden create' do |
|
|
|
|
before do |
|
|
|
|
post :create, params |
|
|
|
|
end |
|
|
|
@ -299,20 +304,20 @@ describe CostlogController, type: :controller do |
|
|
|
|
it { expect(response.response_code).to eq(403) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries" do |
|
|
|
|
describe 'WHEN the user is allowed to create cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful create" |
|
|
|
|
it_should_behave_like 'successful create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create own cost_entries" do |
|
|
|
|
describe 'WHEN the user is allowed to create own cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_own_costs] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful create" |
|
|
|
|
it_should_behave_like 'successful create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
@ -322,174 +327,166 @@ describe CostlogController, type: :controller do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"].delete("spent_on") |
|
|
|
|
params['cost_entry'].delete('spent_on') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful create" |
|
|
|
|
it_should_behave_like 'successful create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN a non existing cost_type_id is specified |
|
|
|
|
WHEN no default cost_type is defined" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
params["cost_entry"]["cost_type_id"] = (cost_type.id + 1).to_s |
|
|
|
|
params['cost_entry']['cost_type_id'] = (cost_type.id + 1).to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN a non existing cost_type_id is specified |
|
|
|
|
WHEN a default cost_type is defined" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
FactoryGirl.create(:cost_type, default: true) |
|
|
|
|
|
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
params["cost_entry"]["cost_type_id"] = 1 |
|
|
|
|
params['cost_entry']['cost_type_id'] = 1 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN no cost_type is specified |
|
|
|
|
WHEN a default cost_type is defined" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
FactoryGirl.create(:cost_type, default: true) |
|
|
|
|
|
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
params["cost_entry"].delete("cost_type_id") |
|
|
|
|
params['cost_entry'].delete('cost_type_id') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN no cost_type is specified |
|
|
|
|
WHEN no default cost_type is defined" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
params["cost_entry"].delete("cost_type_id") |
|
|
|
|
params['cost_entry'].delete('cost_type_id') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN the cost_type id provided belongs to an inactive cost_type" do |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
cost_type.deleted_at = Date.today |
|
|
|
|
cost_type.save! |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN the user is allowed to log cost for someone else and is doing so |
|
|
|
|
WHEN the other user is a member of the project" do |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [] |
|
|
|
|
grant_current_user_permissions user2, [:log_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["user_id"] = user.id.to_s |
|
|
|
|
params['cost_entry']['user_id'] = user.id.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful create" |
|
|
|
|
it_should_behave_like 'successful create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN the user is allowed to log cost for someone else and is doing so |
|
|
|
|
WHEN the other user isn't a member of the project" do |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user2, [:log_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["user_id"] = user.id.to_s |
|
|
|
|
params['cost_entry']['user_id'] = user.id.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN the id of an work_package not included in the provided project is provided" do |
|
|
|
|
|
|
|
|
|
let(:project2) { FactoryGirl.create(:project_with_types) } |
|
|
|
|
let(:work_package2) { FactoryGirl.create(:work_package, project: project2, |
|
|
|
|
type: project2.types.first, |
|
|
|
|
author: user) } |
|
|
|
|
let(:work_package2) { |
|
|
|
|
FactoryGirl.create(:work_package, project: project2, |
|
|
|
|
type: project2.types.first, |
|
|
|
|
author: user) |
|
|
|
|
} |
|
|
|
|
let(:expected_work_package) { work_package2 } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["work_package_id"] = work_package2.id |
|
|
|
|
params['cost_entry']['work_package_id'] = work_package2.id |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create cost_entries |
|
|
|
|
WHEN no work_package_id is provided" do |
|
|
|
|
|
|
|
|
|
let(:expected_work_package) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:log_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"].delete("work_package_id") |
|
|
|
|
params['cost_entry'].delete('work_package_id') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid create" |
|
|
|
|
it_should_behave_like 'invalid create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to create own cost_entries |
|
|
|
|
WHEN the user is trying to log costs for somebody else" do |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user2, [:log_own_costs] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["user_id"] = user.id |
|
|
|
|
params['cost_entry']['user_id'] = user.id |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden create" |
|
|
|
|
it_should_behave_like 'forbidden create' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is not allowed to create cost_entries" do |
|
|
|
|
|
|
|
|
|
describe 'WHEN the user is not allowed to create cost_entries' do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden create" |
|
|
|
|
it_should_behave_like 'forbidden create' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "PUT update" do |
|
|
|
|
let(:params) { { "id" => cost_entry.id.to_s, |
|
|
|
|
"cost_entry" => { "comments" => "lorem", |
|
|
|
|
"work_package_id" => cost_entry.work_package.id.to_s, |
|
|
|
|
"units" => cost_entry.units.to_s, |
|
|
|
|
"spent_on" => cost_entry.spent_on.to_s, |
|
|
|
|
"user_id" => cost_entry.user.id.to_s, |
|
|
|
|
"cost_type_id" => cost_entry.cost_type.id.to_s } } } |
|
|
|
|
describe 'PUT update' do |
|
|
|
|
let(:params) { |
|
|
|
|
{ 'id' => cost_entry.id.to_s, |
|
|
|
|
'cost_entry' => { 'comments' => 'lorem', |
|
|
|
|
'work_package_id' => cost_entry.work_package.id.to_s, |
|
|
|
|
'units' => cost_entry.units.to_s, |
|
|
|
|
'spent_on' => cost_entry.spent_on.to_s, |
|
|
|
|
'user_id' => cost_entry.user.id.to_s, |
|
|
|
|
'cost_type_id' => cost_entry.cost_type.id.to_s } } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
cost_entry.save(validate: false) |
|
|
|
@ -503,27 +500,27 @@ describe CostlogController, type: :controller do |
|
|
|
|
let(:expected_overridden_costs) { cost_entry.overridden_costs } |
|
|
|
|
let(:expected_spent_on) { cost_entry.spent_on } |
|
|
|
|
|
|
|
|
|
shared_examples_for "successful update" do |
|
|
|
|
shared_examples_for 'successful update' do |
|
|
|
|
before do |
|
|
|
|
put :update, params |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it { expect(response).to redirect_to(controller: "costlog", action: "index", project_id: project) } |
|
|
|
|
it { expect(response).to redirect_to(controller: 'costlog', action: 'index', project_id: project) } |
|
|
|
|
it { expect(assigns(:cost_entry)).to eq(cost_entry) } |
|
|
|
|
it_should_behave_like "assigns" |
|
|
|
|
it_should_behave_like 'assigns' |
|
|
|
|
it { expect(assigns(:cost_entry)).not_to be_changed } |
|
|
|
|
it { expect(flash[:notice]).to eql I18n.t(:notice_successful_update) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "invalid update" do |
|
|
|
|
shared_examples_for 'invalid update' do |
|
|
|
|
before { put :update, params } |
|
|
|
|
|
|
|
|
|
it_should_behave_like "assigns" |
|
|
|
|
it_should_behave_like 'assigns' |
|
|
|
|
it { expect(response).to be_success } |
|
|
|
|
it { expect(flash[:notice]).to be_nil } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples_for "forbidden update" do |
|
|
|
|
shared_examples_for 'forbidden update' do |
|
|
|
|
before do |
|
|
|
|
put :update, params |
|
|
|
|
end |
|
|
|
@ -539,10 +536,11 @@ describe CostlogController, type: :controller do |
|
|
|
|
cost_type |
|
|
|
|
overridden_costs |
|
|
|
|
spent_on" do |
|
|
|
|
|
|
|
|
|
let(:expected_work_package) { FactoryGirl.create(:work_package, project: project, |
|
|
|
|
type: project.types.first, |
|
|
|
|
author: user) } |
|
|
|
|
let(:expected_work_package) { |
|
|
|
|
FactoryGirl.create(:work_package, project: project, |
|
|
|
|
type: project.types.first, |
|
|
|
|
author: user) |
|
|
|
|
} |
|
|
|
|
let(:expected_user) { FactoryGirl.create(:user) } |
|
|
|
|
let(:expected_spent_on) { cost_entry.spent_on + 4.days } |
|
|
|
|
let(:expected_units) { cost_entry.units + 20 } |
|
|
|
@ -553,25 +551,24 @@ describe CostlogController, type: :controller do |
|
|
|
|
grant_current_user_permissions expected_user, [] |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["work_package_id"] = expected_work_package.id.to_s |
|
|
|
|
params["cost_entry"]["user_id"] = expected_user.id.to_s |
|
|
|
|
params["cost_entry"]["spent_on"] = expected_spent_on.to_s |
|
|
|
|
params["cost_entry"]["units"] = expected_units.to_s |
|
|
|
|
params["cost_entry"]["cost_type_id"] = expected_cost_type.id.to_s |
|
|
|
|
params["cost_entry"]["overridden_costs"] = expected_overridden_costs.to_s |
|
|
|
|
params['cost_entry']['work_package_id'] = expected_work_package.id.to_s |
|
|
|
|
params['cost_entry']['user_id'] = expected_user.id.to_s |
|
|
|
|
params['cost_entry']['spent_on'] = expected_spent_on.to_s |
|
|
|
|
params['cost_entry']['units'] = expected_units.to_s |
|
|
|
|
params['cost_entry']['cost_type_id'] = expected_cost_type.id.to_s |
|
|
|
|
params['cost_entry']['overridden_costs'] = expected_overridden_costs.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful update" |
|
|
|
|
it_should_behave_like 'successful update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating nothing" do |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful update" |
|
|
|
|
it_should_behave_like 'successful update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed ot update own cost_entries |
|
|
|
@ -581,121 +578,114 @@ describe CostlogController, type: :controller do |
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_own_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["units"] = expected_units.to_s |
|
|
|
|
params['cost_entry']['units'] = expected_units.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "successful update" |
|
|
|
|
it_should_behave_like 'successful update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating the user |
|
|
|
|
WHEN the new user isn't a member of the project" do |
|
|
|
|
|
|
|
|
|
let(:user2) { FactoryGirl.create(:user) } |
|
|
|
|
let(:expected_user) { user2 } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["user_id"] = user2.id.to_s |
|
|
|
|
params['cost_entry']['user_id'] = user2.id.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid update" |
|
|
|
|
it_should_behave_like 'invalid update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating the work_package |
|
|
|
|
WHEN the new work_package isn't an work_package of the current project" do |
|
|
|
|
|
|
|
|
|
let(:project2) { FactoryGirl.create(:project_with_types) } |
|
|
|
|
let(:work_package2) { FactoryGirl.create(:work_package, project: project2, |
|
|
|
|
type: project2.types.first) } |
|
|
|
|
let(:work_package2) { |
|
|
|
|
FactoryGirl.create(:work_package, project: project2, |
|
|
|
|
type: project2.types.first) |
|
|
|
|
} |
|
|
|
|
let(:expected_work_package) { work_package2 } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["work_package_id"] = work_package2.id.to_s |
|
|
|
|
params['cost_entry']['work_package_id'] = work_package2.id.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid update" |
|
|
|
|
it_should_behave_like 'invalid update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating the work_package |
|
|
|
|
WHEN the new work_package_id isn't existing" do |
|
|
|
|
|
|
|
|
|
let(:expected_work_package) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["work_package_id"] = (work_package.id + 1).to_s |
|
|
|
|
params['cost_entry']['work_package_id'] = (work_package.id + 1).to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid update" |
|
|
|
|
it_should_behave_like 'invalid update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating the cost_type |
|
|
|
|
WHEN the new cost_type is deleted" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { FactoryGirl.create(:cost_type, deleted_at: Date.today) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["cost_type_id"] = expected_cost_type.id.to_s |
|
|
|
|
params['cost_entry']['cost_type_id'] = expected_cost_type.id.to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid update" |
|
|
|
|
it_should_behave_like 'invalid update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update cost_entries |
|
|
|
|
WHEN updating the cost_type |
|
|
|
|
WHEN the new cost_type doesn't exist" do |
|
|
|
|
|
|
|
|
|
let(:expected_cost_type) { nil } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["cost_type_id"] = "1" |
|
|
|
|
params['cost_entry']['cost_type_id'] = '1' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "invalid update" |
|
|
|
|
it_should_behave_like 'invalid update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update own cost_entries and not all |
|
|
|
|
WHEN updating own cost entry |
|
|
|
|
WHEN updating the user" do |
|
|
|
|
|
|
|
|
|
let(:user3) { FactoryGirl.create(:user) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user, [:edit_own_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["user_id"] = user3.id |
|
|
|
|
params['cost_entry']['user_id'] = user3.id |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden update" |
|
|
|
|
it_should_behave_like 'forbidden update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "WHEN the user is allowed to update own cost_entries and not all |
|
|
|
|
WHEN updating foreign cost_entry |
|
|
|
|
WHEN updating someting" do |
|
|
|
|
|
|
|
|
|
let(:user3) { FactoryGirl.create(:user) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
grant_current_user_permissions user3, [:edit_own_cost_entries] |
|
|
|
|
|
|
|
|
|
params["cost_entry"]["units"] = (cost_entry.units + 20).to_s |
|
|
|
|
params['cost_entry']['units'] = (cost_entry.units + 20).to_s |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_should_behave_like "forbidden update" |
|
|
|
|
it_should_behave_like 'forbidden update' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|