From ddb2dcbbf805864fe88fa60bf079149e44f3e281 Mon Sep 17 00:00:00 2001 From: Romano Licker Date: Fri, 16 Mar 2012 20:35:49 +0100 Subject: [PATCH] testing recreate_initial_journal! for cost_objects --- .../factories/varibale_cost_object_factory.rb | 7 ++++-- spec/models/variable_cost_object_spec.rb | 20 +++++++++++++++ spec/spec_helper.rb | 25 +++---------------- 3 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 spec/models/variable_cost_object_spec.rb diff --git a/spec/factories/varibale_cost_object_factory.rb b/spec/factories/varibale_cost_object_factory.rb index 74c379dffc..2a03a4f6a5 100644 --- a/spec/factories/varibale_cost_object_factory.rb +++ b/spec/factories/varibale_cost_object_factory.rb @@ -1,3 +1,6 @@ -Factory.define :variable_cost_object do |co| - +Factory.define :variable_cost_object do |m| + m.association :project, :factory => :project + m.sequence(:subject) { |n| "Cost Object No. #{n}" } + m.sequence(:description) { |n| "I am a Cost Object No. #{n}" } + m.fixed_date Time.now end diff --git a/spec/models/variable_cost_object_spec.rb b/spec/models/variable_cost_object_spec.rb new file mode 100644 index 0000000000..65eccaebf6 --- /dev/null +++ b/spec/models/variable_cost_object_spec.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe VariableCostObject do + before(:each) do + @tracker ||= Factory.create(:tracker_feature) + @project ||= Factory.create(:project_with_trackers) + @current = Factory.create(:user, :login => "user1", :mail => "user1@users.com") + + User.stub!(:current).and_return(@current) + end + + it 'should work with recreate initial journal' do + @variable_cost_object ||= Factory.create(:variable_cost_object , :project => @project, :author => @current) + + initial_journal = @variable_cost_object.journals.first + recreated_journal = @variable_cost_object.recreate_initial_journal! + + initial_journal.should be_identical(recreated_journal) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dad5e55d23..729f6fbe1e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,26 +1,7 @@ RAILS_ENV = "test" unless defined? RAILS_ENV -# prevent case where we are using rubygems and test-unit 2.x is installed -begin - require 'rubygems' - gem "test-unit", "~> 1.2.3" -rescue LoadError -end - -begin - #require "config/environment" unless defined? RAILS_ROOT - require 'spec/spec_helper' -rescue LoadError => error - puts <<-EOS - - You need to install rspec in your Redmine project. - Please execute the following code: - - gem install rspec-rails - script/generate rspec - - EOS - raise error -end +require 'spec/spec_helper' +require 'redmine_factory_girl' +require 'identical_ext' Fixtures.create_fixtures File.join(File.dirname(__FILE__), "fixtures"), ActiveRecord::Base.connection.tables