organization_ratings_plugin_profile_controller_test.rb
3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'test_helper'
require 'organization_ratings_plugin_profile_controller'
require File.dirname(__FILE__) + '/../helpers/software_test_helper'
# Re-raise errors caught by the controller.
class OrganizationRatingsPluginProfileController; def rescue_action(e) raise e end; end
class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCase
include SoftwareTestHelper
def setup
@controller = OrganizationRatingsPluginProfileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@environment = Environment.default
@environment.enabled_plugins = ['OrganizationRatingsPlugin']
@environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
@environment.save
SoftwareCommunitiesPlugin::LicenseInfo.create(:version=>"CC-GPL-V2",
:link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt")
@person = create_user('testuser').person
@software = create_software(software_fields)
@statistic_block = SoftwareCommunitiesPlugin::StatisticBlock.new
@software.community.blocks << @statistic_block
@software.community.save!
login_as(@person.identifier)
@controller.stubs(:logged_in?).returns(true)
@controller.stubs(:current_user).returns(@person.user)
end
test "should create a task with a valid benefited people value and no comment" do
assert_difference 'CreateOrganizationRatingComment.count' do
post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
:organization_rating_value => 3, :organization_rating => {:people_benefited => 50}
end
end
test "should create a task with a valid saved value and no comment" do
assert_difference 'CreateOrganizationRatingComment.count' do
post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
:organization_rating_value => 3, :organization_rating => {:saved_value => 50000000}
end
end
test "should not create a task with no saved value or benefited poeple, and no comment" do
assert_no_difference 'CreateOrganizationRatingComment.count' do
post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
:organization_rating_value => 3, :organization_rating => nil
end
end
test "software statistics should be updated when task is accepted" do
@software.reload
assert_equal 0, @software.benefited_people
assert_equal 0.0, @software.saved_resources
post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
:organization_rating_value => 3,
:organization_rating => {:saved_value => 500, :people_benefited => 10}
CreateOrganizationRatingComment.last.finish
@software.reload
assert_equal 10, @software.benefited_people
assert_equal 500.0, @software.saved_resources
end
test "software statistics should not be updated when task is cancelled" do
@software.reload
assert_equal 0, @software.benefited_people
assert_equal 0.0, @software.saved_resources
post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
:organization_rating_value => 3,
:organization_rating => {:saved_value => 500, :people_benefited => 10}
CreateOrganizationRatingComment.last.cancel
@software.reload
assert_equal 0, @software.benefited_people
assert_equal 0.0, @software.saved_resources
end
end