Skip to content

Commit

Permalink
Merge pull request #397 from alphagov/cross-domain-tracking
Browse files Browse the repository at this point in the history
Let publishers self serve cross-domain analytics tracking
  • Loading branch information
benilovj committed Jul 15, 2015
2 parents 11449dc + 3fb4ebb commit 0157fa6
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/views/transactions/_fields.html.erb
Expand Up @@ -31,6 +31,13 @@
:label => 'What you need to know',
:wrapper_html => { :class => 'add-top-margin' },
:input_html => { :rows => 4, :disabled => @resource.locked_for_edits?, :class => 'input-md-7' } %>
<%= f.input :department_analytics_profile,
:label => 'Department analytics profile',
:placeholder => 'UA-XXXXXX-X',
:hint => 'Let departments track user journeys between GOV.UK and their service using Google Analytics.',
:wrapper_html => { :class => 'add-top-margin' },
:input_html => { :rows => 4, :disabled => @resource.locked_for_edits?, :class => 'input-md-2' } %>
<% end %>
<%= render partial: 'shared/common_edition_tags', locals: {f: f} %>
Expand Down
20 changes: 20 additions & 0 deletions db/migrate/20150715113301_add_analytics_profiles.rb
@@ -0,0 +1,20 @@
class AddAnalyticsProfiles < Mongoid::Migration
def self.up
profiles = {
'register-to-vote' => 'UA-23066786-5',
'accelerated-possession-eviction' => 'UA-37377084-12',
'renewtaxcredits' => 'UA-43414424-1',
'registered-traveller' => 'UA-47583357-4',
}

profiles.each do |slug, profile|
editions = TransactionEdition.where(slug: slug, :state.ne => 'archived')
editions.each do |edition|
edition.set(:department_analytics_profile, profile)
end
end
end

def self.down
end
end
92 changes: 92 additions & 0 deletions test/integration/transaction_create_edit_test.rb
@@ -0,0 +1,92 @@
# encoding: utf-8
require 'integration_test_helper'

class TransactionCreateEditTest < JavascriptIntegrationTest
setup do
@artefact = FactoryGirl.create(:artefact,
slug: "register-for-space-flight",
kind: "transaction",
name: "Register for space flight",
owning_app: "publisher",
)

setup_users
stub_collections

login_as @author
end

with_and_without_javascript do
should "edit a new TransactionEdition" do
visit "/publications/#{@artefact.id}"

assert page.has_content? @artefact.name

fill_in "Introductory paragraph", :with => "Become a space pilot"
fill_in "Will continue on", :with => "UK Space Recruitment"
fill_in "More information", :with => "Take part in the final frontier"

save_edition_and_assert_success
assert page.has_content? @artefact.name

transaction = TransactionEdition.first
assert_equal @artefact.id.to_s, transaction.panopticon_id

assert_equal "Become a space pilot", transaction.introduction
assert_equal "UK Space Recruitment", transaction.will_continue_on
assert_equal "Take part in the final frontier", transaction.more_information
end

should "allow editing a TransactionEdition" do
transaction = FactoryGirl.create(:transaction_edition,
:panopticon_id => @artefact.id,
:title => "Register for space flight",
:introduction => "Become a space pilot",
:will_continue_on => "UK Space Recruitment",)

visit "/editions/#{transaction.to_param}"

assert page.has_content? 'Register for space flight'
assert page.has_field?("Introductory paragraph", :with => "Become a space pilot")
assert page.has_field?("Will continue on", :with => "UK Space Recruitment")

fill_in "Introductory paragraph", :with => "Get your licence to fly to Mars"
fill_in "Will continue on", :with => "UK Terrestrial Mars Office"

save_edition_and_assert_success

t = TransactionEdition.find(transaction.id)
assert_equal "Get your licence to fly to Mars", t.introduction
assert_equal "UK Terrestrial Mars Office", t.will_continue_on
end

should "allow only a valid department analytics profile" do
transaction = FactoryGirl.create(:transaction_edition,
:panopticon_id => @artefact.id,
:title => "Register for space flight")

visit "/editions/#{transaction.to_param}"

fill_in "Department analytics profile", :with => "UA-INVALID-SPACE-FLIGHT"
save_edition_and_assert_error

fill_in "Department analytics profile", :with => "UA-00100000-1"
save_edition_and_assert_success

t = TransactionEdition.find(transaction.id)
assert_equal "UA-00100000-1", t.department_analytics_profile
end
end

should "disable fields for a published edition" do
edition = FactoryGirl.create(:transaction_edition,
:panopticon_id => @artefact.id,
:state => 'published',
:slug => @artefact.slug,
:title => "Foo transaction"
)

visit "/editions/#{edition.to_param}"
assert_all_edition_fields_disabled(page)
end
end

0 comments on commit 0157fa6

Please sign in to comment.