Merge pull request #41 from finnlabs/feature/rails3_fix_testsetup

[OPF #764,765] Feature/rails3 fix testsetup
pull/6827/head
Christian Rijke 12 years ago
commit 0e5d9c0f77
  1. 14
      app/models/cost_entry.rb
  2. 2
      app/models/cost_rate.rb
  3. 4
      app/models/default_hourly_rate.rb
  4. 4
      app/models/hourly_rate.rb
  5. 4
      config/locales/en.yml
  6. 8
      features/step_definitions/cost_steps.rb
  7. 2
      lib/open_project/costs/patches/issue_patch.rb
  8. 2
      spec/factories/default_hourly_rate_factory.rb
  9. 2
      spec/factories/hourly_rate_factory.rb

@ -12,7 +12,7 @@ class CostEntry < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
validates_presence_of :issue_id, :project_id, :user_id, :cost_type_id, :units, :spent_on
validates_numericality_of :units, :allow_nil => false, :message => :activerecord_error_invalid
validates_numericality_of :units, :allow_nil => false, :message => :invalid
validates_length_of :comments, :maximum => 255, :allow_nil => true
before_save :before_save
@ -53,16 +53,16 @@ class CostEntry < ActiveRecord::Base
end
def validate
errors.add :units, :activerecord_error_invalid if units && (units < 0)
errors.add :project_id, :activerecord_error_invalid if project.nil?
errors.add :issue_id, :activerecord_error_invalid if issue.nil? || (project != issue.project)
errors.add :cost_type_id, :activerecord_error_invalid if cost_type.present? && cost_type.deleted_at.present?
errors.add :user_id, :activerecord_error_invalid if project.present? && !project.users.include?(user) && user_id_changed?
errors.add :units, :invalid if units && (units < 0)
errors.add :project_id, :invalid if project.nil?
errors.add :issue_id, :invalid if issue.nil? || (project != issue.project)
errors.add :cost_type_id, :invalid if cost_type.present? && cost_type.deleted_at.present?
errors.add :user_id, :invalid if project.present? && !project.users.include?(user) && user_id_changed?
begin
spent_on.to_date
rescue Exception
errors.add :spent_on, :activerecord_error_invalid
errors.add :spent_on, :invalid
end
end

@ -21,6 +21,6 @@ class CostRate < Rate
private
def change_of_cost_type_only_on_first_creation
errors.add :cost_type_id, :activerecord_error_invalid if cost_type_id_changed? && ! self.new_record?
errors.add :cost_type_id, :invalid if cost_type_id_changed? && ! self.new_record?
end
end

@ -33,11 +33,11 @@ class DefaultHourlyRate < Rate
def change_of_user_only_on_first_creation
# Only allow change of user on first creation
errors.add :user_id, :activerecord_error_invalid if !self.new_record? and user_id_changed?
errors.add :user_id, :invalid if !self.new_record? and user_id_changed?
begin
valid_from.to_date
rescue Exception
errors.add :valid_from, :activerecord_error_invalid
errors.add :valid_from, :invalid
end
end
end

@ -61,7 +61,7 @@ class HourlyRate < Rate
# Only allow change of project and user on first creation
return if self.new_record?
errors.add :project_id, :activerecord_error_invalid if project_id_changed?
errors.add :user_id, :activerecord_error_invalid if user_id_changed?
errors.add :project_id, :invalid if project_id_changed?
errors.add :user_id, :invalid if user_id_changed?
end
end

@ -16,8 +16,8 @@ en:
cost_object: Budget
rate: Rate
cost_type:
one: "Cost Type"
other: "Cost Types"
one: "Cost type"
other: "Cost types"
material_budget_item: Unit
attributes:
cost_object:

@ -10,14 +10,12 @@ end
Given /^there (?:is|are) (\d+) (default )?hourly rate[s]? with the following:$/ do |num, is_default, table|
if is_default
hr = DefaultHourlyRate.spawn
hr = FactoryGirl.create(:default_hourly_rate)
else
hr = HourlyRate.spawn
hr = FactoryGirl.create(:hourly_rate)
end
send_table_to_object(hr, table, {
:user => Proc.new do |rate, value|
rate.save!
rate.reload
unless rate.project.nil? || User.find_by_login(value).projects.include?(rate.project)
Rate.update_all({ :project_id => User.find_by_login(value).projects(:order => "id ASC").last.id },
{ :id => rate.id })
@ -38,7 +36,7 @@ Given /^the [Uu]ser "([^\"]*)" has (\d+) [Cc]ost(?: )?[Ee]ntr(?:ies|y)$/ do |use
p = u.projects.last
i = Issue.generate_for_project!(p)
as_admin count do
ce = CostEntry.spawn
ce = FactoryGirl.create(:cost_entry)
ce.user = u
ce.project = p
ce.issue = i

@ -46,7 +46,7 @@ module OpenProject::Costs::Patches::IssuePatch
def validate_cost_object
if cost_object_id_changed?
unless (cost_object_id.blank? || project.cost_object_ids.include?(cost_object_id))
errors.add :cost_object_id, :activerecord_error_invalid
errors.add :cost_object_id, :invalid
end
end
end

@ -1,5 +1,7 @@
FactoryGirl.define do
factory :default_hourly_rate do
association :user, :factory => :user
association :project, :factory => :project
valid_from Date.today
rate 50.0
end

@ -1,5 +1,7 @@
FactoryGirl.define do
factory :hourly_rate do
association :user, :factory => :user
association :project, :factory => :project
valid_from Date.today
rate 50.0
end

Loading…
Cancel
Save