Skip to content

Commit

Permalink
Refactor audit metadata feature test to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgarner committed Nov 3, 2017
1 parent bdb80a3 commit 118b614
Showing 1 changed file with 162 additions and 73 deletions.
235 changes: 162 additions & 73 deletions spec/features/audit/audit/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,103 +1,192 @@
RSpec.feature "Audit metadata", type: :feature do
let!(:my_organisation) do
RSpec.feature 'Audit metadata', type: :feature do
scenario 'showing minimal metadata next to the audit questionnaire' do
given_a_content_item_that_has_not_been_audited_or_assigned
when_i_audit_the_content_item
then_i_am_shown_that_the_content_item_is_assigned_to_no_one
and_i_am_shown_that_the_content_item_is_not_audited_yet
and_i_am_shown_the_content_type
and_i_am_shown_that_the_content_is_guidance
and_i_am_shown_that_the_content_has_not_had_a_major_update
and_i_am_shown_that_the_content_has_no_organisations
and_i_am_shown_that_the_content_has_no_policy_areas
and_i_am_shown_that_the_content_has_not_been_withdrawn
and_i_am_shown_that_the_content_has_no_topics
and_i_am_shown_that_the_content_has_no_unique_page_views
end

scenario 'showing maximal metadata next to the audit questionnaire' do
given_a_content_item_that_has_been_tagged_and_audited_and_assigned
when_i_audit_the_content_item
then_i_am_shown_that_the_content_item_has_been_assigned
and_i_am_shown_that_the_content_item_has_been_audited
and_i_am_shown_the_organisations_the_content_item_is_tagged_to
and_i_am_shown_when_the_last_major_update_happened
and_i_am_shown_the_content_type
and_i_am_shown_that_the_content_is_guidance
and_i_am_shown_the_topics_the_content_item_is_tagged_to
and_i_am_shown_the_policy_areas_the_content_item_is_tagged_to
and_i_am_shown_that_the_content_has_not_been_withdrawn
and_i_am_shown_the_unique_page_views
end

around do |example|
Timecop.freeze(2017, 1, 1) { example.run }
end

def given_a_content_item_that_has_been_tagged_and_audited_and_assigned
auditor = create(
:user,
name: 'Harper Lee',
organisation: create(:organisation, title: 'Authors'),
)

assignee = create(
:user,
name: 'Edd The Duck',
organisation: create(:organisation, title: 'CBBC'),
)

@content_item = create(
:content_item,
document_type: 'guidance',
one_month_page_views: 1234,
six_months_page_views: 12345,
public_updated_at: '2017-01-03',
)

create(
:organisation,
title: "Authors",
:link,
link_type: :organisations,
source: @content_item,
target: create(:content_item, title: 'Home office'),
)
end

let!(:me) do
create(
:user,
name: "Harper Lee",
organisation: my_organisation,
:link,
link_type: :topics,
source: @content_item,
target: create(:content_item, title: 'Borders'),
)

create(
:link,
link_type: :topics,
source: @content_item,
target: create(:content_item, title: 'Immigration'),
)
end

let!(:content_item) do
create(
:link,
link_type: :policy_areas,
source: @content_item,
target: create(:content_item, title: 'Borders and Immigration'),
)

create(:allocation, content_item: @content_item, user: assignee)
create(:audit, content_item: @content_item, user: auditor)
end

def given_a_content_item_that_has_not_been_audited_or_assigned
create(:user)

@content_item = create(
:content_item,
document_type: 'guidance',
public_updated_at: nil,
document_type: "document_collection",
)
end

around do |example|
Timecop.freeze(2017, 1, 1) { example.run }
def when_i_audit_the_content_item
@audit_content_item = ContentAuditTool.new.audit_content_item
@audit_content_item.load(content_id: @content_item.content_id)
end

scenario "showing minimal metadata next to the audit quesionnaire" do
@audit_content_item = ContentAuditTool.new.audit_content_item
@audit_content_item.load(content_id: content_item.content_id)
def then_i_am_shown_that_the_content_item_is_assigned_to_no_one
expect(@audit_content_item.metadata).to have_assigned_to(text: 'No one')
end

@audit_content_item.metadata do |metadata|
expect(metadata).to have_assigned_to(text: 'No one')
expect(metadata).to have_audited(text: 'Not audited yet')
expect(metadata).to have_content_type(text: 'Document Collection')
expect(metadata).to have_guidance(text: 'No')
expect(metadata).to have_last_major_update(text: 'Never')
expect(metadata).to have_organisations(text: 'None')
expect(metadata).to have_policy_areas(text: 'None')
expect(metadata).to have_topics(text: 'None')
expect(metadata).to have_unique_page_views(text: '0 in the last month')
expect(metadata).to have_unique_page_views(text: '0 in the last six months')
expect(metadata).to have_withdrawn(text: 'No')
end
def then_i_am_shown_that_the_content_item_has_been_assigned
expect(@audit_content_item.metadata)
.to have_assigned_to(text: 'Edd The Duck CBBC')
end

def create_linked_content(link_type, title)
target = create(:content_item, title: title)
def and_i_am_shown_that_the_content_item_is_not_audited_yet
expect(@audit_content_item.metadata)
.to have_audited(text: 'Not audited yet')
end

create(
:link,
link_type: link_type,
source_content_id: content_item.content_id,
target_content_id: target.content_id,
)
def and_i_am_shown_that_the_content_item_has_been_audited
expect(@audit_content_item.metadata)
.to have_audited(text: '01/01/17 (less than a minute ago) ' \
'by Harper Lee Authors')
end

scenario "showing maximal metadata next to the audit questionnaire" do
content_item.update!(
public_updated_at: "2017-01-03",
one_month_page_views: 1234,
six_months_page_views: 12345,
document_type: "guidance",
)
def and_i_am_shown_the_content_type
expect(@audit_content_item.metadata)
.to have_content_type(text: 'Guidance')
end

create(:audit, content_item: content_item, user: me)
def and_i_am_shown_that_the_content_has_not_had_a_major_update
expect(@audit_content_item.metadata).to have_last_major_update(text: 'Never')
end

create_linked_content("organisations", "Home office")
create_linked_content("topics", "Immigration")
create_linked_content("topics", "Borders")
create_linked_content("policy_areas", "Borders and Immigration")
def and_i_am_shown_that_the_content_has_no_organisations
expect(@audit_content_item.metadata).to have_organisations(text: 'None')
end

cbbc = create(:organisation, title: "CBBC")
edd_the_duck = create(:user, name: "Edd the Duck", organisation: cbbc)
def and_i_am_shown_that_the_content_has_no_policy_areas
expect(@audit_content_item.metadata).to have_policy_areas(text: 'None')
end

create(:allocation, content_item: content_item, user: edd_the_duck)
def and_i_am_shown_that_the_content_has_no_topics
expect(@audit_content_item.metadata).to have_topics(text: 'None')
end

@audit_content_item = ContentAuditTool.new.audit_content_item
@audit_content_item.load(content_id: content_item.content_id)
def and_i_am_shown_that_the_content_has_no_unique_page_views
@audit_content_item.metadata do |metadata|
expect(metadata)
.to have_unique_page_views(text: '0 in the last month')

expect(metadata)
.to have_unique_page_views(text: '0 in the last six months')
end
end

def and_i_am_shown_that_the_content_has_not_been_withdrawn
expect(@audit_content_item.metadata).to have_withdrawn(text: 'No')
end

def and_i_am_shown_the_organisations_the_content_item_is_tagged_to
expect(@audit_content_item.metadata)
.to have_organisations(text: 'Home office')
end

def and_i_am_shown_when_the_last_major_update_happened
expect(@audit_content_item.metadata)
.to have_last_major_update(text: '03/01/17 (2 days ago)')
end

def and_i_am_shown_that_the_content_is_guidance
expect(@audit_content_item.metadata).to have_content_type(text: 'Guidance')
end

def and_i_am_shown_the_topics_the_content_item_is_tagged_to
expect(@audit_content_item.metadata)
.to have_topics(text: 'Borders, Immigration')
end

def and_i_am_shown_the_policy_areas_the_content_item_is_tagged_to
expect(@audit_content_item.metadata)
.to have_policy_areas(text: 'Borders and Immigration')
end

def and_i_am_shown_the_unique_page_views
@audit_content_item.metadata do |metadata|
expect(metadata).to have_assigned_to(
text: 'Edd the Duck CBBC',
)

expect(metadata).to have_audited(
text: '01/01/17 (less than a minute ago) ' \
'by Harper Lee Authors',
)

expect(metadata).to have_organisations(text: 'Home office')
expect(metadata).to have_last_major_update(text: '03/01/17 (2 days ago)')
expect(metadata).to have_content_type(text: 'Guidance')
expect(metadata).to have_guidance(text: 'Yes')
expect(metadata).to have_topics(text: 'Borders, Immigration')
expect(metadata).to have_policy_areas(text: 'Borders and Immigration')
expect(metadata).to have_withdrawn(text: 'No')
expect(metadata).to have_unique_page_views(text: '1,234 in the last month')
expect(metadata).to have_unique_page_views(text: '12,345 in the last six months')
expect(metadata)
.to have_unique_page_views(text: '1,234 in the last month')

expect(metadata)
.to have_unique_page_views(text: '12,345 in the last six months')
end
end
end

0 comments on commit 118b614

Please sign in to comment.