diff --git a/plugins/google_analytics/lib/ext/profile.rb b/plugins/google_analytics/lib/ext/profile.rb index 8c966a1..acf834c 100644 --- a/plugins/google_analytics/lib/ext/profile.rb +++ b/plugins/google_analytics/lib/ext/profile.rb @@ -2,4 +2,9 @@ require_dependency 'profile' class Profile settings_items :google_analytics_profile_id + attr_accessible :google_analytics_profile_id + + descendants.each do |descendant| + descendant.attr_accessible :google_analytics_profile_id + end end diff --git a/plugins/google_analytics/lib/google_analytics_plugin.rb b/plugins/google_analytics/lib/google_analytics_plugin.rb index 1008c59..dac51dc 100644 --- a/plugins/google_analytics/lib/google_analytics_plugin.rb +++ b/plugins/google_analytics/lib/google_analytics_plugin.rb @@ -19,12 +19,15 @@ class GoogleAnalyticsPlugin < Noosfero::Plugin def head_ending unless profile_id.blank? - expanded_template('tracking-code.rhtml',{:profile_id => profile_id}) + expanded_template('tracking-code.html.erb',{:profile_id => profile_id}) end end def profile_editor_extras - expanded_template('profile-editor-extras.rhtml',{:profile_id => profile_id}) + analytics_id = profile_id + lambda { + render :file => 'profile-editor-extras', :locals => { :profile_id => analytics_id } + } end end diff --git a/plugins/google_analytics/test/functional/profile_editor_controller_test.rb b/plugins/google_analytics/test/functional/profile_editor_controller_test.rb new file mode 100644 index 0000000..1be3bb4 --- /dev/null +++ b/plugins/google_analytics/test/functional/profile_editor_controller_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' +require 'profile_editor_controller' + +# Re-raise errors caught by the controller. +class ProfileEditorController; def rescue_action(e) raise e end; end + +class ProfileEditorControllerTest < ActionController::TestCase + + def setup + @controller = ProfileEditorController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @profile = create_user('default_user').person + login_as(@profile.identifier) + Environment.default.enable_plugin(GoogleAnalyticsPlugin.name) + end + + attr_accessor :profile + + should 'add extra fields to profile editor info and settings' do + get :edit, :profile => profile.identifier + assert_tag_in_string @response.body, :tag => 'label', :content => /Google Analytics/, :attributes => { :for => 'profile_data_google_analytics_profile_id' } + assert_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'profile_data_google_analytics_profile_id' } + end + + should 'save code filled in on field' do + post :edit, :profile => profile.identifier, :profile_data => {:google_analytics_profile_id => 12345678} + assert_equal '12345678', Person.find(profile.id).google_analytics_profile_id + end + +end diff --git a/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb index 10394b3..a46a5e2 100644 --- a/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb +++ b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb @@ -27,11 +27,6 @@ class GoogleAnalyticsPluginTest < ActiveSupport::TestCase assert_equal 'content', @plugin.head_ending end - should 'add extra fields to profile editor info and settings' do - assert_tag_in_string @plugin.profile_editor_extras, - :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10} - end - should 'extends Profile with attr google_analytics_profile_id' do assert_respond_to Profile.new, :google_analytics_profile_id end diff --git a/plugins/google_analytics/views/profile-editor-extras.html.erb b/plugins/google_analytics/views/profile-editor-extras.html.erb new file mode 100644 index 0000000..7dba5a2 --- /dev/null +++ b/plugins/google_analytics/views/profile-editor-extras.html.erb @@ -0,0 +1,3 @@ +

<%= c_('Statistics') %>

+<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %> +<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %> diff --git a/plugins/google_analytics/views/profile-editor-extras.rhtml b/plugins/google_analytics/views/profile-editor-extras.rhtml deleted file mode 100644 index 4073c6d..0000000 --- a/plugins/google_analytics/views/profile-editor-extras.rhtml +++ /dev/null @@ -1,5 +0,0 @@ -<% extend ApplicationHelper %> - -

<%= c_('Statistics') %>

-<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %> -<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %> diff --git a/plugins/google_analytics/views/tracking-code.html.erb b/plugins/google_analytics/views/tracking-code.html.erb new file mode 100644 index 0000000..c233ce9 --- /dev/null +++ b/plugins/google_analytics/views/tracking-code.html.erb @@ -0,0 +1,9 @@ + diff --git a/plugins/google_analytics/views/tracking-code.rhtml b/plugins/google_analytics/views/tracking-code.rhtml deleted file mode 100644 index 8b89062..0000000 --- a/plugins/google_analytics/views/tracking-code.rhtml +++ /dev/null @@ -1,10 +0,0 @@ - -- libgit2 0.21.2