Moves AAJ test to spec

pull/411/head
Hagen Schink 11 years ago
parent 0c711ed3b0
commit 7987934e18
  1. 7
      app/models/work_package.rb
  2. 27
      spec/models/work_package_acts_as_journalized_spec.rb
  3. 17
      test/unit/issue_test.rb

@ -201,6 +201,13 @@ class WorkPackage < ActiveRecord::Base
(project && type) ? (project.all_work_package_custom_fields & type.custom_fields.all) : []
end
def description=(description)
# Bug #501: browsers might swap the line endings causing a Journal.
if description.gsub(/\r\n?/,"\n") != self.description
write_attribute :description, description
end
end
def estimated_hours=(h)
converted_hours = (h.is_a?(String) ? h.to_hours : h)
write_attribute :estimated_hours, !!converted_hours ? converted_hours : h

@ -45,6 +45,33 @@ describe WorkPackage do
it { Journal.all.count.should eq(1) }
end
context "line endings changed" do
let(:description) { "Description\n\nwith newlines\n\nembedded" }
let(:work_package_1) { FactoryGirl.create(:work_package,
project_id: project.id,
type: type,
description: description,
priority: priority) }
before do
work_package_1
work_package_1.description = "Description\r\n\r\nwith newlines\r\n\r\nembedded"
work_package_1.save!
end
describe "does not change journal count" do
subject { Journal.count }
it { should eq(2) } # work_package + work_package_1
end
describe "does not change work package description" do
subject { work_package_1.description }
it { should eq(description) }
end
end
context "on work package change" do
let(:parent_work_package) { FactoryGirl.create(:planning_element,
:project_id => project.id,

@ -16,21 +16,4 @@ class IssueTest < ActiveSupport::TestCase
fixtures :all
test 'changing the line endings in a description will not be recorded as a Journal' do
User.current = User.find(1)
issue = Issue.find(1)
issue.update_attribute(:description, "Description with newlines\n\nembedded")
issue.reload
assert issue.description.include?("\n")
assert_no_difference("Journal.count") do
issue.safe_attributes= {
'description' => "Description with newlines\r\n\r\nembedded"
}
assert issue.save
end
assert_equal "Description with newlines\n\nembedded", issue.reload.description
end
end

Loading…
Cancel
Save