diff --git a/lib/email_article_plugin.rb b/lib/email_article_plugin.rb index c5b15a5..ae614fd 100644 --- a/lib/email_article_plugin.rb +++ b/lib/email_article_plugin.rb @@ -8,13 +8,16 @@ class EmailArticlePlugin < Noosfero::Plugin _("A plugin that emails an article to the members of the community") end + def page + @page + end + def article_toolbar_extra_buttons label = _("Send article to members") htmlclass = _("button with-text icon-menu-mail") title = _("Email article to all community members") - - proc do - if !profile.blank? and !user.blank? and user.is_admin?(profile) and @page.kind_of?(TextArticle) + proc do + if !profile.blank? and !user.blank? and user.is_admin?(profile) and page.kind_of?(TextArticle) link_to_remote( label, { diff --git a/test/functional/email_article_plugin_myprofile_controller_test.rb b/test/functional/email_article_plugin_myprofile_controller_test.rb index 748bb9c..da6f178 100644 --- a/test/functional/email_article_plugin_myprofile_controller_test.rb +++ b/test/functional/email_article_plugin_myprofile_controller_test.rb @@ -16,7 +16,6 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase @profile.add_admin(@user.person) @article = @profile.articles.create!(:name => 'a test article') @article.author = @user.person - puts "---->" + @article.author_id.to_yaml @article.save get :send_email, :profile => @profile.identifier, :id => @article.id assert_response :success @@ -37,11 +36,21 @@ class EmailArticlePluginMyprofileControllerTest < ActionController::TestCase @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 = TextArticle.new + @article.name = 'a test article' + @article.profile = @profile @article.author = @user.person @article.save - ep = EmailArticlePlugin.new - ep.article_toolbar_extra_buttons.call - end - + @plugin = EmailArticlePlugin.new + @plugin.stubs(:link_to_remote).returns(true) + send_mail_button = @plugin.article_toolbar_extra_buttons + 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") + html = self.instance_eval(&send_mail_button) + assert_equal html, "send mail button" + end + end -- libgit2 0.21.2