Commit 3a4c55178821e4fa1514a0b0c20c298f9bacfe64
Exists in
master
and in
29 other branches
Merge branch 'stable'
Showing
15 changed files
with
89 additions
and
8 deletions
Show diff stats
app/controllers/public/account_controller.rb
| ... | ... | @@ -5,6 +5,7 @@ class AccountController < ApplicationController |
| 5 | 5 | require_ssl :except => [ :login_popup, :logout_popup, :wizard, :profile_details ] |
| 6 | 6 | |
| 7 | 7 | before_filter :login_required, :only => [:activation_question, :accept_terms, :activate_enterprise] |
| 8 | + before_filter :redirect_if_logged_in, :only => [:login, :signup] | |
| 8 | 9 | |
| 9 | 10 | # say something nice, you goof! something sweet. |
| 10 | 11 | def index |
| ... | ... | @@ -291,4 +292,10 @@ class AccountController < ApplicationController |
| 291 | 292 | end |
| 292 | 293 | end |
| 293 | 294 | |
| 295 | + def redirect_if_logged_in | |
| 296 | + if logged_in? | |
| 297 | + go_to_initial_page | |
| 298 | + end | |
| 299 | + end | |
| 300 | + | |
| 294 | 301 | end | ... | ... |
app/controllers/public/content_viewer_controller.rb
| ... | ... | @@ -82,7 +82,8 @@ class ContentViewerController < ApplicationController |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | 84 | if @page.folder? && @page.view_as == 'image_gallery' |
| 85 | - @images = @page.images.paginate(:per_page => 12, :page => params[:npage]) | |
| 85 | + @images = @page.images | |
| 86 | + @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] | |
| 86 | 87 | end |
| 87 | 88 | |
| 88 | 89 | @comments = @page.comments(true) |
| ... | ... | @@ -114,4 +115,7 @@ class ContentViewerController < ApplicationController |
| 114 | 115 | redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] |
| 115 | 116 | end |
| 116 | 117 | |
| 118 | + def per_page | |
| 119 | + 12 | |
| 120 | + end | |
| 117 | 121 | end | ... | ... |
app/models/add_friend.rb
| ... | ... | @@ -6,6 +6,8 @@ class AddFriend < Task |
| 6 | 6 | |
| 7 | 7 | validates_uniqueness_of :target_id, :scope => [ :requestor_id ] |
| 8 | 8 | |
| 9 | + validates_length_of :group_for_person, :group_for_friend, :maximum => 150, :allow_nil => true | |
| 10 | + | |
| 9 | 11 | alias :person :requestor |
| 10 | 12 | alias :person= :requestor= |
| 11 | 13 | ... | ... |
app/models/task_mailer.rb
| ... | ... | @@ -22,15 +22,15 @@ class TaskMailer < ActionMailer::Base |
| 22 | 22 | :target => task.target.name, |
| 23 | 23 | :message => msg, |
| 24 | 24 | :environment => task.requestor.environment.name, |
| 25 | - :url => url_for(:host => task.requestor.environment.default_hostname, :controller => 'home'), | |
| 25 | + :url => generate_environment_url(task, :controller => 'home'), | |
| 26 | 26 | :tasks_url => url_for_tasks_list |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | 29 | def invitation_notification(task) |
| 30 | 30 | msg = task.message |
| 31 | 31 | msg = msg.gsub(/<user>/, task.requestor.name) |
| 32 | - msg = msg.gsub(/<friend>/, task.friend_name) | |
| 33 | - msg = msg.gsub(/<url>/, url_for(:host => task.requestor.environment.default_hostname, :controller => 'account', :action => 'signup', :invitation_code => task.code)) | |
| 32 | + msg = msg.gsub(/<friend>/, task.friend_name.blank? ? task.friend_email : task.friend_name) | |
| 33 | + msg = msg.gsub(/<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)) | |
| 34 | 34 | |
| 35 | 35 | recipients task.friend_email |
| 36 | 36 | |
| ... | ... | @@ -66,4 +66,8 @@ class TaskMailer < ActionMailer::Base |
| 66 | 66 | "#{task.requestor.environment.name} <#{task.requestor.environment.contact_email}>" |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | + def generate_environment_url(task, url = {}) | |
| 70 | + url_for(Noosfero.url_options.merge(:host => task.requestor.environment.default_hostname).merge(url)) | |
| 71 | + end | |
| 72 | + | |
| 69 | 73 | end | ... | ... |
app/views/friends/add.rhtml
| ... | ... | @@ -15,7 +15,7 @@ |
| 15 | 15 | |
| 16 | 16 | <div> |
| 17 | 17 | <%= __('Classify your new friend %s: ') % @friend.name %> |
| 18 | - <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups) %> | |
| 18 | + <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups, :maxlength => 150) %> | |
| 19 | 19 | <p> |
| 20 | 20 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
| 21 | 21 | </p> | ... | ... |
app/views/tasks/_add_friend.rhtml
| ... | ... | @@ -27,7 +27,7 @@ |
| 27 | 27 | <%= _('Classify your new friend:') %> |
| 28 | 28 | <%= text_field_with_local_autocomplete("task[group_for_friend]", |
| 29 | 29 | profile.suggested_friend_groups, |
| 30 | - :id => "field-group-for-friend-#{task.id}") %> | |
| 30 | + {:id => "field-group-for-friend-#{task.id}", :maxlength => 150}) %> | |
| 31 | 31 | <p class="friend-classify-suggestions"> |
| 32 | 32 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
| 33 | 33 | </p> | ... | ... |
features/login.feature
| ... | ... | @@ -39,3 +39,8 @@ Feature: login |
| 39 | 39 | | Password | 123456 | |
| 40 | 40 | When I press "Log in" |
| 41 | 41 | Then I should be on Joao Silva's control panel |
| 42 | + | |
| 43 | + Scenario: be redirected if user goes to login page and is logged | |
| 44 | + Given I am logged in as "joaosilva" | |
| 45 | + And I go to login page | |
| 46 | + Then I should be on Joao Silva's control panel | ... | ... |
features/publish_article.feature
| ... | ... | @@ -40,6 +40,7 @@ Feature: publish article |
| 40 | 40 | And I follow "Spread" |
| 41 | 41 | And I check "Sample Community" |
| 42 | 42 | And I press "Publish" |
| 43 | + And I am not logged in | |
| 43 | 44 | And I am logged in as "mariasilva" |
| 44 | 45 | And "Maria Silva" is a member of "Sample Community" |
| 45 | 46 | And I am on Maria Silva's control panel | ... | ... |
features/signup.feature
| ... | ... | @@ -15,3 +15,10 @@ Feature: signup |
| 15 | 15 | And I press "Sign up" |
| 16 | 16 | Then I should see "Thanks for signing up!" |
| 17 | 17 | |
| 18 | + Scenario: be redirected if user goes to signup page and is logged | |
| 19 | + Given the following users | |
| 20 | + | login | name | | |
| 21 | + | joaosilva | Joao Silva | | |
| 22 | + Given I am logged in as "joaosilva" | |
| 23 | + And I go to signup page | |
| 24 | + Then I should be on Joao Silva's control panel | ... | ... |
features/support/paths.rb
test/functional/account_controller_test.rb
| ... | ... | @@ -36,6 +36,7 @@ class AccountControllerTest < Test::Unit::TestCase |
| 36 | 36 | should 'redirect to where user was on login' do |
| 37 | 37 | @request.env["HTTP_REFERER"] = '/bli' |
| 38 | 38 | u = new_user |
| 39 | + @controller.stubs(:logged_in?).returns(false) | |
| 39 | 40 | post :login, :user => {:login => 'quire', :password => 'quire'} |
| 40 | 41 | |
| 41 | 42 | assert_redirected_to '/bli' |
| ... | ... | @@ -283,6 +284,7 @@ class AccountControllerTest < Test::Unit::TestCase |
| 283 | 284 | assert_difference User, :count do |
| 284 | 285 | new_user(:login => 'user1', :email => 'user@example.com') |
| 285 | 286 | assert assigns(:user).valid? |
| 287 | + @controller.stubs(:logged_in?).returns(false) | |
| 286 | 288 | new_user(:login => 'user2', :email => 'user@example.com') |
| 287 | 289 | assert assigns(:user).errors.on(:email) |
| 288 | 290 | end | ... | ... |
test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -804,6 +804,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
| 804 | 804 | assert_template 'slideshow' |
| 805 | 805 | end |
| 806 | 806 | |
| 807 | + should 'display all images from profile in the slideshow' do | |
| 808 | + @controller.stubs(:per_page).returns(1) | |
| 809 | + folder = Folder.create!(:name => 'gallery', :profile => profile, :view_as => 'image_gallery') | |
| 810 | + | |
| 811 | + fixture_filename = '/files/other-pic.jpg' | |
| 812 | + filename = RAILS_ROOT + '/test/fixtures' + fixture_filename | |
| 813 | + system('echo "image for test" | convert -background yellow -page 32x32 text:- %s' % filename) | |
| 814 | + image1 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload(fixture_filename, 'image/jpg')) | |
| 815 | + | |
| 816 | + image2 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
| 817 | + get :view_page, :profile => profile.identifier, :page => folder.explode_path, :slideshow => true | |
| 818 | + | |
| 819 | + assert_equal 2, assigns(:images).size | |
| 820 | + end | |
| 821 | + | |
| 807 | 822 | should 'display source from article' do |
| 808 | 823 | profile.articles << TextileArticle.new(:name => "Article one", :profile => profile, :source => 'http://www.original-source.invalid') |
| 809 | 824 | get :view_page, :profile => profile.identifier, :page => ['article-one'] | ... | ... |
test/integration/enterprise_registration_test.rb
| ... | ... | @@ -44,10 +44,12 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest |
| 44 | 44 | |
| 45 | 45 | code = CreateEnterprise.find(:first, :order => 'id desc').code |
| 46 | 46 | |
| 47 | + post '/account/logout' | |
| 48 | + | |
| 47 | 49 | # steps done by the validator |
| 48 | 50 | validator = create_user_with_permission('validator', 'validate_enterprise', org) |
| 49 | 51 | login 'validator', 'validator' |
| 50 | - | |
| 52 | + | |
| 51 | 53 | get "/myprofile/myorg/enterprise_validation" |
| 52 | 54 | assert_response :success |
| 53 | 55 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myorg/enterprise_validation/details/#{code}" } | ... | ... |
test/unit/add_friend_test.rb
| ... | ... | @@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase |
| 100 | 100 | end |
| 101 | 101 | end |
| 102 | 102 | |
| 103 | + should 'limit "group for person" number of characters' do | |
| 104 | + #Max value is 150 | |
| 105 | + big_word = 'a' * 155 | |
| 106 | + task = AddFriend.new | |
| 107 | + | |
| 108 | + task.group_for_person = big_word | |
| 109 | + task.valid? | |
| 110 | + assert task.errors[:group_for_person] | |
| 111 | + | |
| 112 | + task.group_for_person = 'short name' | |
| 113 | + task.valid? | |
| 114 | + assert !task.errors[:group_for_person] | |
| 115 | + end | |
| 116 | + | |
| 117 | + should 'limit "group for friend" number of characters' do | |
| 118 | + #Max value is 150 | |
| 119 | + big_word = 'a' * 155 | |
| 120 | + task = AddFriend.new | |
| 121 | + | |
| 122 | + task.group_for_friend = big_word | |
| 123 | + task.valid? | |
| 124 | + assert task.errors[:group_for_friend] | |
| 125 | + | |
| 126 | + task.group_for_friend = 'short name' | |
| 127 | + task.valid? | |
| 128 | + assert !task.errors[:group_for_friend] | |
| 129 | + end | |
| 130 | + | |
| 131 | + | |
| 103 | 132 | end | ... | ... |
test/unit/task_mailer_test.rb
| ... | ... | @@ -113,7 +113,7 @@ class TaskMailerTest < Test::Unit::TestCase |
| 113 | 113 | |
| 114 | 114 | task.expects(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') |
| 115 | 115 | task.expects(:friend_email).returns('friend@exemple.com') |
| 116 | - task.expects(:friend_name).returns('friend name') | |
| 116 | + task.expects(:friend_name).returns('friend name').at_least_once | |
| 117 | 117 | |
| 118 | 118 | requestor = mock() |
| 119 | 119 | requestor.expects(:name).returns('my name') | ... | ... |