diff --git a/controllers/insight_plugin_admin_controller.rb b/controllers/insight_plugin_admin_controller.rb new file mode 100644 index 0000000..3144242 --- /dev/null +++ b/controllers/insight_plugin_admin_controller.rb @@ -0,0 +1,16 @@ +class InsightPluginAdminController < PluginAdminController + + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def index + if request.post? + if @environment.update_attributes(params[:environment]) + session[:notice] = _('Insight plugin settings updated successfully.') + else + session[:notice] = _('Insight plugin settings could not be saved.') + end + redirect_to :controller => 'plugins', :action => 'index' + end + end + +end diff --git a/lib/ext/environment.rb b/lib/ext/environment.rb new file mode 100644 index 0000000..7413524 --- /dev/null +++ b/lib/ext/environment.rb @@ -0,0 +1,7 @@ +require_dependency 'environment' + +class Environment + settings_items :insight_domain + settings_items :insight_code + attr_accessible :insight_domain, :insight_code +end diff --git a/lib/insight_plugin.rb b/lib/insight_plugin.rb new file mode 100644 index 0000000..efb6795 --- /dev/null +++ b/lib/insight_plugin.rb @@ -0,0 +1,19 @@ +class InsightPlugin < Noosfero::Plugin + + def self.plugin_name + "Insight" + end + + def self.plugin_description + _("Add insight system to your Noosfero's environment") + end + + def body_ending + domain = context.environment.insight_domain + code = context.environment.insight_code + unless domain.blank? || code.blank? + expanded_template('insight-code.rhtml',{:domain => domain, :code => code}) + end + end + +end diff --git a/test/functional/insight_plugin_admin_controller_test.rb b/test/functional/insight_plugin_admin_controller_test.rb new file mode 100644 index 0000000..4d04ed8 --- /dev/null +++ b/test/functional/insight_plugin_admin_controller_test.rb @@ -0,0 +1,27 @@ +require_relative '../test_helper' + +class InsightPluginAdminControllerTest < ActionController::TestCase + + def setup + @environment = Environment.default + user_login = create_admin_user(@environment) + login_as(user_login) + @environment.enabled_plugins = ['InsightPlugin'] + @environment.save! + end + + should 'access index action' do + get :index + assert_template 'index' + assert_response :success + end + + should 'update insight plugin settings' do + assert_nil @environment.reload.insight_domain + assert_nil @environment.reload.insight_code + post :index, :environment => { :insight_domain => 'http://something', :insight_code => 'salsdfkldsjflw43rewr' } + assert_not_nil @environment.reload.insight_domain + assert_not_nil @environment.reload.insight_code + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..70322cf --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1 @@ +require_relative '../../../test/test_helper' diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb new file mode 100644 index 0000000..152d3ee --- /dev/null +++ b/test/unit/environment_test.rb @@ -0,0 +1,13 @@ +require_relative '../test_helper' + +class EnvironmentTest < ActiveSupport::TestCase + + should 'extends Environment with attr insight_domain' do + assert_respond_to Environment.new, :insight_domain + end + + should 'extends Environment with attr insight_code' do + assert_respond_to Environment.new, :insight_code + end + +end diff --git a/test/unit/insight_plugin_test.rb b/test/unit/insight_plugin_test.rb new file mode 100644 index 0000000..47be1b8 --- /dev/null +++ b/test/unit/insight_plugin_test.rb @@ -0,0 +1,36 @@ +require_relative '../test_helper' + +class InsightPluginTest < ActiveSupport::TestCase + + def setup + @plugin = InsightPlugin.new + @context = mock() + @plugin.context = @context + @environment = Environment.new + @context.stubs(:environment).returns(@environment) + end + + attr_accessor :plugin, :environment + + should 'add content at the body ending unless domain and site_id are blank' do + environment.insight_domain = 'insight.domain.example.com' + environment.insight_code = 5 + plugin.stubs(:expanded_template).returns('content') + assert_equal 'content', plugin.body_ending + end + + should 'not add any content at the body ending if domain is blank' do + environment.insight_domain = nil + environment.insight_code = 5 + plugin.stubs(:expanded_template).returns('content') + assert_equal nil, plugin.body_ending + end + + should 'not add any content at the body ending if site_id is blank' do + environment.insight_domain = 'insight.domain.example.com' + environment.insight_code = nil + plugin.stubs(:expanded_template).returns('content') + assert_equal nil, plugin.body_ending + end + +end diff --git a/views/insight-code.rhtml b/views/insight-code.rhtml new file mode 100644 index 0000000..563515c --- /dev/null +++ b/views/insight-code.rhtml @@ -0,0 +1,3 @@ + + + diff --git a/views/insight_plugin_admin/index.html.erb b/views/insight_plugin_admin/index.html.erb new file mode 100644 index 0000000..0323127 --- /dev/null +++ b/views/insight_plugin_admin/index.html.erb @@ -0,0 +1,13 @@ +