Commit 9fd165ce461f45fe9e4d33fb7a05e5c27ca7df27

Authored by Daniela Feitosa
1 parent b501e2ce

fixes for google_analytics_plugin

- allow mass-assignment
- Replaced .rhtml by .html.erb
- updated script code
plugins/google_analytics/lib/ext/profile.rb
... ... @@ -2,4 +2,9 @@ require_dependency 'profile'
2 2  
3 3 class Profile
4 4 settings_items :google_analytics_profile_id
  5 + attr_accessible :google_analytics_profile_id
  6 +
  7 + descendants.each do |descendant|
  8 + descendant.attr_accessible :google_analytics_profile_id
  9 + end
5 10 end
... ...
plugins/google_analytics/lib/google_analytics_plugin.rb
... ... @@ -19,12 +19,15 @@ class GoogleAnalyticsPlugin < Noosfero::Plugin
19 19  
20 20 def head_ending
21 21 unless profile_id.blank?
22   - expanded_template('tracking-code.rhtml',{:profile_id => profile_id})
  22 + expanded_template('tracking-code.html.erb',{:profile_id => profile_id})
23 23 end
24 24 end
25 25  
26 26 def profile_editor_extras
27   - expanded_template('profile-editor-extras.rhtml',{:profile_id => profile_id})
  27 + analytics_id = profile_id
  28 + lambda {
  29 + render :file => 'profile-editor-extras', :locals => { :profile_id => analytics_id }
  30 + }
28 31 end
29 32  
30 33 end
... ...
plugins/google_analytics/test/functional/profile_editor_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require 'test_helper'
  2 +require 'profile_editor_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class ProfileEditorController; def rescue_action(e) raise e end; end
  6 +
  7 +class ProfileEditorControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @controller = ProfileEditorController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 + @profile = create_user('default_user').person
  14 + login_as(@profile.identifier)
  15 + Environment.default.enable_plugin(GoogleAnalyticsPlugin.name)
  16 + end
  17 +
  18 + attr_accessor :profile
  19 +
  20 + should 'add extra fields to profile editor info and settings' do
  21 + get :edit, :profile => profile.identifier
  22 + assert_tag_in_string @response.body, :tag => 'label', :content => /Google Analytics/, :attributes => { :for => 'profile_data_google_analytics_profile_id' }
  23 + assert_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'profile_data_google_analytics_profile_id' }
  24 + end
  25 +
  26 + should 'save code filled in on field' do
  27 + post :edit, :profile => profile.identifier, :profile_data => {:google_analytics_profile_id => 12345678}
  28 + assert_equal '12345678', Person.find(profile.id).google_analytics_profile_id
  29 + end
  30 +
  31 +end
... ...
plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
... ... @@ -27,11 +27,6 @@ class GoogleAnalyticsPluginTest &lt; ActiveSupport::TestCase
27 27 assert_equal 'content', @plugin.head_ending
28 28 end
29 29  
30   - should 'add extra fields to profile editor info and settings' do
31   - assert_tag_in_string @plugin.profile_editor_extras,
32   - :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10}
33   - end
34   -
35 30 should 'extends Profile with attr google_analytics_profile_id' do
36 31 assert_respond_to Profile.new, :google_analytics_profile_id
37 32 end
... ...
plugins/google_analytics/views/profile-editor-extras.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2><%= c_('Statistics') %></h2>
  2 +<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %>
  3 +<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %>
... ...
plugins/google_analytics/views/profile-editor-extras.rhtml
... ... @@ -1,5 +0,0 @@
1   -<% extend ApplicationHelper %>
2   -
3   -<h2><%= c_('Statistics') %></h2>
4   -<%= labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => profile_id)) %>
5   -<%= link_to(_('See how to configure statistics for your profile'), '/doc/plugins/google_analytics', :target => '_blank') %>
plugins/google_analytics/views/tracking-code.html.erb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<script>
  2 + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  3 + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  4 + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  5 + })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  6 +
  7 + ga('create', '<%= escape_javascript locals[:profile_id] %>', 'auto');
  8 + ga('send', 'pageview');
  9 +</script>
... ...
plugins/google_analytics/views/tracking-code.rhtml
... ... @@ -1,10 +0,0 @@
1   -<script type="text/javascript">
2   - var _gaq = _gaq || [];
3   - _gaq.push(['_setAccount', '<%= escape_javascript locals[:profile_id] %>']);
4   - _gaq.push(['_trackPageview']);
5   - (function() {
6   - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
7   - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
8   - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
9   - })();
10   -</script>