Commit 1f9bf65ef48ceaacd9bc00a06c95824869c471d9
0 parents
Exists in
master
initial plugin infraestruture
Showing
9 changed files
with
135 additions
and
0 deletions
Show diff stats
1 | +++ a/controllers/insight_plugin_admin_controller.rb | |
... | ... | @@ -0,0 +1,16 @@ |
1 | +class InsightPluginAdminController < PluginAdminController | |
2 | + | |
3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
4 | + | |
5 | + def index | |
6 | + if request.post? | |
7 | + if @environment.update_attributes(params[:environment]) | |
8 | + session[:notice] = _('Insight plugin settings updated successfully.') | |
9 | + else | |
10 | + session[:notice] = _('Insight plugin settings could not be saved.') | |
11 | + end | |
12 | + redirect_to :controller => 'plugins', :action => 'index' | |
13 | + end | |
14 | + end | |
15 | + | |
16 | +end | ... | ... |
1 | +++ a/lib/insight_plugin.rb | |
... | ... | @@ -0,0 +1,19 @@ |
1 | +class InsightPlugin < Noosfero::Plugin | |
2 | + | |
3 | + def self.plugin_name | |
4 | + "Insight" | |
5 | + end | |
6 | + | |
7 | + def self.plugin_description | |
8 | + _("Add insight system to your Noosfero's environment") | |
9 | + end | |
10 | + | |
11 | + def body_ending | |
12 | + domain = context.environment.insight_domain | |
13 | + code = context.environment.insight_code | |
14 | + unless domain.blank? || code.blank? | |
15 | + expanded_template('insight-code.rhtml',{:domain => domain, :code => code}) | |
16 | + end | |
17 | + end | |
18 | + | |
19 | +end | ... | ... |
1 | +++ a/test/functional/insight_plugin_admin_controller_test.rb | |
... | ... | @@ -0,0 +1,27 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class InsightPluginAdminControllerTest < ActionController::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @environment = Environment.default | |
7 | + user_login = create_admin_user(@environment) | |
8 | + login_as(user_login) | |
9 | + @environment.enabled_plugins = ['InsightPlugin'] | |
10 | + @environment.save! | |
11 | + end | |
12 | + | |
13 | + should 'access index action' do | |
14 | + get :index | |
15 | + assert_template 'index' | |
16 | + assert_response :success | |
17 | + end | |
18 | + | |
19 | + should 'update insight plugin settings' do | |
20 | + assert_nil @environment.reload.insight_domain | |
21 | + assert_nil @environment.reload.insight_code | |
22 | + post :index, :environment => { :insight_domain => 'http://something', :insight_code => 'salsdfkldsjflw43rewr' } | |
23 | + assert_not_nil @environment.reload.insight_domain | |
24 | + assert_not_nil @environment.reload.insight_code | |
25 | + end | |
26 | + | |
27 | +end | ... | ... |
1 | +++ a/test/unit/environment_test.rb | |
... | ... | @@ -0,0 +1,13 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class EnvironmentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'extends Environment with attr insight_domain' do | |
6 | + assert_respond_to Environment.new, :insight_domain | |
7 | + end | |
8 | + | |
9 | + should 'extends Environment with attr insight_code' do | |
10 | + assert_respond_to Environment.new, :insight_code | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
1 | +++ a/test/unit/insight_plugin_test.rb | |
... | ... | @@ -0,0 +1,36 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class InsightPluginTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @plugin = InsightPlugin.new | |
7 | + @context = mock() | |
8 | + @plugin.context = @context | |
9 | + @environment = Environment.new | |
10 | + @context.stubs(:environment).returns(@environment) | |
11 | + end | |
12 | + | |
13 | + attr_accessor :plugin, :environment | |
14 | + | |
15 | + should 'add content at the body ending unless domain and site_id are blank' do | |
16 | + environment.insight_domain = 'insight.domain.example.com' | |
17 | + environment.insight_code = 5 | |
18 | + plugin.stubs(:expanded_template).returns('content') | |
19 | + assert_equal 'content', plugin.body_ending | |
20 | + end | |
21 | + | |
22 | + should 'not add any content at the body ending if domain is blank' do | |
23 | + environment.insight_domain = nil | |
24 | + environment.insight_code = 5 | |
25 | + plugin.stubs(:expanded_template).returns('content') | |
26 | + assert_equal nil, plugin.body_ending | |
27 | + end | |
28 | + | |
29 | + should 'not add any content at the body ending if site_id is blank' do | |
30 | + environment.insight_domain = 'insight.domain.example.com' | |
31 | + environment.insight_code = nil | |
32 | + plugin.stubs(:expanded_template).returns('content') | |
33 | + assert_equal nil, plugin.body_ending | |
34 | + end | |
35 | + | |
36 | +end | ... | ... |
1 | +++ a/views/insight_plugin_admin/index.html.erb | |
... | ... | @@ -0,0 +1,13 @@ |
1 | +<h1><%= _("Insight plugin settings") %></h1> | |
2 | + | |
3 | +<%= form_for(:environment) do |f| %> | |
4 | + | |
5 | + <%= labelled_form_field _('Insight domain'), f.text_field(:insight_domain) %> | |
6 | + | |
7 | + <%= labelled_form_field _('Insight Code'), f.text_field(:insight_code) %> | |
8 | + | |
9 | + <% button_bar do %> | |
10 | + <%= submit_button(:save, c_('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
11 | + <% end %> | |
12 | + | |
13 | +<% end %> | ... | ... |