parent
74862806ca
commit
f55b84c606
@ -0,0 +1,349 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe UserMailer do |
||||
describe 'journal details' do |
||||
let(:type_standard) { FactoryGirl.build_stubbed(:type_standard) } |
||||
let(:user) { FactoryGirl.build_stubbed(:user) } |
||||
let(:journal) { FactoryGirl.build_stubbed(:work_package_journal) } |
||||
let(:work_package) { FactoryGirl.build_stubbed(:issue, |
||||
type: type_standard) } |
||||
|
||||
subject { UserMailer.issue_updated(user, journal).body.encoded } |
||||
|
||||
before do |
||||
work_package.stub(:reload).and_return(work_package) |
||||
|
||||
journal.stub(:journable).and_return(work_package) |
||||
journal.stub(:user).and_return(user) |
||||
|
||||
Setting.stub(:mail_from).and_return('john@doe.com') |
||||
Setting.stub(:host_name).and_return('mydomain.foo') |
||||
Setting.stub(:protocol).and_return('http') |
||||
Setting.stub(:default_language).and_return('en') |
||||
end |
||||
|
||||
describe 'plain text mail' do |
||||
before do |
||||
Setting.stub(:plain_text_mail).and_return('1') |
||||
end |
||||
|
||||
describe 'done ration modifications' do |
||||
context 'changed done ratio' do |
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [40, 100]}) |
||||
end |
||||
|
||||
it 'displays changed done ratio' do |
||||
should match("% done changed from 40 to 100") |
||||
end |
||||
end |
||||
|
||||
context 'new done ratio' do |
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [nil, 100]}) |
||||
end |
||||
|
||||
it 'displays new done ratio' do |
||||
should match("% done changed from 0 to 100") |
||||
end |
||||
end |
||||
|
||||
context 'deleted done ratio' do |
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [50, nil]}) |
||||
end |
||||
|
||||
it 'displays deleted done ratio' do |
||||
should match("% done changed from 50 to 0") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'start_date attribute' do |
||||
context 'format the start date' do |
||||
before do |
||||
journal.stub(:details).and_return({"start_date" => ['2010-01-01', '2010-01-31']}) |
||||
end |
||||
|
||||
it 'old date should be formatted' do |
||||
should match("01/01/2010") |
||||
end |
||||
|
||||
it 'new date should be formatted' do |
||||
should match("01/31/2010") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'due_date attribute' do |
||||
context 'format the end date' do |
||||
before do |
||||
journal.stub(:details).and_return({"due_date" => ['2010-01-01', '2010-01-31']}) |
||||
end |
||||
|
||||
it 'old date should be formatted' do |
||||
should match("01/01/2010") |
||||
end |
||||
|
||||
it 'new date should be formatted' do |
||||
should match("01/31/2010") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'project attribute' do |
||||
let(:project_1) { FactoryGirl.create(:project) } |
||||
let(:project_2) { FactoryGirl.create(:project) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"project_id" => [project_1.id, project_2.id]}) |
||||
end |
||||
|
||||
it "shows the old project's name" do |
||||
should match(project_1.name) |
||||
end |
||||
|
||||
it "shows the new project's name" do |
||||
should match(project_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute issue status' do |
||||
let(:issue_status_1) { FactoryGirl.create(:issue_status) } |
||||
let(:issue_status_2) { FactoryGirl.create(:issue_status) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"status_id" => [issue_status_1.id, issue_status_2.id]}) |
||||
end |
||||
|
||||
it "shows the old status' name" do |
||||
should match(issue_status_1.name) |
||||
end |
||||
|
||||
it "shows the new status' name" do |
||||
should match(issue_status_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute type' do |
||||
let(:type_1) { FactoryGirl.create(:type_standard) } |
||||
let(:type_2) { FactoryGirl.create(:type_bug) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"type_id" => [type_1.id, type_2.id]}) |
||||
end |
||||
|
||||
it "shows the old type's name" do |
||||
should match(type_1.name) |
||||
end |
||||
|
||||
it "shows the new type's name" do |
||||
should match(type_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute assigned to' do |
||||
let(:assignee_1) { FactoryGirl.create(:user) } |
||||
let(:assignee_2) { FactoryGirl.create(:user) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"assigned_to_id" => [assignee_1.id, assignee_2.id]}) |
||||
end |
||||
|
||||
it "shows the old assignee's name" do |
||||
should match(assignee_1.name) |
||||
end |
||||
|
||||
it "shows the new assignee's name" do |
||||
should match(assignee_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute priority' do |
||||
let(:priority_1) { FactoryGirl.create(:priority) } |
||||
let(:priority_2) { FactoryGirl.create(:priority) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"priority_id" => [priority_1.id, priority_2.id]}) |
||||
end |
||||
|
||||
it "shows the old priority's name" do |
||||
should match(priority_1.name) |
||||
end |
||||
|
||||
it "shows the new priority's name" do |
||||
should match(priority_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute category' do |
||||
let(:category_1) { FactoryGirl.create(:issue_category) } |
||||
let(:category_2) { FactoryGirl.create(:issue_category) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"category_id" => [category_1.id, category_2.id]}) |
||||
end |
||||
|
||||
it "shows the old category's name" do |
||||
should match(category_1.name) |
||||
end |
||||
|
||||
it "shows the new category's name" do |
||||
should match(category_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute fixed version' do |
||||
let(:version_1) { FactoryGirl.create(:version) } |
||||
let(:version_2) { FactoryGirl.create(:version) } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"fixed_version_id" => [version_1.id, version_2.id]}) |
||||
end |
||||
|
||||
it "shows the old version's name" do |
||||
should match(version_1.name) |
||||
end |
||||
|
||||
it "shows the new version's name" do |
||||
should match(version_2.name) |
||||
end |
||||
end |
||||
|
||||
describe 'attribute estimated hours' do |
||||
let(:estimated_hours_1) { 30.5678 } |
||||
let(:estimated_hours_2) { 35.912834 } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"estimated_hours" => [estimated_hours_1, estimated_hours_2]}) |
||||
end |
||||
|
||||
it "shows the old estimated hours" do |
||||
should match('%.2f' % estimated_hours_1) |
||||
end |
||||
|
||||
it "shows the new estimated hours" do |
||||
should match('%.2f' % estimated_hours_2) |
||||
end |
||||
end |
||||
|
||||
describe 'custom field' do |
||||
let(:expected_text_1) { "original, unchanged text" } |
||||
let(:expected_text_2) { "modified, new text" } |
||||
let(:custom_field) { FactoryGirl.create :work_package_custom_field, |
||||
field_format: "text" } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"custom_fields_#{custom_field.id}" => [expected_text_1, expected_text_2]}) |
||||
end |
||||
|
||||
it "shows the old custom field value" do |
||||
should match(expected_text_1) |
||||
end |
||||
|
||||
it "shows the new custom field value" do |
||||
should match(expected_text_2) |
||||
end |
||||
end |
||||
|
||||
describe 'attachments' do |
||||
let(:attachment) { FactoryGirl.create :attachment } |
||||
|
||||
context 'added' do |
||||
before do |
||||
journal.stub(:details).and_return({"attachments_#{attachment.id}" => [nil, attachment.filename]}) |
||||
end |
||||
|
||||
it "shows the attachment's filename" do |
||||
should match(attachment.filename) |
||||
end |
||||
|
||||
it "shows status 'added'" do |
||||
should match('added') |
||||
end |
||||
|
||||
it "shows no status 'deleted'" do |
||||
should_not match('deleted') |
||||
end |
||||
end |
||||
|
||||
context 'removed' do |
||||
before do |
||||
journal.stub(:details).and_return({"attachments_#{attachment.id}" => [attachment.filename, nil]}) |
||||
end |
||||
|
||||
it "shows the attachment's filename" do |
||||
should match(attachment.filename) |
||||
end |
||||
|
||||
it "shows no status 'added'" do |
||||
should_not match('added') |
||||
end |
||||
|
||||
it "shows status 'deleted'" do |
||||
should match('deleted') |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'html mail' do |
||||
let(:expected_translation) { I18n.t(:done_ratio, :scope => [:activerecord, |
||||
:attributes, |
||||
:work_package]) } |
||||
let(:expected_prefix) { "<li><strong>#{expected_translation}</strong>" } |
||||
|
||||
before do |
||||
Setting.stub(:plain_text_mail).and_return('0') |
||||
end |
||||
|
||||
context 'changed done ratio' do |
||||
let(:expected) { "#{expected_prefix} changed from <i>40</i> to <i>100</i>" } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [40, 100]}) |
||||
end |
||||
|
||||
it 'displays changed done ratio' do |
||||
should match(expected) |
||||
end |
||||
end |
||||
|
||||
context 'new done ratio' do |
||||
let(:expected) { "#{expected_prefix} changed from <i>0</i> to <i>100</i>" } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [nil, 100]}) |
||||
end |
||||
|
||||
it 'displays new done ratio' do |
||||
should match(expected) |
||||
end |
||||
end |
||||
|
||||
context 'deleted done ratio' do |
||||
let(:expected) { "#{expected_prefix} changed from <i>50</i> to <i>0</i>" } |
||||
|
||||
before do |
||||
journal.stub(:details).and_return({"done_ratio" => [50, nil]}) |
||||
end |
||||
|
||||
it 'displays deleted done ratio' do |
||||
should match(expected) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,208 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# |
||||
# Copyright (C) 2012-2013 the OpenProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
require File.expand_path('../../../test_helper', __FILE__) |
||||
|
||||
class IssuesHelperTest < HelperTestCase |
||||
include ApplicationHelper |
||||
include IssuesHelper |
||||
|
||||
include ActionDispatch::Assertions::SelectorAssertions |
||||
|
||||
# Used by assert_select |
||||
def html_document |
||||
HTML::Document.new(@response.body) |
||||
end |
||||
|
||||
def setup |
||||
super |
||||
set_language_if_valid('en') |
||||
User.current = nil |
||||
@response = ActionController::TestResponse.new |
||||
end |
||||
|
||||
def controller |
||||
@controller ||= IssuesController.new |
||||
end |
||||
|
||||
def request |
||||
@request ||= ActionController::TestRequest.new |
||||
end |
||||
|
||||
|
||||
# TODO: Move test code to Journal class |
||||
context "IssuesHelper#show_detail" do |
||||
context "with no_html" do |
||||
should 'show a changing attribute' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [40, 100]}) |
||||
|
||||
assert_equal "% done changed from 40 to 100", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
|
||||
should 'show a new attribute' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [nil, 100]}) |
||||
|
||||
assert_equal "% done changed from 0 to 100", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
|
||||
should 'show a deleted attribute' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [50, nil]}) |
||||
|
||||
assert_equal "% done changed from 50 to 0", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
end |
||||
|
||||
context "with html" do |
||||
should 'show a changing attribute with HTML highlights' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [40, 100]}) |
||||
|
||||
@response.body = journal.render_detail(journal.details.to_a.first, :no_html => false) |
||||
|
||||
html_node = HTML::Document.new(@response.body) |
||||
assert_select html_node.root, 'strong', :text => I18n.t(:done_ratio, :scope => [:activerecord, |
||||
:attributes, |
||||
:work_package]) |
||||
assert_select html_node.root, 'i', :text => '40' |
||||
assert_select html_node.root, 'i', :text => '100' |
||||
end |
||||
|
||||
should 'show a new attribute with HTML highlights' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [nil, 100]}) |
||||
|
||||
@response.body = journal.render_detail(journal.details.to_a.first, :no_html => false) |
||||
|
||||
html_node = HTML::Document.new(@response.body) |
||||
assert_select html_node.root, 'strong', :text => I18n.t(:done_ratio, :scope => [:activerecord, |
||||
:attributes, |
||||
:work_package]) |
||||
assert_select html_node.root, 'i', :text => '100' |
||||
end |
||||
|
||||
should 'show a deleted attribute with HTML highlights' do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"done_ratio" => [50, nil]}) |
||||
|
||||
@response.body = journal.render_detail(journal.details.to_a.first, :no_html => false) |
||||
|
||||
html_node = HTML::Document.new(@response.body) |
||||
assert_select html_node.root, 'strong', :text => I18n.t(:done_ratio, :scope => [:activerecord, |
||||
:attributes, |
||||
:work_package]) |
||||
end |
||||
end |
||||
|
||||
context "with a start_date attribute" do |
||||
should "format the current date" do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"start_date" => ['2010-01-01', '2010-01-31']}) |
||||
|
||||
assert_match "01/31/2010", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
|
||||
should "format the old date" do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"start_date" => ['2010-01-01', '2010-01-31']}) |
||||
|
||||
assert_match "01/01/2010", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
end |
||||
|
||||
context "with a due_date attribute" do |
||||
should "format the current date" do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"start_date" => ['2010-01-01', '2010-01-31']}) |
||||
|
||||
assert_match "01/31/2010", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
|
||||
should "format the old date" do |
||||
issue = FactoryGirl.build :issue |
||||
journal = FactoryGirl.build :work_package_journal |
||||
|
||||
journal.stubs(:journable).returns(issue) |
||||
journal.stubs(:details).returns({"start_date" => ['2010-01-01', '2010-01-31']}) |
||||
|
||||
assert_match "01/01/2010", journal.render_detail(journal.details.to_a.first, :no_html => true) |
||||
end |
||||
end |
||||
|
||||
context "with a project attribute" do |
||||
should_show_the_old_and_new_values_for('project_id', Project) |
||||
end |
||||
|
||||
context "with a issue status attribute" do |
||||
should_show_the_old_and_new_values_for('status_id', IssueStatus) |
||||
end |
||||
|
||||
context "with a type attribute" do |
||||
should_show_the_old_and_new_values_for('type_id', Type) |
||||
end |
||||
|
||||
context "with a assigned to attribute" do |
||||
should_show_the_old_and_new_values_for('assigned_to_id', User) |
||||
end |
||||
|
||||
context "with a priority attribute" do |
||||
should_show_the_old_and_new_values_for('priority_id', IssuePriority) do |
||||
@old_value = IssuePriority.generate!(:type => 'IssuePriority') |
||||
@new_value = IssuePriority.generate!(:type => 'IssuePriority') |
||||
end |
||||
end |
||||
|
||||
context "with a category attribute" do |
||||
should_show_the_old_and_new_values_for('category_id', IssueCategory) |
||||
end |
||||
|
||||
context "with a fixed version attribute" do |
||||
should_show_the_old_and_new_values_for('fixed_version_id', Version) |
||||
end |
||||
|
||||
context "with a estimated hours attribute" do |
||||
should "format the time into two decimal places" |
||||
should "format the old time into two decimal places" |
||||
end |
||||
|
||||
should "test custom fields" |
||||
should "test attachments" |
||||
end |
||||
end |
Loading…
Reference in new issue