Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from alphagov/cross-domain-tracking
Let publishers self serve cross-domain analytics tracking
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |