email_article_plugin_myprofile_controller_test.rb
2.14 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
require_relative '../../../../test/test_helper'
class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase
def setup
Environment.delete_all
@environment = Environment.new(:name => 'testenv', :is_default => true)
@environment.enabled_plugins = ['EmailArticlePlugin']
@environment.save!
end
should 'be able to deliver mail as profile admin' do
@profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community')
@user = create_user('testinguser')
login_as(@user.login)
@profile.add_admin(@user.person)
@article = @profile.articles.create!(:name => 'a test article')
@article.author = @user.person
@article.save
get :send_email, :profile => @profile.identifier, :id => @article.id
assert_response :success
end
should 'deny access to email article unless if profile admin' do
@profile = Community.create!(:name => 'Another community', :identifier => 'another-community')
@user = create_user('user-out-of-the-community')
login_as(@user.login)
@article = @profile.articles.create!(:name => 'a test article')
@article.author = @user.person
@article.save
get :send_email, :profile => @profile.identifier, :id => @article.id
assert_response 403
end
should 'show button at article_extra_toolbar_buttons' do
@profile = Community.create!(:name => 'Another community', :identifier => 'another-community')
@user = create_user('user-out-of-the-community')
login_as(@user.login)
@article = TextArticle.new
@article.name = 'a test article'
@article.profile = @profile
@article.author = @user.person
@article.save
@plugin = EmailArticlePlugin.new
@plugin.stubs(:link_to_remote).returns(true)
send_mail_button = @plugin.article_extra_toolbar_buttons(@article)
self.stubs(:profile).returns(@profile)
self.stubs(:user).returns(@user)
# self.stubs(:page).returns(@article)
@user.stubs(:is_admin?).returns(true)
self.stubs(:link_to_remote).returns("send mail button")
# @plugin.class_eval{@page=2}
html = self.instance_eval(&send_mail_button)
assert_equal html, "send mail button"
end
end