Merge pull request #97 from finnlabs/feature/rspec-299

RSpec 2.99 Upgrade
pull/6827/head
ulferts 10 years ago
commit 510217726b
  1. 66
      spec/controllers/costlog_controller_spec.rb
  2. 6
      spec/controllers/work_packages_bulk_controller_spec.rb
  3. 6
      spec/helpers/cost_objects_helper_spec.rb
  4. 82
      spec/models/cost_entry_spec.rb
  5. 8
      spec/models/cost_type_spec.rb
  6. 6
      spec/models/default_hourly_rate_spec.rb
  7. 6
      spec/models/hourly_rate_spec.rb
  8. 42
      spec/models/labor_budget_item_spec.rb
  9. 52
      spec/models/permitted_params_spec.rb
  10. 24
      spec/models/rate_spec.rb
  11. 82
      spec/models/time_entry_spec.rb
  12. 42
      spec/models/user_deletion_spec.rb
  13. 28
      spec/models/user_spec.rb
  14. 16
      spec/models/variable_cost_object_spec.rb
  15. 50
      spec/models/work_package/ask_before_destruction_spec.rb
  16. 14
      spec/models/work_package_spec.rb
  17. 20
      spec/routing/cost_objects_routing_spec.rb
  18. 16
      spec/routing/cost_types_routing_spec.rb
  19. 16
      spec/routing/costlog_routing_spec.rb
  20. 12
      spec/routing/hourly_rates_routing_spec.rb

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb")
describe CostlogController do
describe CostlogController, :type => :controller do
include Cost::PluginSpecHelper
let (:project) { FactoryGirl.create(:project_with_types) }
let (:work_package) { FactoryGirl.create(:work_package, :project => project,
@ -45,26 +45,26 @@ describe CostlogController do
member.principal = user
member.save!
user.reload # in order to refresh the member/membership associations
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
end
def disable_flash_sweep
@controller.instance_eval{flash.stub!(:sweep)}
@controller.instance_eval{allow(flash).to receive(:sweep)}
end
shared_examples_for "assigns" do
it { assigns(:cost_entry).project.should == expected_project }
it { assigns(:cost_entry).work_package.should == expected_work_package }
it { assigns(:cost_entry).user.should == expected_user }
it { assigns(:cost_entry).spent_on.should == expected_spent_on }
it { assigns(:cost_entry).cost_type.should == expected_cost_type }
it { assigns(:cost_entry).units.should == expected_units }
it { assigns(:cost_entry).overridden_costs.should == expected_overridden_costs }
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) }
it { expect(assigns(:cost_entry).spent_on).to eq(expected_spent_on) }
it { expect(assigns(:cost_entry).cost_type).to eq(expected_cost_type) }
it { expect(assigns(:cost_entry).units).to eq(expected_units) }
it { expect(assigns(:cost_entry).overridden_costs).to eq(expected_overridden_costs) }
end
before do
disable_flash_sweep
@controller.stub!(:check_if_login_required)
allow(@controller).to receive(:check_if_login_required)
end
after do
@ -87,9 +87,9 @@ describe CostlogController do
get :new, params
end
it { response.should be_success }
it { expect(response).to be_success }
it_should_behave_like "assigns"
it { response.should render_template('edit') }
it { expect(response).to render_template('edit') }
end
shared_examples_for "forbidden new" do
@ -97,7 +97,7 @@ describe CostlogController do
get :new, params
end
it { response.response_code.should == 403 }
it { expect(response.response_code).to eq(403) }
end
describe "WHEN user allowed to create new cost_entry" do
@ -151,10 +151,10 @@ describe CostlogController do
get :edit, params
end
it { response.should be_success }
it { assigns(:cost_entry).should == cost_entry }
it { assigns(:cost_entry).should_not be_changed }
it { response.should render_template('edit') }
it { expect(response).to be_success }
it { expect(assigns(:cost_entry)).to eq(cost_entry) }
it { expect(assigns(:cost_entry)).not_to be_changed }
it { expect(response).to render_template('edit') }
end
shared_examples_for "forbidden edit" do
@ -162,7 +162,7 @@ describe CostlogController do
get :edit, params
end
it { response.response_code.should == 403 }
it { expect(response.response_code).to eq(403) }
end
describe "WHEN the user is allowed to edit cost_entries" do
@ -238,7 +238,7 @@ describe CostlogController do
get :edit, params
end
it { response.response_code.should == 404 }
it { expect(response.response_code).to eq(404) }
end
end
@ -274,10 +274,10 @@ describe CostlogController do
end
# is this really usefull, shouldn't it redirect to the creating work_package by default?
it { response.should redirect_to(:controller => "costlog", :action => "index", :project_id => project) }
it { assigns(:cost_entry).should_not be_new_record }
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 { flash[:notice].should eql I18n.t(:notice_successful_create) }
it { expect(flash[:notice]).to eql I18n.t(:notice_successful_create) }
end
@ -286,9 +286,9 @@ describe CostlogController do
post :create, params
end
it { response.should be_success }
it { expect(response).to be_success }
it_should_behave_like "assigns"
it { flash[:notice].should be_nil }
it { expect(flash[:notice]).to be_nil }
end
shared_examples_for "forbidden create" do
@ -296,7 +296,7 @@ describe CostlogController do
post :create, params
end
it { response.response_code.should == 403 }
it { expect(response.response_code).to eq(403) }
end
describe "WHEN the user is allowed to create cost_entries" do
@ -508,19 +508,19 @@ describe CostlogController do
put :update, params
end
it { response.should redirect_to(:controller => "costlog", :action => "index", :project_id => project) }
it { assigns(:cost_entry).should == cost_entry }
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 { assigns(:cost_entry).should_not be_changed }
it { flash[:notice].should eql I18n.t(:notice_successful_update) }
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
before { put :update, params }
it_should_behave_like "assigns"
it { response.should be_success }
it { flash[:notice].should be_nil }
it { expect(response).to be_success }
it { expect(flash[:notice]).to be_nil }
end
shared_examples_for "forbidden update" do
@ -528,7 +528,7 @@ describe CostlogController do
put :update, params
end
it { response.response_code.should == 403 }
it { expect(response.response_code).to eq(403) }
end
describe "WHEN the user is allowed to update cost_entries

@ -19,7 +19,7 @@
require 'spec_helper'
describe WorkPackages::BulkController do
describe WorkPackages::BulkController, :type => :controller do
let(:project) { FactoryGirl.create(:project_with_types) }
let(:controller_role) { FactoryGirl.build(:role, :permissions => [:view_work_packages, :edit_work_packages]) }
let(:user) { FactoryGirl.create :user, member_in_project: project, member_through_role: controller_role }
@ -27,7 +27,7 @@ describe WorkPackages::BulkController do
let(:work_package) { FactoryGirl.create(:work_package, project: project) }
before do
User.stub(:current).and_return user
allow(User).to receive(:current).and_return user
end
describe :update do
@ -36,7 +36,7 @@ describe WorkPackages::BulkController do
subject { work_package.reload.cost_object.try :id }
it { should == cost_object.id }
it { is_expected.to eq(cost_object.id) }
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe CostObjectsHelper do
describe CostObjectsHelper, :type => :helper do
let(:project) { FactoryGirl.build(:project) }
let(:cost_object) { FactoryGirl.build(:cost_object, :project => project) }
@ -40,7 +40,7 @@ describe CostObjectsHelper do
cost_object.description
].join(I18n.t(:general_csv_separator))
cost_objects_to_csv([cost_object]).include?(expected).should be_true
expect(cost_objects_to_csv([cost_object]).include?(expected)).to be_truthy
end
it "should start with a header explaining the fields" do
@ -57,7 +57,7 @@ describe CostObjectsHelper do
CostObject.human_attribute_name(:description)
].join(I18n.t(:general_csv_separator))
cost_objects_to_csv([cost_object]).start_with?(expected).should be_true
expect(cost_objects_to_csv([cost_object]).start_with?(expected)).to be_truthy
end
end
end

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe CostEntry do
describe CostEntry, :type => :model do
include Cost::PluginSpecHelper
let(:project) { FactoryGirl.create(:project_with_types) }
@ -87,7 +87,7 @@ describe CostEntry do
cost_entry.save!
end
it { CostEntry.visible(user2, project).all.should =~ [cost_entry] }
it { expect(CostEntry.visible(user2, project).all).to match_array([cost_entry]) }
end
describe "WHEN not having the view_cost_entries permission
@ -99,7 +99,7 @@ describe CostEntry do
cost_entry.save!
end
it { CostEntry.visible(user2, project).all.should =~ [] }
it { expect(CostEntry.visible(user2, project).all).to match_array([]) }
end
describe "WHEN having the view_own_cost_entries permission
@ -111,7 +111,7 @@ describe CostEntry do
cost_entry.save!
end
it { CostEntry.visible(user2, project).all.should =~ [] }
it { expect(CostEntry.visible(user2, project).all).to match_array([]) }
end
describe "WHEN having the view_own_cost_entries permission
@ -123,7 +123,7 @@ describe CostEntry do
cost_entry2.save!
end
it { CostEntry.visible(cost_entry2.user, project).all.should =~ [cost_entry2] }
it { expect(CostEntry.visible(cost_entry2.user, project).all).to match_array([cost_entry2]) }
end
end
end
@ -143,7 +143,7 @@ describe CostEntry do
(0..5).each do |units|
cost_entry.units = units
cost_entry.save!
cost_entry.costs.should == first_rate.rate * units
expect(cost_entry.costs).to eq(first_rate.rate * units)
end
end
end
@ -155,7 +155,7 @@ describe CostEntry do
cost_entry.reload
end
it { cost_entry.costs.should == fourth_rate.rate * cost_entry.units }
it { expect(cost_entry.costs).to eq(fourth_rate.rate * cost_entry.units) }
end
describe "WHEN a new rate is added for the future" do
@ -166,7 +166,7 @@ describe CostEntry do
cost_entry.reload
end
it { cost_entry.costs.should == third_rate.rate * cost_entry.units }
it { expect(cost_entry.costs).to eq(third_rate.rate * cost_entry.units) }
end
describe "WHEN a new rate is added in between" do
@ -177,7 +177,7 @@ describe CostEntry do
cost_entry.reload
end
it { cost_entry.costs.should == third_rate.rate * cost_entry.units }
it { expect(cost_entry.costs).to eq(third_rate.rate * cost_entry.units) }
end
describe "WHEN a rate is destroyed" do
@ -187,7 +187,7 @@ describe CostEntry do
cost_entry.reload
end
it { cost_entry.costs.should == cost_entry.units * second_rate.rate }
it { expect(cost_entry.costs).to eq(cost_entry.units * second_rate.rate) }
end
describe "WHEN a rate's valid from is updated" do
@ -197,7 +197,7 @@ describe CostEntry do
cost_entry.reload
end
it { cost_entry.costs.should == cost_entry.units * first_rate.rate }
it { expect(cost_entry.costs).to eq(cost_entry.units * first_rate.rate) }
end
describe "WHEN spent on is changed" do
@ -210,7 +210,7 @@ describe CostEntry do
(5.days.ago.to_date..Date.today).each do |time|
cost_entry.spent_on = time
cost_entry.save!
cost_entry.costs.should == cost_entry.units * CostRate.first(:conditions => ["cost_type_id = ? AND valid_from <= ?", cost_entry.cost_type.id, cost_entry.spent_on], :order => "valid_from DESC").rate
expect(cost_entry.costs).to eq(cost_entry.units * CostRate.first(:conditions => ["cost_type_id = ? AND valid_from <= ?", cost_entry.cost_type.id, cost_entry.spent_on], :order => "valid_from DESC").rate)
end
end
end
@ -224,7 +224,7 @@ describe CostEntry do
cost_entry.overridden_costs = value
end
it { cost_entry.overridden_costs.should == value }
it { expect(cost_entry.overridden_costs).to eq(value) }
end
end
@ -236,7 +236,7 @@ describe CostEntry do
cost_entry.overridden_costs = value
end
it { cost_entry.real_costs.should == value }
it { expect(cost_entry.real_costs).to eq(value) }
end
end
@ -245,12 +245,12 @@ describe CostEntry do
cost_entry.save!
end
it{ cost_entry.should be_valid }
it{ expect(cost_entry).to be_valid }
describe "WHEN no cost_type is provided" do
before { cost_entry.cost_type = nil }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN no project is provided" do
@ -261,44 +261,44 @@ describe CostEntry do
cost_entry.work_package = nil
end
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN no work_package is provided" do
before { cost_entry.work_package = nil }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN the work_package is not in the project" do
before { cost_entry.work_package = work_package2 }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN no units are provided" do
before { cost_entry.units = nil }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN no spent_on is provided" do
before { cost_entry.spent_on = nil }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN no user is provided" do
before { cost_entry.user = nil }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN the provided user is no member of the project
WHEN the user is unchanged" do
before { member.destroy }
it { cost_entry.should be_valid }
it { expect(cost_entry).to be_valid }
end
describe "WHEN the provided user is no member of the project
@ -308,13 +308,13 @@ describe CostEntry do
member.destroy
end
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
describe "WHEN the cost_type is deleted" do
before { cost_type.deleted_at = Date.new }
it { cost_entry.should_not be_valid }
it { expect(cost_entry).not_to be_valid }
end
end
@ -325,11 +325,11 @@ describe CostEntry do
user.destroy
end
it { cost_entry.reload.user.should == DeletedUser.first }
it { expect(cost_entry.reload.user).to eq(DeletedUser.first) }
end
describe "WHEN an existing user is provided" do
it { cost_entry.user.should == user }
it { expect(cost_entry.user).to eq(user) }
end
end
@ -342,7 +342,7 @@ describe CostEntry do
cost_entry
end
it { cost_entry.editable_by?(user2).should be_true }
it { expect(cost_entry.editable_by?(user2)).to be_truthy }
end
describe "WHEN the user has the edit_cost_entries permission
@ -351,7 +351,7 @@ describe CostEntry do
is_member(project, cost_entry2.user, [:edit_cost_entries])
end
it { cost_entry2.editable_by?(cost_entry2.user).should be_true }
it { expect(cost_entry2.editable_by?(cost_entry2.user)).to be_truthy }
end
describe "WHEN the user has the edit_own_cost_entries permission
@ -362,7 +362,7 @@ describe CostEntry do
cost_entry2
end
it { cost_entry2.editable_by?(cost_entry2.user).should be_true }
it { expect(cost_entry2.editable_by?(cost_entry2.user)).to be_truthy }
end
describe "WHEN the user has the edit_own_cost_entries permission
@ -373,7 +373,7 @@ describe CostEntry do
cost_entry
end
it { cost_entry.editable_by?(user2).should be_false }
it { expect(cost_entry.editable_by?(user2)).to be_falsey }
end
describe "WHEN the user has no cost permission
@ -384,7 +384,7 @@ describe CostEntry do
cost_entry2
end
it { cost_entry2.editable_by?(cost_entry2.user).should be_false }
it { expect(cost_entry2.editable_by?(cost_entry2.user)).to be_falsey }
end
end
@ -395,7 +395,7 @@ describe CostEntry do
is_member(project, user2, [:log_costs])
end
it { cost_entry.creatable_by?(user2).should be_true }
it { expect(cost_entry.creatable_by?(user2)).to be_truthy }
end
describe "WHEN the user has the log_costs permission
@ -404,7 +404,7 @@ describe CostEntry do
is_member(project, cost_entry2.user, [:log_costs])
end
it { cost_entry2.creatable_by?(cost_entry2.user).should be_true }
it { expect(cost_entry2.creatable_by?(cost_entry2.user)).to be_truthy }
end
describe "WHEN the user has the log own costs permission
@ -413,7 +413,7 @@ describe CostEntry do
is_member(project, cost_entry2.user, [:log_own_costs])
end
it { cost_entry2.creatable_by?(cost_entry2.user).should be_true }
it { expect(cost_entry2.creatable_by?(cost_entry2.user)).to be_truthy }
end
describe "WHEN the user has the log_own_costs permission
@ -422,7 +422,7 @@ describe CostEntry do
is_member(project, user2, [:log_own_costs])
end
it { cost_entry.creatable_by?(user2).should be_false }
it { expect(cost_entry.creatable_by?(user2)).to be_falsey }
end
describe "WHEN the user has no cost permission
@ -431,7 +431,7 @@ describe CostEntry do
is_member(project, cost_entry2.user, [])
end
it { cost_entry2.creatable_by?(cost_entry2.user).should be_false }
it { expect(cost_entry2.creatable_by?(cost_entry2.user)).to be_falsey }
end
end
@ -442,7 +442,7 @@ describe CostEntry do
is_member(project, user2, [:view_cost_rates])
end
it { cost_entry.costs_visible_by?(user2).should be_true }
it { expect(cost_entry.costs_visible_by?(user2)).to be_truthy }
end
describe "WHEN the user has the view_cost_rates permission in another project
@ -451,7 +451,7 @@ describe CostEntry do
is_member(project2, user2, [:view_cost_rates])
end
it { cost_entry.costs_visible_by?(user2).should be_false }
it { expect(cost_entry.costs_visible_by?(user2)).to be_falsey }
end
describe "WHEN the user lacks the view_cost_rates permission
@ -462,7 +462,7 @@ describe CostEntry do
cost_entry2.update_attribute(:overridden_costs, 1.0)
end
it { cost_entry2.costs_visible_by?(cost_entry2.user).should be_true }
it { expect(cost_entry2.costs_visible_by?(cost_entry2.user)).to be_truthy }
end
describe "WHEN the user lacks the view_cost_rates permission
@ -472,7 +472,7 @@ describe CostEntry do
is_member(project, cost_entry2.user, [])
end
it { cost_entry2.costs_visible_by?(cost_entry2.user).should be_false }
it { expect(cost_entry2.costs_visible_by?(cost_entry2.user)).to be_falsey }
end
end
end

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb")
describe CostType do
describe CostType, :type => :model do
let(:klass) { CostType }
let(:cost_type) { klass.new :name => "ct1",
:unit => "singular",
@ -40,7 +40,7 @@ describe CostType do
cost_type.save!
end
it { klass.should have(0).active }
it { expect(klass.size).to eq(0) }
end
describe "WHEN a CostType instance is not deleted" do
@ -48,8 +48,8 @@ describe CostType do
cost_type.save!
end
it { klass.should have(1).active }
it { klass.active[0].should == cost_type }
it { expect(klass.size).to eq(1) }
it { expect(klass.active[0]).to eq(cost_type) }
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe DefaultHourlyRate do
describe DefaultHourlyRate, :type => :model do
let(:project) { FactoryGirl.create(:project) }
let(:user) { FactoryGirl.create(:user) }
let(:rate) { FactoryGirl.build(:default_hourly_rate, :project => project,
@ -32,7 +32,7 @@ describe DefaultHourlyRate do
rate.save!
end
it { rate.user.should == user }
it { expect(rate.user).to eq(user) }
end
describe "WHEN a non existing user is provided (i.e. the user is deleted)" do
@ -43,7 +43,7 @@ describe DefaultHourlyRate do
rate.reload
end
it { rate.user.should == DeletedUser.first }
it { expect(rate.user).to eq(DeletedUser.first) }
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe HourlyRate do
describe HourlyRate, :type => :model do
let(:project) { FactoryGirl.create(:project) }
let(:user) { FactoryGirl.create(:user) }
let(:rate) { FactoryGirl.build(:hourly_rate, :project => project,
@ -32,7 +32,7 @@ describe HourlyRate do
rate.save!
end
it { rate.user.should == user }
it { expect(rate.user).to eq(user) }
end
describe "WHEN a non existing user is provided (i.e. the user is deleted)" do
@ -43,7 +43,7 @@ describe HourlyRate do
rate.reload
end
it { rate.user.should == DeletedUser.first }
it { expect(rate.user).to eq(DeletedUser.first) }
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe LaborBudgetItem do
describe LaborBudgetItem, :type => :model do
include Cost::PluginSpecHelper
let(:item) { FactoryGirl.build(:labor_budget_item, :cost_object => cost_object) }
let(:cost_object) { FactoryGirl.build(:variable_cost_object, :project => project) }
@ -40,7 +40,7 @@ describe LaborBudgetItem do
item.user = nil
end
it { item.calculated_costs.should == default_costs }
it { expect(item.calculated_costs).to eq(default_costs) }
end
describe "WHEN no hours are defined" do
@ -48,7 +48,7 @@ describe LaborBudgetItem do
item.hours = nil
end
it { item.calculated_costs.should == default_costs }
it { expect(item.calculated_costs).to eq(default_costs) }
end
describe "WHEN user, hours and rate are defined" do
@ -60,7 +60,7 @@ describe LaborBudgetItem do
rate.save!
end
it { item.calculated_costs.should == (rate.rate * item.hours) }
it { expect(item.calculated_costs).to eq(rate.rate * item.hours) }
end
describe "WHEN user, hours and rate are defined
@ -75,7 +75,7 @@ describe LaborBudgetItem do
user.destroy
end
it { item.calculated_costs.should == (rate.rate * item.hours) }
it { expect(item.calculated_costs).to eq(rate.rate * item.hours) }
end
end
@ -88,7 +88,7 @@ describe LaborBudgetItem do
item.reload
end
it { item.user.should == user }
it { expect(item.user).to eq(user) }
end
describe "WHEN a non existing user is provided (i.e. the user has been deleted)" do
@ -100,15 +100,15 @@ describe LaborBudgetItem do
item.reload
end
it { item.user.should == DeletedUser.first }
it { item.user_id.should == user.id }
it { expect(item.user).to eq(DeletedUser.first) }
it { expect(item.user_id).to eq(user.id) }
end
end
describe :valid? do
describe "WHEN hours, cost_object and user are provided" do
it "should be valid" do
item.should be_valid
expect(item).to be_valid
end
end
@ -118,8 +118,8 @@ describe LaborBudgetItem do
end
it "should not be valid" do
item.should_not be_valid
item.errors[:hours].should == [I18n.t('activerecord.errors.messages.not_a_number')]
expect(item).not_to be_valid
expect(item.errors[:hours]).to eq([I18n.t('activerecord.errors.messages.not_a_number')])
end
end
@ -129,8 +129,8 @@ describe LaborBudgetItem do
end
it "should not be valid" do
item.should_not be_valid
item.errors[:hours].should == [I18n.t('activerecord.errors.messages.not_a_number')]
expect(item).not_to be_valid
expect(item.errors[:hours]).to eq([I18n.t('activerecord.errors.messages.not_a_number')])
end
end
@ -140,8 +140,8 @@ describe LaborBudgetItem do
end
it "should not be valid" do
item.should_not be_valid
item.errors[:cost_object].should == [I18n.t('activerecord.errors.messages.blank')]
expect(item).not_to be_valid
expect(item.errors[:cost_object]).to eq([I18n.t('activerecord.errors.messages.blank')])
end
end
@ -151,8 +151,8 @@ describe LaborBudgetItem do
end
it "should not be valid" do
item.should_not be_valid
item.errors[:user].should == [I18n.t('activerecord.errors.messages.blank')]
expect(item).not_to be_valid
expect(item.errors[:user]).to eq([I18n.t('activerecord.errors.messages.blank')])
end
end
end
@ -171,7 +171,7 @@ describe LaborBudgetItem do
item.user = user
end
it { item.costs_visible_by?(user).should be_true }
it { expect(item.costs_visible_by?(user)).to be_truthy }
end
describe "WHEN the item is assigned to the user
@ -183,7 +183,7 @@ describe LaborBudgetItem do
item.user = user
end
it { item.costs_visible_by?(user).should be_false }
it { expect(item.costs_visible_by?(user)).to be_falsey }
end
describe "WHEN the item is assigned to another user
@ -195,7 +195,7 @@ describe LaborBudgetItem do
item.user = user
end
it { item.costs_visible_by?(user2).should be_true }
it { expect(item.costs_visible_by?(user2)).to be_truthy }
end
describe "WHEN the item is assigned to another user
@ -207,7 +207,7 @@ describe LaborBudgetItem do
item.user = user
end
it { item.costs_visible_by?(user2).should be_false }
it { expect(item.costs_visible_by?(user2)).to be_falsey }
end
end
end

@ -19,38 +19,38 @@
require File.expand_path('../../spec_helper', __FILE__)
describe PermittedParams do
describe PermittedParams, :type => :model do
let(:user) { FactoryGirl.build(:user) }
describe :cost_entry do
it "should return comments" do
params = ActionController::Parameters.new(:cost_entry => { "comments" => "blubs" } )
PermittedParams.new(params, user).cost_entry.should == { "comments" => "blubs" }
expect(PermittedParams.new(params, user).cost_entry).to eq({ "comments" => "blubs" })
end
it "should return units" do
params = ActionController::Parameters.new(:cost_entry => { "units" => "5.0" } )
PermittedParams.new(params, user).cost_entry.should == { "units" => "5.0" }
expect(PermittedParams.new(params, user).cost_entry).to eq({ "units" => "5.0" })
end
it "should return overridden_costs" do
params = ActionController::Parameters.new(:cost_entry => { "overridden_costs" => "5.0" } )
PermittedParams.new(params, user).cost_entry.should == { "overridden_costs" => "5.0" }
expect(PermittedParams.new(params, user).cost_entry).to eq({ "overridden_costs" => "5.0" })
end
it "should return spent_on" do
params = ActionController::Parameters.new(:cost_entry => { "spent_on" => Date.today.to_s } )
PermittedParams.new(params, user).cost_entry.should == { "spent_on" => Date.today.to_s }
expect(PermittedParams.new(params, user).cost_entry).to eq({ "spent_on" => Date.today.to_s })
end
it "should not return project_id" do
params = ActionController::Parameters.new(:cost_entry => { "project_id" => 42 } )
PermittedParams.new(params, user).cost_entry.should == { }
expect(PermittedParams.new(params, user).cost_entry).to eq({ })
end
end
@ -58,25 +58,25 @@ describe PermittedParams do
it "should return comments" do
params = ActionController::Parameters.new(:cost_object => { "subject" => "subject_test" } )
PermittedParams.new(params, user).cost_object.should == { "subject" => "subject_test" }
expect(PermittedParams.new(params, user).cost_object).to eq({ "subject" => "subject_test" })
end
it "should return description" do
params = ActionController::Parameters.new(:cost_object => { "description" => "description_test" } )
PermittedParams.new(params, user).cost_object.should == { "description" => "description_test" }
expect(PermittedParams.new(params, user).cost_object).to eq({ "description" => "description_test" })
end
it "should return fixed_date" do
params = ActionController::Parameters.new(:cost_object => { "fixed_date" => "2013-05-06" } )
PermittedParams.new(params, user).cost_object.should == { "fixed_date" => "2013-05-06" }
expect(PermittedParams.new(params, user).cost_object).to eq({ "fixed_date" => "2013-05-06" })
end
it "should not return project_id" do
params = ActionController::Parameters.new(:cost_object => { "project_id" => 42 } )
PermittedParams.new(params, user).cost_object.should == { }
expect(PermittedParams.new(params, user).cost_object).to eq({ })
end
context 'with budget item params' do
@ -94,7 +94,7 @@ describe PermittedParams do
}}
end
it { should == budget_item_params }
it { is_expected.to eq(budget_item_params) }
end
context 'of a new material budget item' do
@ -107,7 +107,7 @@ describe PermittedParams do
}}}
end
it { should == budget_item_params }
it { is_expected.to eq(budget_item_params) }
end
context 'of an existing labor budget item' do
@ -120,7 +120,7 @@ describe PermittedParams do
}}}
end
it { should == budget_item_params }
it { is_expected.to eq(budget_item_params) }
end
context 'of a new labor budget item' do
@ -133,7 +133,7 @@ describe PermittedParams do
}}}
end
it { should == budget_item_params }
it { is_expected.to eq(budget_item_params) }
end
end
end
@ -142,43 +142,43 @@ describe PermittedParams do
it "should return name" do
params = ActionController::Parameters.new(:cost_type => { "name" => "name_test" } )
PermittedParams.new(params, user).cost_type.should == { "name" => "name_test" }
expect(PermittedParams.new(params, user).cost_type).to eq({ "name" => "name_test" })
end
it "should return unit" do
params = ActionController::Parameters.new(:cost_type => { "unit" => "unit_test" } )
PermittedParams.new(params, user).cost_type.should == { "unit" => "unit_test" }
expect(PermittedParams.new(params, user).cost_type).to eq({ "unit" => "unit_test" })
end
it "should return unit_plural" do
params = ActionController::Parameters.new(:cost_type => { "unit_plural" => "unit_plural_test" } )
PermittedParams.new(params, user).cost_type.should == { "unit_plural" => "unit_plural_test" }
expect(PermittedParams.new(params, user).cost_type).to eq({ "unit_plural" => "unit_plural_test" })
end
it "should return default" do
params = ActionController::Parameters.new(:cost_type => { "default" => 7 } )
PermittedParams.new(params, user).cost_type.should == { "default" => 7 }
expect(PermittedParams.new(params, user).cost_type).to eq({ "default" => 7 })
end
it "should return new_rate_attributes" do
params = ActionController::Parameters.new(:cost_type => { "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" }, "1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } } )
PermittedParams.new(params, user).cost_type.should == { "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" }, "1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } }
expect(PermittedParams.new(params, user).cost_type).to eq({ "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" }, "1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } })
end
it "should return existing_rate_attributes" do
params = ActionController::Parameters.new(:cost_type => { "existing_rate_attributes" => { "9" => { "valid_from" => "2013-05-05", "rate" => "50.0" } } } )
PermittedParams.new(params, user).cost_type.should == { "existing_rate_attributes" => { "9" => { "valid_from" => "2013-05-05", "rate" => "50.0" } } }
expect(PermittedParams.new(params, user).cost_type).to eq({ "existing_rate_attributes" => { "9" => { "valid_from" => "2013-05-05", "rate" => "50.0" } } })
end
it "should not return project_id" do
params = ActionController::Parameters.new(:cost_type => { "project_id" => 42 } )
PermittedParams.new(params, user).cost_type.should == { }
expect(PermittedParams.new(params, user).cost_type).to eq({ })
end
end
@ -187,16 +187,16 @@ describe PermittedParams do
params = ActionController::Parameters.new(:user => { "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } } )
PermittedParams.new(params, user).user_rates.should == { "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } }
expect(PermittedParams.new(params, user).user_rates).to eq({ "new_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } })
end
it "should return existing_rate_attributes" do
params = ActionController::Parameters.new(:user => { "existing_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } } )
PermittedParams.new(params, user).user_rates.should == { "existing_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } }
expect(PermittedParams.new(params, user).user_rates).to eq({ "existing_rate_attributes" => { "0" => { "valid_from" => "2013-05-08", "rate" => "5002" },
"1" => { "valid_from" => "2013-05-10", "rate" => "5004" } } })
end
end
@ -207,7 +207,7 @@ describe PermittedParams do
params = ActionController::Parameters.new(:work_package => hash)
PermittedParams.new(params, user).new_work_package.should == hash
expect(PermittedParams.new(params, user).new_work_package).to eq(hash)
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Rate do
describe Rate, :type => :model do
let(:rate) { FactoryGirl.build(:rate) }
describe :valid? do
@ -29,8 +29,8 @@ describe Rate do
end
it "should not be valid" do
rate.should_not be_valid
rate.errors[:rate].should == [I18n.t('activerecord.errors.messages.not_a_number')]
expect(rate).not_to be_valid
expect(rate.errors[:rate]).to eq([I18n.t('activerecord.errors.messages.not_a_number')])
end
end
@ -40,8 +40,8 @@ describe Rate do
end
it "should not be valid" do
rate.should_not be_valid
rate.errors[:rate].should == [I18n.t('activerecord.errors.messages.not_a_number')]
expect(rate).not_to be_valid
expect(rate.errors[:rate]).to eq([I18n.t('activerecord.errors.messages.not_a_number')])
end
end
@ -50,7 +50,7 @@ describe Rate do
rate.rate = 5.0
end
it { rate.should be_valid }
it { expect(rate).to be_valid }
end
describe "WHEN a date is supplied" do
@ -58,7 +58,7 @@ describe Rate do
rate.valid_from = Date.today
end
it { rate.should be_valid }
it { expect(rate).to be_valid }
end
describe "WHEN a transformable string is supplied for date" do
@ -66,7 +66,7 @@ describe Rate do
rate.valid_from = "2012-03-04"
end
it { rate.should be_valid }
it { expect(rate).to be_valid }
end
describe "WHEN a nontransformable string is supplied for date" do
@ -75,8 +75,8 @@ describe Rate do
end
it "should not be valid" do
rate.should_not be_valid
rate.errors[:valid_from].should == [I18n.t('activerecord.errors.messages.not_a_date')]
expect(rate).not_to be_valid
expect(rate.errors[:valid_from]).to eq([I18n.t('activerecord.errors.messages.not_a_date')])
end
end
@ -86,8 +86,8 @@ describe Rate do
end
it "should not be valid" do
rate.should_not be_valid
rate.errors[:valid_from].should == [I18n.t('activerecord.errors.messages.not_a_date')]
expect(rate).not_to be_valid
expect(rate.errors[:valid_from]).to eq([I18n.t('activerecord.errors.messages.not_a_date')])
end
end
end

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe TimeEntry do
describe TimeEntry, :type => :model do
include Cost::PluginSpecHelper
let(:project) { FactoryGirl.create(:project_with_types, is_public: false) }
let(:project2) { FactoryGirl.create(:project_with_types, is_public: false) }
@ -62,18 +62,18 @@ describe TimeEntry do
it "should always prefer overridden_costs" do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
value = rand(500)
time_entry.overridden_costs = value
time_entry.overridden_costs.should == value
time_entry.real_costs.should == value
expect(time_entry.overridden_costs).to eq(value)
expect(time_entry.real_costs).to eq(value)
time_entry.save!
end
describe "given rate" do
before(:each) do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
@default_example = time_entry2
end
@ -81,7 +81,7 @@ describe TimeEntry do
(0..100).each do |hours|
time_entry.hours = hours
time_entry.save!
time_entry.costs.should == time_entry.rate.rate * hours
expect(time_entry.costs).to eq(time_entry.rate.rate * hours)
end
end
@ -90,7 +90,7 @@ describe TimeEntry do
time_entry.spent_on = Time.now
time_entry.hours = 1
time_entry.save!
time_entry.costs.should == hourly_one.rate
expect(time_entry.costs).to eq(hourly_one.rate)
(hourly = HourlyRate.new.tap do |hr|
hr.valid_from = 1.day.ago
hr.rate = 1.0
@ -98,8 +98,8 @@ describe TimeEntry do
hr.project = hourly_one.project
end).save!
time_entry.reload
time_entry.rate.should_not == hourly_one
time_entry.costs.should == hourly.rate
expect(time_entry.rate).not_to eq(hourly_one)
expect(time_entry.costs).to eq(hourly.rate)
end
it "should update cost if a new rate is added in between" do
@ -107,7 +107,7 @@ describe TimeEntry do
time_entry.spent_on = 3.days.ago.to_date
time_entry.hours = 1
time_entry.save!
time_entry.costs.should == hourly_three.rate
expect(time_entry.costs).to eq(hourly_three.rate)
(hourly = HourlyRate.new.tap do |hr|
hr.valid_from = 3.days.ago.to_date
hr.rate = 1.0
@ -115,8 +115,8 @@ describe TimeEntry do
hr.project = hourly_one.project
end).save!
time_entry.reload
time_entry.rate.should_not == hourly_three
time_entry.costs.should == hourly.rate
expect(time_entry.rate).not_to eq(hourly_three)
expect(time_entry.costs).to eq(hourly.rate)
end
it "should update cost if a spent_on changes" do
@ -124,7 +124,7 @@ describe TimeEntry do
(5.days.ago.to_date..Date.today).each do |time|
time_entry.spent_on = time.to_date
time_entry.save!
time_entry.costs.should == time_entry.user.rate_at(time, project.id).rate
expect(time_entry.costs).to eq(time_entry.user.rate_at(time, project.id).rate)
end
end
@ -132,30 +132,30 @@ describe TimeEntry do
time_entry.spent_on = hourly_one.valid_from
time_entry.hours = 1
time_entry.save!
time_entry.costs.should == hourly_one.rate
expect(time_entry.costs).to eq(hourly_one.rate)
hourly_one.destroy
time_entry.reload
time_entry.costs.should == hourly_three.rate
expect(time_entry.costs).to eq(hourly_three.rate)
hourly_three.destroy
time_entry.reload
time_entry.costs.should == hourly_five.rate
expect(time_entry.costs).to eq(hourly_five.rate)
end
it "should be able to change order of rates (sorted by valid_from)" do
time_entry.spent_on = hourly_one.valid_from
time_entry.save!
time_entry.rate.should == hourly_one
expect(time_entry.rate).to eq(hourly_one)
hourly_one.valid_from = hourly_three.valid_from - 1.day
hourly_one.save!
time_entry.reload
time_entry.rate.should == hourly_three
expect(time_entry.rate).to eq(hourly_three)
end
end
describe "default rate" do
before(:each) do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
@default_example = time_entry2
end
@ -163,7 +163,7 @@ describe TimeEntry do
(0..100).each do |hours|
@default_example.hours = hours
@default_example.save!
@default_example.costs.should == @default_example.rate.rate * hours
expect(@default_example.costs).to eq(@default_example.rate.rate * hours)
end
end
@ -172,15 +172,15 @@ describe TimeEntry do
@default_example.spent_on = Time.now.to_date
@default_example.hours = 1
@default_example.save!
@default_example.costs.should == default_hourly_one.rate
expect(@default_example.costs).to eq(default_hourly_one.rate)
(hourly = DefaultHourlyRate.new.tap do |dhr|
dhr.valid_from = 1.day.ago.to_date
dhr.rate = 1.0
dhr.user = user2
end).save!
@default_example.reload
@default_example.rate.should_not == default_hourly_one
@default_example.costs.should == hourly.rate
expect(@default_example.rate).not_to eq(default_hourly_one)
expect(@default_example.costs).to eq(hourly.rate)
end
it "should update cost if a new rate is added in between" do
@ -188,15 +188,15 @@ describe TimeEntry do
@default_example.spent_on = 3.days.ago.to_date
@default_example.hours = 1
@default_example.save!
@default_example.costs.should == default_hourly_three.rate
expect(@default_example.costs).to eq(default_hourly_three.rate)
(hourly = DefaultHourlyRate.new.tap do |dhr|
dhr.valid_from = 3.days.ago.to_date
dhr.rate = 1.0
dhr.user = user2
end).save!
@default_example.reload
@default_example.rate.should_not == default_hourly_three
@default_example.costs.should == hourly.rate
expect(@default_example.rate).not_to eq(default_hourly_three)
expect(@default_example.costs).to eq(hourly.rate)
end
it "should update cost if a spent_on changes" do
@ -204,7 +204,7 @@ describe TimeEntry do
(5.days.ago.to_date..Date.today).each do |time|
@default_example.spent_on = time.to_date
@default_example.save!
@default_example.costs.should == @default_example.user.rate_at(time, project.id).rate
expect(@default_example.costs).to eq(@default_example.user.rate_at(time, project.id).rate)
end
end
@ -212,13 +212,13 @@ describe TimeEntry do
@default_example.spent_on = default_hourly_one.valid_from
@default_example.hours = 1
@default_example.save!
@default_example.costs.should == default_hourly_one.rate
expect(@default_example.costs).to eq(default_hourly_one.rate)
default_hourly_one.destroy
@default_example.reload
@default_example.costs.should == default_hourly_three.rate
expect(@default_example.costs).to eq(default_hourly_three.rate)
default_hourly_three.destroy
@default_example.reload
@default_example.costs.should == default_hourly_five.rate
expect(@default_example.costs).to eq(default_hourly_five.rate)
end
it "shoud be able to switch between default hourly rate and hourly rate" do
@ -226,7 +226,7 @@ describe TimeEntry do
@default_example.rate = default_hourly_one
@default_example.save!
@default_example.reload
@default_example.rate.should == default_hourly_one
expect(@default_example.rate).to eq(default_hourly_one)
(rate = HourlyRate.new.tap do |hr|
hr.valid_from = 10.days.ago.to_date
@ -236,10 +236,10 @@ describe TimeEntry do
end).save!
@default_example.reload
@default_example.rate.should == rate
expect(@default_example.rate).to eq(rate)
rate.destroy
@default_example.reload
@default_example.rate.should == default_hourly_one
expect(@default_example.rate).to eq(default_hourly_one)
end
describe :costs_visible_by? do
@ -256,7 +256,7 @@ describe TimeEntry do
time_entry.user = user
end
it { time_entry.costs_visible_by?(user).should be_true }
it { expect(time_entry.costs_visible_by?(user)).to be_truthy }
end
describe "WHEN the time_entry is assigned to the user
@ -268,7 +268,7 @@ describe TimeEntry do
time_entry.user = user
end
it { time_entry.costs_visible_by?(user).should be_false }
it { expect(time_entry.costs_visible_by?(user)).to be_falsey }
end
describe "WHEN the time_entry is assigned to another user
@ -280,7 +280,7 @@ describe TimeEntry do
time_entry.user = user
end
it { time_entry.costs_visible_by?(user2).should be_true }
it { expect(time_entry.costs_visible_by?(user2)).to be_truthy }
end
describe "WHEN the time_entry is assigned to another user
@ -292,7 +292,7 @@ describe TimeEntry do
time_entry.user = user
end
it { time_entry.costs_visible_by?(user2).should be_false }
it { expect(time_entry.costs_visible_by?(user2)).to be_falsey }
end
end
end
@ -308,7 +308,7 @@ describe TimeEntry do
time_entry.save!
end
it { TimeEntry.visible(user2, project).all.should =~ [time_entry] }
it { expect(TimeEntry.visible(user2, project).all).to match_array([time_entry]) }
end
describe "WHEN not having the view_time_entries permission
@ -320,7 +320,7 @@ describe TimeEntry do
time_entry.save!
end
it { TimeEntry.visible(user2, project).all.should =~ [] }
it { expect(TimeEntry.visible(user2, project).all).to match_array([]) }
end
describe "WHEN having the view_own_time_entries permission
@ -334,7 +334,7 @@ describe TimeEntry do
time_entry.save!
end
it { TimeEntry.visible(user2, project).all.should =~ [] }
it { expect(TimeEntry.visible(user2, project).all).to match_array([]) }
end
describe "WHEN having the view_own_time_entries permission
@ -348,7 +348,7 @@ describe TimeEntry do
time_entry2.save!
end
it { TimeEntry.visible(time_entry2.user, project).all.should =~ [time_entry2] }
it { expect(TimeEntry.visible(time_entry2.user, project).all).to match_array([time_entry2]) }
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe User, "#destroy" do
describe User, :type => :model, "#destroy" do
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:substitute_user) { DeletedUser.first }
@ -53,22 +53,22 @@ describe User, "#destroy" do
associated_instance.reload
end
it { associated_class.find_by_id(associated_instance.id).should == associated_instance }
it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
it "should replace the user on all associations" do
associations.each do |association|
associated_instance.send(association).should == substitute_user
expect(associated_instance.send(association)).to eq(substitute_user)
end
end
it { associated_instance.journals.first.user.should == user2 }
it { expect(associated_instance.journals.first.user).to eq(user2) }
it "should update first journal changed_data" do
associations.each do |association|
associated_instance.journals.first.changed_data["#{association}_id".to_sym].last.should == user2.id
expect(associated_instance.journals.first.changed_data["#{association}_id".to_sym].last).to eq(user2.id)
end
end
it { associated_instance.journals.last.user.should == substitute_user }
it { expect(associated_instance.journals.last.user).to eq(substitute_user) }
it "should update second journal changed_data" do
associations.each do |association|
associated_instance.journals.last.changed_data["#{association}_id".to_sym].last.should == substitute_user.id
expect(associated_instance.journals.last.changed_data["#{association}_id".to_sym].last).to eq(substitute_user.id)
end
end
end
@ -92,23 +92,23 @@ describe User, "#destroy" do
associated_instance.reload
end
it { associated_class.find_by_id(associated_instance.id).should == associated_instance }
it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
it "should keep the current user on all associations" do
associations.each do |association|
associated_instance.send(association).should == user2
expect(associated_instance.send(association)).to eq(user2)
end
end
it { associated_instance.journals.first.user.should == substitute_user }
it { expect(associated_instance.journals.first.user).to eq(substitute_user) }
it "should update the first journal" do
associations.each do |association|
associated_instance.journals.first.changed_data["#{association}_id".to_sym].last.should == substitute_user.id
expect(associated_instance.journals.first.changed_data["#{association}_id".to_sym].last).to eq(substitute_user.id)
end
end
it { associated_instance.journals.last.user.should == user2 }
it { expect(associated_instance.journals.last.user).to eq(user2) }
it "should update the last journal" do
associations.each do |association|
associated_instance.journals.last.changed_data["#{association}_id".to_sym].first.should == substitute_user.id
associated_instance.journals.last.changed_data["#{association}_id".to_sym].last.should == user2.id
expect(associated_instance.journals.last.changed_data["#{association}_id".to_sym].first).to eq(substitute_user.id)
expect(associated_instance.journals.last.changed_data["#{association}_id".to_sym].last).to eq(user2.id)
end
end
end
@ -138,8 +138,8 @@ describe User, "#destroy" do
user.destroy
end
it { LaborBudgetItem.find_by_id(item.id).should == item }
it { item.user_id.should == user.id }
it { expect(LaborBudgetItem.find_by_id(item.id)).to eq(item) }
it { expect(item.user_id).to eq(user.id) }
end
describe "WHEN the user has a cost entry" do
@ -162,7 +162,7 @@ describe User, "#destroy" do
entry.reload
end
it { entry.user_id.should == user.id }
it { expect(entry.user_id).to eq(user.id) }
end
describe "WHEN the user is assigned an hourly rate" do
@ -174,8 +174,8 @@ describe User, "#destroy" do
user.destroy
end
it { HourlyRate.find_by_id(hourly_rate.id).should == hourly_rate }
it { hourly_rate.reload.user_id.should == user.id }
it { expect(HourlyRate.find_by_id(hourly_rate.id)).to eq(hourly_rate) }
it { expect(hourly_rate.reload.user_id).to eq(user.id) }
end
describe "WHEN the user is assigned a default hourly rate" do
@ -187,7 +187,7 @@ describe User, "#destroy" do
user.destroy
end
it { DefaultHourlyRate.find_by_id(default_hourly_rate.id).should == default_hourly_rate }
it { default_hourly_rate.reload.user_id.should == user.id }
it { expect(DefaultHourlyRate.find_by_id(default_hourly_rate.id)).to eq(default_hourly_rate) }
it { expect(default_hourly_rate.reload.user_id).to eq(user.id) }
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe User do
describe User, :type => :model do
include Cost::PluginSpecHelper
let(:klass) { User }
let(:user) { FactoryGirl.build(:user) }
@ -31,7 +31,7 @@ describe User do
describe :allowed_to do
describe "WITH querying for a non existent permission" do
it { user.allowed_to?(:bogus_permission, project).should be_false }
it { expect(user.allowed_to?(:bogus_permission, project)).to be_falsey }
end
end
@ -51,7 +51,7 @@ describe User do
end
it "should return a sql condition where the project id the user has the permission in is enforced" do
user.allowed_to_condition_with_project_id(permission).should == "(projects.id in (#{project.id}))"
expect(user.allowed_to_condition_with_project_id(permission)).to eq("(projects.id in (#{project.id}))")
end
end
@ -68,7 +68,7 @@ describe User do
valid_conditions = ["(projects.id in (#{project.id}, #{project2.id}))",
"(projects.id in (#{project2.id}, #{project.id}))"]
valid_conditions.should include(user.allowed_to_condition_with_project_id(permission))
expect(valid_conditions).to include(user.allowed_to_condition_with_project_id(permission))
end
end
@ -79,7 +79,7 @@ describe User do
end
it "should return a neutral (for an or operation) sql condition" do
user.allowed_to_condition_with_project_id(permission).should == "1=0"
expect(user.allowed_to_condition_with_project_id(permission)).to eq("1=0")
end
end
@ -91,7 +91,7 @@ describe User do
end
it "should return a sql condition where all the project ids the user has the permission in is enforced" do
user.allowed_to_condition_with_project_id(permission, project).should == "(projects.id in (#{project.id}))"
expect(user.allowed_to_condition_with_project_id(permission, project)).to eq("(projects.id in (#{project.id}))")
end
end
end
@ -116,15 +116,15 @@ describe User do
end
it "should update the rate" do
user.rates.detect{ |r| r.id == project_hourly_rate.id }.rate.should == new_attributes[project_hourly_rate.id.to_s][:rate].to_i
expect(user.rates.detect{ |r| r.id == project_hourly_rate.id }.rate).to eq(new_attributes[project_hourly_rate.id.to_s][:rate].to_i)
end
it "should update valid_from" do
user.rates.detect{ |r| r.id == project_hourly_rate.id }.valid_from.should == new_attributes[project_hourly_rate.id.to_s][:valid_from].to_date
expect(user.rates.detect{ |r| r.id == project_hourly_rate.id }.valid_from).to eq(new_attributes[project_hourly_rate.id.to_s][:valid_from].to_date)
end
it "should not create a rate" do
user.rates.size.should == 1
expect(user.rates.size).to eq(1)
end
end
@ -144,15 +144,15 @@ describe User do
end
it "should not update the rate" do
user.rates.detect{ |r| r.id == project_hourly_rate.id }.rate.should == @original_rate
expect(user.rates.detect{ |r| r.id == project_hourly_rate.id }.rate).to eq(@original_rate)
end
it "should not update valid_from" do
user.rates.detect{ |r| r.id == project_hourly_rate.id }.valid_from.should == @original_valid_from
expect(user.rates.detect{ |r| r.id == project_hourly_rate.id }.valid_from).to eq(@original_valid_from)
end
it "should not create a rate" do
user.rates.size.should == 1
expect(user.rates.size).to eq(1)
end
end
@ -167,7 +167,7 @@ describe User do
end
it "should delete the hourly rate" do
user.rates(true).should be_empty
expect(user.rates(true)).to be_empty
end
end
@ -182,7 +182,7 @@ describe User do
end
it "should delete the default hourly rate" do
user.default_rates(true).should be_empty
expect(user.default_rates(true)).to be_empty
end
end
end

@ -19,7 +19,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe VariableCostObject do
describe VariableCostObject, :type => :model do
let(:cost_object) { FactoryGirl.build(:variable_cost_object) }
let(:type) { FactoryGirl.create(:type_feature) }
let(:project) { FactoryGirl.create(:project_with_types) }
@ -27,7 +27,7 @@ describe VariableCostObject do
describe 'recreate initial journal' do
before do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
@variable_cost_object = FactoryGirl.create(:variable_cost_object , :project => project,
:author => user)
@ -36,17 +36,17 @@ describe VariableCostObject do
@recreated_journal = @variable_cost_object.recreate_initial_journal!
end
it { @initial_journal.should be_identical(@recreated_journal) }
it { expect(@initial_journal).to be_identical(@recreated_journal) }
end
describe "initialization" do
let(:cost_object) { VariableCostObject.new }
before do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
end
it { cost_object.author.should == user }
it { expect(cost_object.author).to eq(user) }
end
describe "destroy" do
@ -60,8 +60,8 @@ describe VariableCostObject do
cost_object.destroy
end
it { VariableCostObject.find_by_id(cost_object.id).should be_nil }
it { WorkPackage.find_by_id(work_package.id).should == work_package }
it { work_package.reload.cost_object.should be_nil }
it { expect(VariableCostObject.find_by_id(cost_object.id)).to be_nil }
it { expect(WorkPackage.find_by_id(work_package.id)).to eq(work_package) }
it { expect(work_package.reload.cost_object).to be_nil }
end
end

@ -19,7 +19,7 @@
require 'spec_helper'
describe WorkPackage do
describe WorkPackage, :type => :model do
let(:work_package) { FactoryGirl.create(:work_package, :project => project,
:status => status) }
let(:work_package2) { FactoryGirl.create(:work_package, :project => project2,
@ -54,7 +54,7 @@ describe WorkPackage do
end
it "should be true" do
WorkPackage.cleanup_action_required_before_destructing?(work_package).should be_true
expect(WorkPackage.cleanup_action_required_before_destructing?(work_package)).to be_truthy
end
end
@ -66,7 +66,7 @@ describe WorkPackage do
end
it "should be true" do
WorkPackage.cleanup_action_required_before_destructing?([work_package, work_package2]).should be_true
expect(WorkPackage.cleanup_action_required_before_destructing?([work_package, work_package2])).to be_truthy
end
end
@ -76,7 +76,7 @@ describe WorkPackage do
end
it "should be false" do
WorkPackage.cleanup_action_required_before_destructing?(work_package).should be_false
expect(WorkPackage.cleanup_action_required_before_destructing?(work_package)).to be_falsey
end
end
end
@ -89,7 +89,7 @@ describe WorkPackage do
end
it "should be have 'CostEntry' as class to address" do
WorkPackage.associated_classes_to_address_before_destruction_of(work_package).should == [CostEntry]
expect(WorkPackage.associated_classes_to_address_before_destruction_of(work_package)).to eq([CostEntry])
end
end
@ -99,7 +99,7 @@ describe WorkPackage do
end
it "should be empty" do
WorkPackage.associated_classes_to_address_before_destruction_of(work_package).should be_empty
expect(WorkPackage.associated_classes_to_address_before_destruction_of(work_package)).to be_empty
end
end
end
@ -119,7 +119,7 @@ describe WorkPackage do
end
it 'should return true' do
action.should be_true
expect(action).to be_truthy
end
end
@ -127,14 +127,14 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, :action => 'destroy') }
it 'should return true' do
action.should be_true
expect(action).to be_truthy
end
it 'should not touch the cost_entry' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
end
@ -142,14 +142,14 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user) }
it 'should return true' do
action.should be_true
expect(action).to be_truthy
end
it 'should not touch the cost_entry' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
end
@ -157,20 +157,20 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, :action => 'nullify') }
it 'should return false' do
action.should be_false
expect(action).to be_falsey
end
it 'should not alter the work_package_id of all cost entries' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
it 'should set an error on work packages' do
action
work_package.errors.get(:base).should == [I18n.t(:'activerecord.errors.models.work_package.nullify_is_not_valid_for_cost_entries')]
expect(work_package.errors.get(:base)).to eq([I18n.t(:'activerecord.errors.models.work_package.nullify_is_not_valid_for_cost_entries')])
end
end
@ -186,21 +186,21 @@ describe WorkPackage do
end
it 'should return true' do
action.should be_true
expect(action).to be_truthy
end
it 'should set the work_package_id of all cost entries to the new work package' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package2.id
expect(cost_entry.work_package_id).to eq(work_package2.id)
end
it "should set the project_id of all cost entries to the new work package's project" do
action
cost_entry.reload
cost_entry.project_id.should == work_package2.project_id
expect(cost_entry.project_id).to eq(work_package2.project_id)
end
end
@ -213,14 +213,14 @@ describe WorkPackage do
end
it 'should return true' do
action.should be_false
expect(action).to be_falsey
end
it 'should not alter the work_package_id of all cost entries' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
end
@ -229,14 +229,14 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, :action => 'reassign', :reassign_to_id => 0) }
it 'should return true' do
action.should be_false
expect(action).to be_falsey
end
it 'should not alter the work_package_id of all cost entries' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
end
@ -245,14 +245,14 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, :action => 'reassign') }
it 'should return true' do
action.should be_false
expect(action).to be_falsey
end
it 'should not alter the work_package_id of all cost entries' do
action
cost_entry.reload
cost_entry.work_package_id.should == work_package.id
expect(cost_entry.work_package_id).to eq(work_package.id)
end
end
@ -260,7 +260,7 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, :action => 'bogus') }
it 'should return false' do
action.should be_false
expect(action).to be_falsey
end
end
@ -268,7 +268,7 @@ describe WorkPackage do
let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, nil) }
it 'should return false' do
action.should be_false
expect(action).to be_falsey
end
end
end

@ -19,7 +19,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe WorkPackage do
describe WorkPackage, :type => :model do
let(:user) { FactoryGirl.create(:admin) }
let(:role) { FactoryGirl.create(:role) }
let(:project) do
@ -36,21 +36,21 @@ describe WorkPackage do
let!(:cost_object) { FactoryGirl.create(:cost_object, project: project) }
before(:each) do
User.stub!(:current).and_return(user)
allow(User).to receive(:current).and_return(user)
end
it "should update cost entries on move" do
work_package.project_id.should eql project.id
work_package.move_to_project(project2).should_not be_false
cost_entry.reload.project_id.should eql project2.id
expect(work_package.project_id).to eql project.id
expect(work_package.move_to_project(project2)).not_to be_falsey
expect(cost_entry.reload.project_id).to eql project2.id
end
it "should allow to set cost_object to nil" do
work_package.cost_object = cost_object
work_package.save!
work_package.cost_object.should eql cost_object
expect(work_package.cost_object).to eql cost_object
work_package.cost_object = nil
lambda { work_package.save! }.should_not raise_error(ActiveRecord::RecordInvalid)
expect { work_package.save! }.not_to raise_error
end
end

@ -19,33 +19,33 @@
require 'spec_helper'
describe CostObjectsController do
describe CostObjectsController, :type => :routing do
describe "routing" do
it { get('/projects/blubs/cost_objects/new').should route_to(:controller => 'cost_objects',
it { expect(get('/projects/blubs/cost_objects/new')).to route_to(:controller => 'cost_objects',
:action => 'new',
:project_id => 'blubs') }
it { post('/projects/blubs/cost_objects').should route_to(:controller => 'cost_objects',
it { expect(post('/projects/blubs/cost_objects')).to route_to(:controller => 'cost_objects',
:action => 'create',
:project_id => 'blubs') }
it { get('/projects/blubs/cost_objects').should route_to(:controller => 'cost_objects',
it { expect(get('/projects/blubs/cost_objects')).to route_to(:controller => 'cost_objects',
:action => 'index',
:project_id => 'blubs') }
it { get('/cost_objects/5').should route_to(:controller => 'cost_objects',
it { expect(get('/cost_objects/5')).to route_to(:controller => 'cost_objects',
:action => 'show',
:id => '5') }
it { put('/cost_objects/5').should route_to(:controller => 'cost_objects',
it { expect(put('/cost_objects/5')).to route_to(:controller => 'cost_objects',
:action => 'update',
:id => '5') }
it { delete('/cost_objects/5').should route_to(:controller => 'cost_objects',
it { expect(delete('/cost_objects/5')).to route_to(:controller => 'cost_objects',
:action => 'destroy',
:id => '5') }
it { post('/projects/42/cost_objects/update_material_budget_item').should route_to(:controller => 'cost_objects',
it { expect(post('/projects/42/cost_objects/update_material_budget_item')).to route_to(:controller => 'cost_objects',
:action => 'update_material_budget_item',
:project_id => '42') }
it { post('/projects/42/cost_objects/update_labor_budget_item').should route_to(:controller => 'cost_objects',
it { expect(post('/projects/42/cost_objects/update_labor_budget_item')).to route_to(:controller => 'cost_objects',
:action => 'update_labor_budget_item',
:project_id => '42') }
it { get('/cost_objects/5/copy').should route_to(:controller => 'cost_objects',
it { expect(get('/cost_objects/5/copy')).to route_to(:controller => 'cost_objects',
:action => 'copy',
:id => '5') }
end

@ -19,30 +19,30 @@
require 'spec_helper'
describe CostTypesController do
describe CostTypesController, :type => :routing do
describe "routing" do
it { get('/cost_types').should route_to(:controller => 'cost_types',
it { expect(get('/cost_types')).to route_to(:controller => 'cost_types',
:action => 'index') }
it { post('/cost_types').should route_to(:controller => 'cost_types',
it { expect(post('/cost_types')).to route_to(:controller => 'cost_types',
:action => 'create') }
it { get('/cost_types/new').should route_to(:controller => 'cost_types',
it { expect(get('/cost_types/new')).to route_to(:controller => 'cost_types',
:action => 'new') }
it { get('/cost_types/5/edit').should route_to(:controller => 'cost_types',
it { expect(get('/cost_types/5/edit')).to route_to(:controller => 'cost_types',
:action => 'edit',
:id => '5') }
it { put('/cost_types/5').should route_to(:controller => 'cost_types',
it { expect(put('/cost_types/5')).to route_to(:controller => 'cost_types',
:action => 'update',
:id => '5') }
it { put('/cost_types/5/set_rate').should route_to(:controller => 'cost_types',
it { expect(put('/cost_types/5/set_rate')).to route_to(:controller => 'cost_types',
:action => 'set_rate',
:id => '5') }
it { put('/cost_types/5/toggle_delete').should route_to(:controller => 'cost_types',
it { expect(put('/cost_types/5/toggle_delete')).to route_to(:controller => 'cost_types',
:action => 'toggle_delete',
:id => '5') }
end

@ -19,33 +19,33 @@
require 'spec_helper'
describe CostlogController do
describe CostlogController, :type => :routing do
describe "routing" do
it { get('/work_packages/5/cost_entries').should route_to(:controller => 'costlog',
it { expect(get('/work_packages/5/cost_entries')).to route_to(:controller => 'costlog',
:action => 'index',
:work_package_id => '5') }
it { get('/projects/blubs/cost_entries/new').should route_to(:controller => 'costlog',
it { expect(get('/projects/blubs/cost_entries/new')).to route_to(:controller => 'costlog',
:action => 'new',
:project_id => 'blubs') }
it { post('/projects/blubs/cost_entries').should route_to(:controller => 'costlog',
it { expect(post('/projects/blubs/cost_entries')).to route_to(:controller => 'costlog',
:action => 'create',
:project_id => 'blubs') }
it { get('/work_packages/5/cost_entries/new').should route_to(:controller => 'costlog',
it { expect(get('/work_packages/5/cost_entries/new')).to route_to(:controller => 'costlog',
:action => 'new',
:work_package_id => '5') }
it { get('/cost_entries/5/edit').should route_to(:controller => 'costlog',
it { expect(get('/cost_entries/5/edit')).to route_to(:controller => 'costlog',
:action => 'edit',
:id => '5') }
it { put('/cost_entries/5').should route_to(:controller => 'costlog',
it { expect(put('/cost_entries/5')).to route_to(:controller => 'costlog',
:action => 'update',
:id => '5') }
it { delete('/cost_entries/5').should route_to(:controller => 'costlog',
it { expect(delete('/cost_entries/5')).to route_to(:controller => 'costlog',
:action => 'destroy',
:id => '5') }
end

@ -19,28 +19,28 @@
require 'spec_helper'
describe HourlyRatesController do
describe HourlyRatesController, :type => :routing do
describe "routing" do
it { get('/projects/blubs/hourly_rates/5').should route_to(:controller => 'hourly_rates',
it { expect(get('/projects/blubs/hourly_rates/5')).to route_to(:controller => 'hourly_rates',
:action => 'show',
:project_id => 'blubs',
:id => '5') }
it { get('/projects/blubs/hourly_rates/5/edit').should route_to(:controller => 'hourly_rates',
it { expect(get('/projects/blubs/hourly_rates/5/edit')).to route_to(:controller => 'hourly_rates',
:action => 'edit',
:project_id => 'blubs',
:id => '5') }
it { get('/hourly_rates/5/edit').should route_to(:controller => 'hourly_rates',
it { expect(get('/hourly_rates/5/edit')).to route_to(:controller => 'hourly_rates',
:action => 'edit',
:id => '5') }
it { put('/projects/blubs/hourly_rates/5').should route_to(:controller => 'hourly_rates',
it { expect(put('/projects/blubs/hourly_rates/5')).to route_to(:controller => 'hourly_rates',
:action => 'update',
:project_id => 'blubs',
:id => '5') }
it { post('/projects/blubs/hourly_rates/5/set_rate').should route_to(:controller => 'hourly_rates',
it { expect(post('/projects/blubs/hourly_rates/5/set_rate')).to route_to(:controller => 'hourly_rates',
:action => 'set_rate',
:project_id => 'blubs',
:id => '5') }

Loading…
Cancel
Save