profile_controller_test.rb
3.29 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
86
87
88
89
90
91
92
93
94
95
96
require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
require File.expand_path(File.dirname(__FILE__)) + '/../helpers/software_test_helper'
require(
File.expand_path(File.dirname(__FILE__)) +
'/../../../../app/controllers/public/profile_controller'
)
class ProfileController; def rescue_action(e) raise e end; end
class ProfileControllerTest < ActionController::TestCase
include SoftwareTestHelper
def setup
@controller =CommunitiesRatingsPluginProfileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@profile = create_user('default_user').person
LicenseInfo.create(
:version=>"CC-GPL-V2",
:link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
)
@environment = Environment.default
@environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'CommunitiesRatingsPlugin']
@admin = create_user("adminuser").person
@admin.stubs(:has_permission?).returns("true")
@environment.add_admin(@admin)
@environment.save
@software = create_software(software_fields)
end
should "dispach additional comment fields when a software is rated" do
login_as(@admin.name)
get :new_rating , profile: @software.community.identifier
assert_template :new_rating
assert_match(/Additional informations/, @response.body)
end
should "DO NOT dispach additional comment fields when the rated community isn't a software" do
login_as(@admin.name)
community = fast_create(Community)
get :new_rating , profile: community.identifier
assert_template :new_rating
assert_not_match(/Additional informations/, @response.body)
end
should "show additional comment fields on rate list if logged user is a environment admin" do
login_as(@admin.name)
seed_avaliations
get :new_rating , profile: @software.community.identifier
assert_match("<span>People benefited :</span> 123", @response.body)
assert_match("<span>Saved Value :</span> 123456.0", @response.body)
end
should "show additional comment fields on rate list if logged user is the software admin" do
seed_avaliations
login_as(@profile.name)
@software.community.add_admin @profile
get :new_rating , profile: @software.community.identifier
assert_match("<span>People benefited :</span> 123", @response.body)
assert_match("<span>Saved Value :</span> 123456.0", @response.body)
end
should "DO NOT show additional comment fields on rate list if logged user in't a admin" do
login_as(@profile.name)
seed_avaliations
get :new_rating , profile: @software.community.identifier
assert_not_match("<span>People benefited :</span> 123", @response.body)
assert_not_match("<span>Saved Value :</span> 123456.0", @response.body)
end
private
def make_avaliation software, person, rate_value, people_benefited, saved_value
comment = Comment.create! :author=>person, :body=>"simple body", :people_benefited=>people_benefited, :saved_value=>saved_value
rate = CommunityRating.new :value=>rate_value, :person=>person, :community=>software.community
rate.comment = comment
rate.save!
rate
end
def seed_avaliations
make_avaliation @software, @profile, 1, 123, 123456
make_avaliation @software, @admin, 2, 456, 789456
end
end