Commit 3cd609d0bdd56d539ad86ffb8d7d31aba4e77013
1 parent
56eca94b
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
proposals_discussion: added tests
Showing
12 changed files
with
206 additions
and
27 deletions
Show diff stats
plugins/proposals_discussion/controllers/public/proposals_discussion_plugin_public_controller.rb
@@ -9,27 +9,27 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | @@ -9,27 +9,27 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | ||
9 | page = (params[:page] || 1).to_i | 9 | page = (params[:page] || 1).to_i |
10 | 10 | ||
11 | set_seed | 11 | set_seed |
12 | - proposals = holder.proposals.public.reorder('random()') | ||
13 | - proposals = proposals.page(page).per_page(5) | 12 | + @proposals = holder.proposals.public.reorder('random()') |
13 | + @proposals = @proposals.page(page).per_page(5) | ||
14 | 14 | ||
15 | - unless proposals.empty? | ||
16 | - render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => proposals, :holder => holder, :next_page => page+1} | 15 | + unless @proposals.empty? |
16 | + render :partial => 'content_viewer/proposals_list_content', :locals => {:proposals => @proposals, :holder => holder, :page => page+1} | ||
17 | else | 17 | else |
18 | render :text => '' | 18 | render :text => '' |
19 | end | 19 | end |
20 | end | 20 | end |
21 | 21 | ||
22 | - private | 22 | + private |
23 | 23 | ||
24 | - def set_seed | ||
25 | - #XXX postgresql specific | ||
26 | - seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed]) | ||
27 | - profile.connection.execute("select setseed(#{seed_val})") | ||
28 | - end | 24 | + def set_seed |
25 | + #XXX postgresql specific | ||
26 | + seed_val = profile.connection.quote(cookies[:_noosfero_proposals_discussion_rand_seed]) | ||
27 | + profile.connection.execute("select setseed(#{seed_val})") | ||
28 | + end | ||
29 | 29 | ||
30 | - def set_rand_cookie | ||
31 | - return if cookies[:_noosfero_proposals_discussion_rand_seed].present? | ||
32 | - cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 900} | ||
33 | - end | 30 | + def set_rand_cookie |
31 | + return if cookies[:_noosfero_proposals_discussion_rand_seed].present? | ||
32 | + cookies[:_noosfero_proposals_discussion_rand_seed] = {value: rand, expires: Time.now + 600} | ||
33 | + end | ||
34 | 34 | ||
35 | end | 35 | end |
plugins/proposals_discussion/public/style.css
1 | .private-proposals .proposal { | 1 | .private-proposals .proposal { |
2 | - background: rgb(249, 252, 193); | 2 | + background: url(/images/hachure.png); |
3 | + opacity: 0.5; | ||
4 | + filter: alpha(opacity=25); | ||
5 | + zoom: 1; | ||
3 | } | 6 | } |
4 | 7 | ||
5 | .proposal { | 8 | .proposal { |
@@ -10,7 +13,6 @@ | @@ -10,7 +13,6 @@ | ||
10 | vertical-align: top; | 13 | vertical-align: top; |
11 | margin: 12px 13px 12px 0; | 14 | margin: 12px 13px 12px 0; |
12 | box-shadow: 5px 5px 5px -2px #ddd; | 15 | box-shadow: 5px 5px 5px -2px #ddd; |
13 | - padding: 5px; | ||
14 | } | 16 | } |
15 | 17 | ||
16 | .article-body-proposals-discussion-plugin_discussion .actions, | 18 | .article-body-proposals-discussion-plugin_discussion .actions, |
@@ -22,11 +24,12 @@ | @@ -22,11 +24,12 @@ | ||
22 | display: table-cell; | 24 | display: table-cell; |
23 | border-right: 1px solid; | 25 | border-right: 1px solid; |
24 | border-color: rgb(201, 201, 201); | 26 | border-color: rgb(201, 201, 201); |
27 | + padding: 5px; | ||
25 | } | 28 | } |
26 | .proposal .topic { | 29 | .proposal .topic { |
27 | border-right: 0; | 30 | border-right: 0; |
28 | text-align: center; | 31 | text-align: center; |
29 | - width: 30%; | 32 | + width: 24%; |
30 | } | 33 | } |
31 | .proposal .score { | 34 | .proposal .score { |
32 | width: 8%; | 35 | width: 8%; |
@@ -50,16 +53,16 @@ | @@ -50,16 +53,16 @@ | ||
50 | } | 53 | } |
51 | 54 | ||
52 | #article .proposal .title a { | 55 | #article .proposal .title a { |
53 | - padding: 8px 0px; | 56 | + padding: 4px 0px; |
54 | } | 57 | } |
55 | 58 | ||
56 | .proposal .content { | 59 | .proposal .content { |
57 | - width: 60%; | 60 | + width: 68%; |
58 | color: rgb(83, 83, 83); | 61 | color: rgb(83, 83, 83); |
59 | } | 62 | } |
60 | 63 | ||
61 | .proposal .abstract { | 64 | .proposal .abstract { |
62 | - padding-top: 8px; | 65 | + padding-top: 4px; |
63 | } | 66 | } |
64 | 67 | ||
65 | form .proposals-discussion-plugin textarea { | 68 | form .proposals-discussion-plugin textarea { |
plugins/proposals_discussion/test/functional/proposals_discussion_plugin_myprofile_controller_test.rb
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class ProposalsDiscussionPluginMyprofileControllerTest < ActionController::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = fast_create(Community) | ||
7 | + @discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) | ||
8 | + @topic = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => @discussion.id, :profile_id => @profile.id) | ||
9 | + @person = create_user_with_permission('testinguser', 'post_content') | ||
10 | + login_as :testinguser | ||
11 | + end | ||
12 | + | ||
13 | + attr_reader :profile, :discussion, :topic, :person | ||
14 | + | ||
15 | + should 'list topics for selection' do | ||
16 | + 3.times {fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => discussion.id, :profile_id => profile.id)} | ||
17 | + get :select_topic, :profile => profile.identifier, :parent_id => discussion.id | ||
18 | + assert_equal discussion, assigns(:discussion) | ||
19 | + assert_select 'div#topics' do | ||
20 | + assert_select 'div.content', discussion.topics.count | ||
21 | + assert_select "input[name='discussion[topic]']", discussion.topics.count | ||
22 | + end | ||
23 | + assert_tag :form, :attributes => {:action => "/myprofile/#{profile.identifier}/plugin/proposals_discussion/myprofile/new_proposal"} | ||
24 | + end | ||
25 | + | ||
26 | + should 'new_proposal redirect to cms controller' do | ||
27 | + get :new_proposal, :profile => profile.identifier, :discussion => {:topic => topic.id} | ||
28 | + assert_redirected_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => topic.id | ||
29 | + end | ||
30 | + | ||
31 | + should 'publish a proposal' do | ||
32 | + proposal = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :profile_id => profile.id, :published => false, :created_by_id => person.id) | ||
33 | + get :publish_proposal, :proposal_id => proposal.id, :profile => profile.identifier | ||
34 | + assert proposal.reload.published | ||
35 | + end | ||
36 | + | ||
37 | + should 'do not publish if the logged user do not have edition permission' do | ||
38 | + proposal = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :profile_id => profile.id, :published => false) | ||
39 | + get :publish_proposal, :proposal_id => proposal.id, :profile => profile.identifier | ||
40 | + assert_response 403 | ||
41 | + assert !proposal.reload.published | ||
42 | + end | ||
43 | + | ||
44 | +end |
plugins/proposals_discussion/test/functional/proposals_discussion_plugin_public_controller_test.rb
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class ProposalsDiscussionPluginPublicControllerTest < ActionController::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = fast_create(Community) | ||
7 | + @discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) | ||
8 | + @topic = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => @discussion.id, :profile_id => @profile.id) | ||
9 | + end | ||
10 | + | ||
11 | + attr_reader :profile, :discussion, :topic | ||
12 | + | ||
13 | + should 'load proposals' do | ||
14 | + proposals = 3.times.map { fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal title', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id)} | ||
15 | + get :load_proposals, :profile => profile.identifier, :holder_id => discussion.id | ||
16 | + assert_equivalent proposals, assigns(:proposals) | ||
17 | + end | ||
18 | + | ||
19 | + should 'add link to next page' do | ||
20 | + proposal = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal title', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
21 | + get :load_proposals, :profile => profile.identifier, :holder_id => discussion.id | ||
22 | + assert_match /href=.*page=2/, response.body | ||
23 | + end | ||
24 | + | ||
25 | + should 'render blank text if it is the last page' do | ||
26 | + get :load_proposals, :profile => profile.identifier, :holder_id => discussion.id | ||
27 | + assert_equal '', response.body | ||
28 | + end | ||
29 | + | ||
30 | +end |
plugins/proposals_discussion/test/unit/discussion_test.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class DiscussionTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = fast_create(Community) | ||
7 | + @discussion = ProposalsDiscussionPlugin::Discussion.new(:name => 'test', :profile => @profile) | ||
8 | + end | ||
9 | + | ||
10 | + attr_reader :profile, :discussion | ||
11 | + | ||
12 | + should 'return list of topics' do | ||
13 | + discussion.save! | ||
14 | + topic1 = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => discussion.id) | ||
15 | + topic2 = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => discussion.id) | ||
16 | + assert_equivalent [topic1, topic2], discussion.topics | ||
17 | + end | ||
18 | + | ||
19 | + should 'return list of proposals' do | ||
20 | + discussion.save! | ||
21 | + topic = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => discussion.id) | ||
22 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | ||
23 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | ||
24 | + assert_equivalent [proposal1, proposal2], discussion.proposals | ||
25 | + end | ||
26 | + | ||
27 | +end |
plugins/proposals_discussion/test/unit/proposal_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | -class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | 3 | +class ProposalTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @profile = fast_create(Community) | 6 | @profile = fast_create(Community) |
7 | + @person = fast_create(Person) | ||
7 | @proposal = ProposalsDiscussionPlugin::Proposal.new(:name => 'test', :profile => @profile) | 8 | @proposal = ProposalsDiscussionPlugin::Proposal.new(:name => 'test', :profile => @profile) |
9 | + @proposal.created_by = @person | ||
8 | end | 10 | end |
9 | 11 | ||
10 | - attr_reader :profile, :proposal | 12 | + attr_reader :profile, :proposal, :person |
11 | 13 | ||
12 | should 'save a proposal' do | 14 | should 'save a proposal' do |
13 | proposal.abstract = 'abstract' | 15 | proposal.abstract = 'abstract' |
@@ -19,4 +21,12 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | @@ -19,4 +21,12 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | ||
19 | assert proposal.errors['abstract'].present? | 21 | assert proposal.errors['abstract'].present? |
20 | end | 22 | end |
21 | 23 | ||
24 | + should 'allow edition if user is the author' do | ||
25 | + assert proposal.allow_edit?(person) | ||
26 | + end | ||
27 | + | ||
28 | + should 'do not allow edition if user is not the author' do | ||
29 | + assert !proposal.allow_edit?(fast_create(Person)) | ||
30 | + end | ||
31 | + | ||
22 | end | 32 | end |
plugins/proposals_discussion/test/unit/proposals_discussion_plugin_test.rb
@@ -26,9 +26,15 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | @@ -26,9 +26,15 @@ class ProposalsDiscussionPluginTest < ActiveSupport::TestCase | ||
26 | assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion | 26 | assert_not_includes plugin.content_types, ProposalsDiscussionPlugin::Discussion |
27 | end | 27 | end |
28 | 28 | ||
29 | - should 'return Proposal as a content type if parent is a Discussion' do | 29 | + should 'return Topic as a content type if parent is a Discussion' do |
30 | parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) | 30 | parent = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => @profile.id) |
31 | @params[:parent_id] = parent.id | 31 | @params[:parent_id] = parent.id |
32 | + assert_includes plugin.content_types, ProposalsDiscussionPlugin::Topic | ||
33 | + end | ||
34 | + | ||
35 | + should 'return Proposal as a content type if parent is a Topic' do | ||
36 | + parent = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => @profile.id) | ||
37 | + @params[:parent_id] = parent.id | ||
32 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal | 38 | assert_includes plugin.content_types, ProposalsDiscussionPlugin::Proposal |
33 | end | 39 | end |
34 | 40 |
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class TopicTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = fast_create(Community) | ||
7 | + @topic = ProposalsDiscussionPlugin::Topic.new(:name => 'test', :profile => @profile) | ||
8 | + end | ||
9 | + | ||
10 | + attr_reader :profile, :topic | ||
11 | + | ||
12 | + should 'return list of proposals' do | ||
13 | + topic.save! | ||
14 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | ||
15 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | ||
16 | + assert_equivalent [proposal1, proposal2], topic.proposals | ||
17 | + end | ||
18 | + | ||
19 | + should 'allow any user to create proposals in a topic' do | ||
20 | + assert topic.allow_create?(Person.new) | ||
21 | + end | ||
22 | + | ||
23 | + should 'return list of comments' do | ||
24 | + topic.save! | ||
25 | + proposal = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | ||
26 | + comment1 = fast_create(Comment, :source_id => proposal.id) | ||
27 | + comment2 = fast_create(Comment, :source_id => proposal.id) | ||
28 | + assert_equivalent [comment1, comment2], topic.proposals_comments | ||
29 | + end | ||
30 | + | ||
31 | + should 'return list of authors' do | ||
32 | + topic.save! | ||
33 | + author1 = fast_create(Person) | ||
34 | + author2 = fast_create(Person) | ||
35 | + fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :created_by_id => author1) | ||
36 | + fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :created_by_id => author2) | ||
37 | + assert_equivalent [author1, author2], topic.proposals_authors | ||
38 | + end | ||
39 | + | ||
40 | + should 'return most active participants' do | ||
41 | + topic.save! | ||
42 | + author1 = fast_create(Person) | ||
43 | + author2 = fast_create(Person) | ||
44 | + fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :created_by_id => author1) | ||
45 | + fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :created_by_id => author2) | ||
46 | + fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id, :created_by_id => author2) | ||
47 | + assert_equal [author2, author1], topic.most_active_participants | ||
48 | + end | ||
49 | + | ||
50 | +end |
plugins/proposals_discussion/views/content_viewer/_proposal_card.html.erb
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <%= link_to proposal_card.name, proposal_card.view_url %> | 4 | <%= link_to proposal_card.name, proposal_card.view_url %> |
5 | </div> | 5 | </div> |
6 | <div class="abstract"> | 6 | <div class="abstract"> |
7 | - <%= link_to strip_tags(proposal_card.lead), proposal_card.view_url %> | 7 | + <%= link_to strip_tags(proposal_card.abstract), proposal_card.view_url %> |
8 | </div> | 8 | </div> |
9 | </div> | 9 | </div> |
10 | <div class="score"> | 10 | <div class="score"> |
plugins/proposals_discussion/views/content_viewer/_proposals_list.html.erb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | }); | 9 | }); |
10 | </script> | 10 | </script> |
11 | 11 | ||
12 | -<% private_proposals = @page.proposals.private(user)%> | 12 | +<% private_proposals = user ? @page.proposals.private(user) : [] %> |
13 | <% unless private_proposals.empty? %> | 13 | <% unless private_proposals.empty? %> |
14 | <div class="private-proposals"> | 14 | <div class="private-proposals"> |
15 | <h5><%= _('My private proposals') %></h5> | 15 | <h5><%= _('My private proposals') %></h5> |
@@ -18,7 +18,6 @@ | @@ -18,7 +18,6 @@ | ||
18 | <% end %> | 18 | <% end %> |
19 | 19 | ||
20 | <div class="proposals"> | 20 | <div class="proposals"> |
21 | - <h5><%= _('Proposals') %></h5> | ||
22 | <div class="more"> | 21 | <div class="more"> |
23 | <img src="/images/loading.gif" alt="Loading" /><%= _("Loading...") %> | 22 | <img src="/images/loading.gif" alt="Loading" /><%= _("Loading...") %> |
24 | <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %> | 23 | <%= link_to '', url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier }) %> |
plugins/proposals_discussion/views/content_viewer/_proposals_list_content.html.erb
1 | +<% unless proposals.empty? %> | ||
2 | + <h5><%= _('Proposals') %></h5> | ||
3 | +<% end %> | ||
4 | + | ||
1 | <%= render :partial => 'content_viewer/proposal_card', :collection => proposals %> | 5 | <%= render :partial => 'content_viewer/proposal_card', :collection => proposals %> |
2 | 6 | ||
3 | <div class="more"> | 7 | <div class="more"> |
4 | - <%= link_to _('More'), url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :page => next_page }) %> | 8 | + <%= link_to _('More'), url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :page => page }) %> |
5 | </div> | 9 | </div> |
plugins/proposals_discussion/views/content_viewer/topic.html.erb
@@ -24,4 +24,10 @@ | @@ -24,4 +24,10 @@ | ||
24 | </span> | 24 | </span> |
25 | </div> | 25 | </div> |
26 | 26 | ||
27 | +<div class="actions"> | ||
28 | + <%= link_to url_for({:controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => @page.id}), :class => 'button with-text icon-add' do %> | ||
29 | + <strong><%= _("Send my proposal") %></strong> | ||
30 | + <% end %> | ||
31 | +</div> | ||
32 | + | ||
27 | <%= render :partial => 'content_viewer/proposals_list', :locals => {:holder => @page} %> | 33 | <%= render :partial => 'content_viewer/proposals_list', :locals => {:holder => @page} %> |