From a729e69f15d0b96786e30182c5ef97b86a0cbf68 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Fri, 9 Oct 2015 14:51:25 -0300 Subject: [PATCH] newsletter: Also search blogs by people's and enterprises' names --- plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb | 8 ++++---- plugins/newsletter/features/newsletter_plugin.feature | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- plugins/newsletter/views/newsletter_plugin_admin/index.html.erb | 6 +++--- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb b/plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb index 20e3b40..5e912a5 100644 --- a/plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb +++ b/plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb @@ -30,14 +30,14 @@ class NewsletterPluginAdminController < PluginAdminController end #TODO: Make this query faster - def search_communities - communities = environment.communities + def search_profiles + profiles = environment.profiles blogs = Blog.joins(:profile).where(profiles: {environment_id: environment.id}) - found_communities = find_by_contents(:communities, environment, communities, params['q'], {:page => 1})[:results] + found_profiles = find_by_contents(:profiles, environment, profiles, params['q'], {:page => 1})[:results] found_blogs = find_by_contents(:blogs, environment, blogs, params['q'], {:page => 1})[:results] - results = (found_blogs + found_communities.map(&:blogs).flatten).uniq + results = (found_blogs + found_profiles.map(&:blogs).flatten).uniq render :text => results.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} }.to_json end diff --git a/plugins/newsletter/features/newsletter_plugin.feature b/plugins/newsletter/features/newsletter_plugin.feature index 927f1d1..6455a29 100644 --- a/plugins/newsletter/features/newsletter_plugin.feature +++ b/plugins/newsletter/features/newsletter_plugin.feature @@ -1,27 +1,21 @@ Feature: newsletter plugin Background: - Given the following users - | login | name | - | joaosilva | Joao Silva | - And I am logged in as "joaosilva" + Given I am logged in as admin Scenario: as admin I can configure plugin - Given I am logged in as admin When I go to the environment control panel And I follow "Plugins" Then I should see "Configuration" linking to "/admin/plugin/newsletter" Scenario: in the newsletter settings I can see the field to enable/disable - Given I am logged in as admin When I go to the environment control panel And I follow "Plugins" And I follow "Configuration" Then I should see "Enable send of newsletter to members on this environment" Scenario: redirect to newsletter visualization after save and visualize - Given I am logged in as admin - And "NewsletterPlugin" plugin is enabled + Given "NewsletterPlugin" plugin is enabled When I go to the environment control panel And I follow "Plugins" And I follow "Configuration" @@ -30,11 +24,58 @@ Feature: newsletter plugin And I should not see "Newsletter settings" Scenario: stay on newsletter settings page after save - Given I am logged in as admin - And "NewsletterPlugin" plugin is enabled + Given "NewsletterPlugin" plugin is enabled When I go to the environment control panel And I follow "Plugins" And I follow "Configuration" And I press "Save" Then I should see "Newsletter settings" And I should not see "If you can't view this email, click here" + + @selenium + Scenario: search community and select blog for newsletter + Given the following communities + | identifier | name | + | sample-community | Sample Community | + And the following blogs + | owner | name | + | sample-community | Sample Blog | + And "NewsletterPlugin" plugin is enabled + When I go to the environment control panel + And I follow "Plugins" + And I follow "Configuration" + And I type in "Sample Community" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community" + And I press "Save" + Then I should see "Sample Blog in Sample Community" + + @selenium + Scenario: search profile and select blog for newsletter + Given the following users + | login | name | + | joaosilva | Joao Silva | + And the following blogs + | owner | name | + | joaosilva | Joao Blog | + And "NewsletterPlugin" plugin is enabled + When I go to the environment control panel + And I follow "Plugins" + And I follow "Configuration" + And I type in "Silva" into autocomplete list "search-profiles" and I choose "Joao Blog in Joao Silva" + And I press "Save" + Then I should see "Joao Blog in Joao Silva" + + @selenium + Scenario: search blog and select it for newsletter + Given the following communities + | identifier | name | + | sample-community | Sample Community | + And the following blogs + | owner | name | + | sample-community | Sample Blog | + And "NewsletterPlugin" plugin is enabled + When I go to the environment control panel + And I follow "Plugins" + And I follow "Configuration" + And I type in "Sample Blog" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community" + And I press "Save" + Then I should see "Sample Blog in Sample Community" diff --git a/plugins/newsletter/views/newsletter_plugin_admin/index.html.erb b/plugins/newsletter/views/newsletter_plugin_admin/index.html.erb index d72fcef..91cc134 100644 --- a/plugins/newsletter/views/newsletter_plugin_admin/index.html.erb +++ b/plugins/newsletter/views/newsletter_plugin_admin/index.html.erb @@ -29,11 +29,11 @@ %>

<%= _('Blogs from which news will be compiled') %>

- <% search_action = url_for(:action => 'search_communities') %> + <% search_action = url_for(:action => 'search_profiles') %> <% selected_blogs = @blogs.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} } %> <%= token_input_field_tag( - 'newsletter[blog_ids]', 'search-communities', search_action, - { hint_text: _('Type in the communities\' or blogs\' names'), + 'newsletter[blog_ids]', 'search-profiles', search_action, + { hint_text: _('Type in the profiles\' or blogs\' names'), focus: false, pre_populate: selected_blogs }) %>
-- libgit2 0.21.2