govuk_content_models 42.0.0 → 42.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/app/traits/attachable.rb +2 -2
- data/govuk_content_models.gemspec +1 -2
- data/lib/govuk_content_models/version.rb +1 -1
- metadata +3 -83
- data/test/fixtures/uploads/image.jpg +0 -0
- data/test/models/action_test.rb +0 -13
- data/test/models/artefact_action_test.rb +0 -130
- data/test/models/artefact_external_link_test.rb +0 -32
- data/test/models/artefact_test.rb +0 -482
- data/test/models/business_support/business_size_test.rb +0 -25
- data/test/models/business_support/business_type_test.rb +0 -25
- data/test/models/business_support/location_test.rb +0 -25
- data/test/models/business_support/purpose_test.rb +0 -29
- data/test/models/business_support/sector_test.rb +0 -25
- data/test/models/business_support/stage_test.rb +0 -25
- data/test/models/business_support/support_type_test.rb +0 -25
- data/test/models/business_support_edition_test.rb +0 -282
- data/test/models/campaign_edition_test.rb +0 -91
- data/test/models/completed_transaction_edition_test.rb +0 -56
- data/test/models/downtime_test.rb +0 -93
- data/test/models/edition_scheduled_for_publishing_test.rb +0 -91
- data/test/models/edition_test.rb +0 -1185
- data/test/models/help_page_edition_test.rb +0 -43
- data/test/models/licence_edition_test.rb +0 -105
- data/test/models/local_service_test.rb +0 -6
- data/test/models/local_transaction_edition_test.rb +0 -37
- data/test/models/overview_dashboard_test.rb +0 -46
- data/test/models/parted_test.rb +0 -26
- data/test/models/prerendered_entity_tests.rb +0 -46
- data/test/models/rendered_manual_test.rb +0 -10
- data/test/models/simple_smart_answer_edition_test.rb +0 -211
- data/test/models/simple_smart_answer_node_test.rb +0 -134
- data/test/models/simple_smart_answer_option_test.rb +0 -97
- data/test/models/time_zone_test.rb +0 -48
- data/test/models/transaction_edition_test.rb +0 -36
- data/test/models/travel_advice_edition_test.rb +0 -469
- data/test/models/user_test.rb +0 -155
- data/test/models/video_edition_test.rb +0 -64
- data/test/models/workflow_test.rb +0 -498
- data/test/test_helper.rb +0 -61
- data/test/traits/attachable_test.rb +0 -244
- data/test/validators/link_validator_test.rb +0 -86
- data/test/validators/safe_html_validator_test.rb +0 -83
- data/test/validators/slug_validator_test.rb +0 -109
@@ -1,43 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class HelpPageEditionTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@artefact = FactoryGirl.create(:artefact, kind: 'help_page', slug: "help/foo")
|
6
|
-
end
|
7
|
-
|
8
|
-
should "have correct extra fields" do
|
9
|
-
h = FactoryGirl.create(
|
10
|
-
:help_page_edition,
|
11
|
-
panopticon_id: @artefact.id,
|
12
|
-
body: "I'm a help page.",
|
13
|
-
)
|
14
|
-
|
15
|
-
assert_equal "I'm a help page.", h.body
|
16
|
-
end
|
17
|
-
|
18
|
-
should "give a friendly (legacy supporting) description of its format" do
|
19
|
-
help_page = HelpPageEdition.new
|
20
|
-
assert_equal "HelpPage", help_page.format
|
21
|
-
end
|
22
|
-
|
23
|
-
should "return the body as whole_body" do
|
24
|
-
h = FactoryGirl.build(
|
25
|
-
:help_page_edition,
|
26
|
-
panopticon_id: @artefact.id,
|
27
|
-
body: "Something",
|
28
|
-
)
|
29
|
-
assert_equal h.body, h.whole_body
|
30
|
-
end
|
31
|
-
|
32
|
-
should "clone extra fields when cloning edition" do
|
33
|
-
help_page = FactoryGirl.create(
|
34
|
-
:help_page_edition,
|
35
|
-
panopticon_id: @artefact.id,
|
36
|
-
state: "published",
|
37
|
-
body: "I'm very helpful",
|
38
|
-
)
|
39
|
-
|
40
|
-
new_help_page = help_page.build_clone
|
41
|
-
assert_equal help_page.body, new_help_page.body
|
42
|
-
end
|
43
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class LicenceEditionTest < ActiveSupport::TestCase
|
4
|
-
def setup
|
5
|
-
@artefact = FactoryGirl.create(:artefact)
|
6
|
-
end
|
7
|
-
|
8
|
-
should "have correct extra fields" do
|
9
|
-
l = FactoryGirl.create(
|
10
|
-
:licence_edition,
|
11
|
-
panopticon_id: @artefact.id,
|
12
|
-
licence_identifier: "AB1234",
|
13
|
-
licence_short_description: "Short description of licence",
|
14
|
-
licence_overview: "Markdown overview of licence...",
|
15
|
-
will_continue_on: "The HMRC website",
|
16
|
-
continuation_link: "http://www.hmrc.gov.uk"
|
17
|
-
)
|
18
|
-
|
19
|
-
assert_equal "AB1234", l.licence_identifier
|
20
|
-
assert_equal "Short description of licence", l.licence_short_description
|
21
|
-
assert_equal "Markdown overview of licence...", l.licence_overview
|
22
|
-
assert_equal "The HMRC website", l.will_continue_on
|
23
|
-
assert_equal "http://www.hmrc.gov.uk", l.continuation_link
|
24
|
-
end
|
25
|
-
|
26
|
-
context "validations" do
|
27
|
-
setup do
|
28
|
-
@l = FactoryGirl.build(:licence_edition, panopticon_id: @artefact.id)
|
29
|
-
end
|
30
|
-
|
31
|
-
should "require a licence identifier" do
|
32
|
-
@l.licence_identifier = ''
|
33
|
-
assert_equal false, @l.valid?, "expected licence edition not to be valid"
|
34
|
-
end
|
35
|
-
|
36
|
-
context "licence identifier uniqueness" do
|
37
|
-
should "require a unique licence identifier" do
|
38
|
-
artefact2 = FactoryGirl.create(:artefact)
|
39
|
-
FactoryGirl.create(:licence_edition, :licence_identifier => "wibble", panopticon_id: artefact2.id)
|
40
|
-
@l.licence_identifier = "wibble"
|
41
|
-
assert ! @l.valid?, "expected licence edition not to be valid"
|
42
|
-
end
|
43
|
-
|
44
|
-
should "not consider archived editions when evaluating uniqueness" do
|
45
|
-
artefact2 = FactoryGirl.create(:artefact)
|
46
|
-
FactoryGirl.create(:licence_edition, :licence_identifier => "wibble", panopticon_id: artefact2.id, :state => "archived")
|
47
|
-
@l.licence_identifier = "wibble"
|
48
|
-
assert @l.valid?, "expected licence edition to be valid"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
should "not require a unique licence identifier for different versions of the same licence edition" do
|
53
|
-
@l.state = 'published'
|
54
|
-
@l.licence_identifier = 'wibble'
|
55
|
-
@l.save!
|
56
|
-
|
57
|
-
new_version = @l.build_clone
|
58
|
-
assert_equal 'wibble', new_version.licence_identifier
|
59
|
-
assert new_version.valid?, "Expected clone to be valid"
|
60
|
-
end
|
61
|
-
|
62
|
-
should "not validate the continuation link when blank" do
|
63
|
-
@l.continuation_link = ""
|
64
|
-
assert @l.valid?, "continuation link validation should not be triggered when the field is blank"
|
65
|
-
end
|
66
|
-
should "fail validation when the continuation link has an invalid url" do
|
67
|
-
@l.continuation_link = "not&a+valid_url"
|
68
|
-
assert !@l.valid?, "continuation link validation should fail with a invalid url"
|
69
|
-
end
|
70
|
-
should "pass validation with a valid continuation link url" do
|
71
|
-
@l.continuation_link = "http://www.hmrc.gov.uk"
|
72
|
-
assert @l.valid?, "continuation_link validation should pass with a valid url"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
should "clone extra fields when cloning edition" do
|
77
|
-
licence = FactoryGirl.create(:licence_edition,
|
78
|
-
:panopticon_id => @artefact.id,
|
79
|
-
:state => "published",
|
80
|
-
:licence_identifier => "1234",
|
81
|
-
:licence_short_description => "Short description of licence",
|
82
|
-
:licence_overview => "Overview to be cloned",
|
83
|
-
:will_continue_on => "Continuation text to be cloned",
|
84
|
-
:continuation_link => "http://www.gov.uk")
|
85
|
-
new_licence = licence.build_clone
|
86
|
-
|
87
|
-
assert_equal licence.licence_identifier, new_licence.licence_identifier
|
88
|
-
assert_equal licence.licence_short_description, new_licence.licence_short_description
|
89
|
-
assert_equal licence.licence_overview, new_licence.licence_overview
|
90
|
-
assert_equal licence.will_continue_on, new_licence.will_continue_on
|
91
|
-
assert_equal licence.continuation_link, new_licence.continuation_link
|
92
|
-
end
|
93
|
-
|
94
|
-
context "indexable_content" do
|
95
|
-
should "include the licence_overview, removing markup" do
|
96
|
-
licence = FactoryGirl.create(:licence_edition)
|
97
|
-
assert_includes licence.indexable_content, "This is a licence overview"
|
98
|
-
end
|
99
|
-
|
100
|
-
should "include the licence_short_description" do
|
101
|
-
licence = FactoryGirl.create(:licence_edition)
|
102
|
-
assert_includes licence.indexable_content, "This is a licence short description."
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "govuk_content_models/test_helpers/local_services"
|
3
|
-
|
4
|
-
class LocalTransactionEditionTest < ActiveSupport::TestCase
|
5
|
-
include LocalServicesHelper
|
6
|
-
BINS = 1
|
7
|
-
HOUSING_BENEFIT = 2
|
8
|
-
NONEXISTENT = 999
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@artefact = FactoryGirl.create(:artefact)
|
12
|
-
end
|
13
|
-
|
14
|
-
test "should be a transaction search format" do
|
15
|
-
bins_transaction = LocalTransactionEdition.new(
|
16
|
-
lgsl_code: BINS,
|
17
|
-
title: "Transaction",
|
18
|
-
slug: "slug",
|
19
|
-
panopticon_id: @artefact.id
|
20
|
-
)
|
21
|
-
assert_equal "transaction", bins_transaction.search_format
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
test "should validate on save that a LocalService exists for that lgsl_code" do
|
26
|
-
s = LocalService.create!(lgsl_code: BINS, providing_tier: %w{county unitary})
|
27
|
-
|
28
|
-
lt = LocalTransactionEdition.new(lgsl_code: NONEXISTENT, title: "Foo", slug: "foo", panopticon_id: @artefact.id)
|
29
|
-
lt.save
|
30
|
-
assert !lt.valid?
|
31
|
-
|
32
|
-
lt = LocalTransactionEdition.new(lgsl_code: s.lgsl_code, title: "Bar", slug: "bar", panopticon_id: @artefact.id)
|
33
|
-
lt.save
|
34
|
-
assert lt.valid?
|
35
|
-
assert lt.persisted?
|
36
|
-
end
|
37
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class OverviewDashboardTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test "Can create and retrieve dashboard overview objects" do
|
6
|
-
overview = create_test_overview
|
7
|
-
|
8
|
-
assert_equal overview.dashboard_type, "Format"
|
9
|
-
assert_equal overview.result_group, "Guide"
|
10
|
-
check_status_equal overview, row_status
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
def create_test_overview
|
15
|
-
overview = OverviewDashboard.create dashboard_type: "Format", result_group: "Guide"
|
16
|
-
|
17
|
-
row_status.each do |k, v|
|
18
|
-
overview[k] = v
|
19
|
-
end
|
20
|
-
|
21
|
-
overview.save
|
22
|
-
|
23
|
-
found_overviews = OverviewDashboard.where(dashboard_type: "Format")
|
24
|
-
assert_equal found_overviews.size, 1
|
25
|
-
found_overviews.first
|
26
|
-
end
|
27
|
-
|
28
|
-
def row_status
|
29
|
-
{
|
30
|
-
draft: 1,
|
31
|
-
ammends_needed: 1,
|
32
|
-
in_review: 1,
|
33
|
-
ready: 1,
|
34
|
-
fact_check_recieved: 1,
|
35
|
-
fact_check: 1,
|
36
|
-
published: 1,
|
37
|
-
archived: 1
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def check_status_equal(actual_object, expected_hash)
|
42
|
-
expected_hash.each do |k, v|
|
43
|
-
assert_equal actual_object[k], expected_hash[k]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/test/models/parted_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
# require "edition"
|
3
|
-
# require "parted"
|
4
|
-
|
5
|
-
class PartedTest < ActiveSupport::TestCase
|
6
|
-
test "should merge part validation errors with parent document's errors" do
|
7
|
-
edition = FactoryGirl.create(:guide_edition)
|
8
|
-
edition.parts.build(_id: '54c10d4d759b743528000010', order: '1', title: "", slug: "overview")
|
9
|
-
edition.parts.build(_id: '54c10d4d759b743528000011', order: '2', title: "Prepare for your appointment", slug: "")
|
10
|
-
edition.parts.build(_id: '54c10d4d759b743528000012', order: '3', title: "Valid", slug: "valid")
|
11
|
-
|
12
|
-
refute edition.valid?
|
13
|
-
|
14
|
-
assert_equal({title: ["can't be blank"]}, edition.errors[:parts][0]['54c10d4d759b743528000010:1'])
|
15
|
-
assert_equal({slug: ["can't be blank", "is invalid"]}, edition.errors[:parts][0]['54c10d4d759b743528000011:2'])
|
16
|
-
assert_equal 2, edition.errors[:parts][0].length
|
17
|
-
end
|
18
|
-
|
19
|
-
test "#whole_body returns ordered parts" do
|
20
|
-
edition = FactoryGirl.create(:guide_edition)
|
21
|
-
edition.parts.build(_id: '54c10d4d759b743528000010', order: '1', title: "Part 1", slug: "part_1")
|
22
|
-
edition.parts.build(_id: '54c10d4d759b743528000011', order: '3', title: "Part 3", slug: "part_3")
|
23
|
-
edition.parts.build(_id: '54c10d4d759b743528000012', order: '2', title: "Part 2", slug: "part_2")
|
24
|
-
assert_equal("# Part 1\n\n\n\n# Part 2\n\n\n\n# Part 3\n\n", edition.whole_body)
|
25
|
-
end
|
26
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# include in a test class and define a #model_class instance method
|
2
|
-
|
3
|
-
module PrerenderedEntityTests
|
4
|
-
def test_duplicate_slug_not_allowed
|
5
|
-
model_class.create(slug: "my-slug")
|
6
|
-
second = model_class.create(slug: "my-slug")
|
7
|
-
|
8
|
-
refute second.valid?
|
9
|
-
assert_equal 1, model_class.count
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_has_no_govspeak_fields
|
13
|
-
refute model_class.const_defined?(:GOVSPEAK_FIELDS)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_create_or_update_by_slug
|
17
|
-
slug = "a-slug"
|
18
|
-
original_title = "Original title"
|
19
|
-
|
20
|
-
version1_attrs= {
|
21
|
-
slug: slug,
|
22
|
-
title: original_title,
|
23
|
-
}
|
24
|
-
|
25
|
-
created = model_class.create_or_update_by_slug!(version1_attrs)
|
26
|
-
|
27
|
-
assert created.is_a?(model_class)
|
28
|
-
assert created.persisted?
|
29
|
-
|
30
|
-
version2_attrs = version1_attrs.merge(
|
31
|
-
title: "Updated title",
|
32
|
-
)
|
33
|
-
|
34
|
-
version2 = model_class.create_or_update_by_slug!(version2_attrs)
|
35
|
-
|
36
|
-
assert version2.persisted?
|
37
|
-
assert_equal "Updated title", version2.title
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_find_by_slug
|
41
|
-
created = model_class.create!(slug: "find-by-this-slug")
|
42
|
-
found = model_class.find_by_slug("find-by-this-slug")
|
43
|
-
|
44
|
-
assert_equal created, found
|
45
|
-
end
|
46
|
-
end
|
@@ -1,211 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class SimpleSmartAnswerEditionTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@artefact = FactoryGirl.create(:artefact)
|
6
|
-
end
|
7
|
-
|
8
|
-
should "be created with valid nodes" do
|
9
|
-
edition = FactoryGirl.build(:simple_smart_answer_edition, panopticon_id: @artefact.id)
|
10
|
-
edition.body = "This is a simple smart answer."
|
11
|
-
|
12
|
-
edition.nodes.build(:slug => "question1", :title => "You approach two locked doors. Which do you choose?", :kind => "question", :order => 1)
|
13
|
-
edition.nodes.build(:slug => "left", :title => "As you open the door, a lion bursts out and mauls you to death.", :order => 2, :kind => "outcome")
|
14
|
-
edition.nodes.build(:slug => "right", :title => "As you open the door, a tiger bursts out and mauls you to death.", :order => 3, :kind => "outcome")
|
15
|
-
edition.save!
|
16
|
-
|
17
|
-
edition = SimpleSmartAnswerEdition.first
|
18
|
-
|
19
|
-
assert_equal "This is a simple smart answer.", edition.body
|
20
|
-
assert_equal 3, edition.nodes.count
|
21
|
-
assert_equal ["question1", "left", "right"], edition.nodes.all.map(&:slug)
|
22
|
-
end
|
23
|
-
|
24
|
-
should "copy the body and nodes when cloning an edition" do
|
25
|
-
edition = FactoryGirl.create(:simple_smart_answer_edition,
|
26
|
-
panopticon_id: @artefact.id,
|
27
|
-
body: "This smart answer is somewhat unique and calls for a different kind of introduction",
|
28
|
-
state: "published"
|
29
|
-
)
|
30
|
-
edition.nodes.build(:slug => "question1", :title => "You approach two open doors. Which do you choose?", :kind => "question", :order => 1)
|
31
|
-
edition.nodes.build(:slug => "left", :title => "As you wander through the door, it slams shut behind you, as a lion starts pacing towards you...", :order => 2, :kind => "outcome")
|
32
|
-
edition.nodes.build(:slug => "right", :title => "As you wander through the door, it slams shut behind you, as a tiger starts pacing towards you...", :order => 3, :kind => "outcome")
|
33
|
-
edition.save!
|
34
|
-
|
35
|
-
cloned_edition = edition.build_clone
|
36
|
-
cloned_edition.save!
|
37
|
-
|
38
|
-
old_edition = SimpleSmartAnswerEdition.find(edition.id)
|
39
|
-
assert_equal ["question", "outcome", "outcome"], old_edition.nodes.all.map(&:kind)
|
40
|
-
assert_equal ["question1", "left", "right"], old_edition.nodes.all.map(&:slug)
|
41
|
-
|
42
|
-
new_edition = SimpleSmartAnswerEdition.find(cloned_edition.id)
|
43
|
-
assert_equal edition.body, new_edition.body
|
44
|
-
assert_equal ["question", "outcome", "outcome"], new_edition.nodes.all.map(&:kind)
|
45
|
-
assert_equal ["question1", "left", "right"], new_edition.nodes.all.map(&:slug)
|
46
|
-
end
|
47
|
-
|
48
|
-
should "not copy nodes when new edition is not a smart answer" do
|
49
|
-
edition = FactoryGirl.create(:simple_smart_answer_edition,
|
50
|
-
panopticon_id: @artefact.id,
|
51
|
-
body: "This smart answer is somewhat unique and calls for a different kind of introduction",
|
52
|
-
state: "published"
|
53
|
-
)
|
54
|
-
edition.nodes.build(:slug => "question1", :title => "You approach two open doors. Which do you choose?", :kind => "question", :order => 1)
|
55
|
-
edition.save!
|
56
|
-
|
57
|
-
new_edition = edition.build_clone(AnswerEdition)
|
58
|
-
|
59
|
-
assert_equal "This smart answer is somewhat unique and calls for a different kind of introduction\n\n\nquestion: You approach two open doors. Which do you choose? \n\n ", new_edition.body
|
60
|
-
|
61
|
-
assert new_edition.is_a?(AnswerEdition)
|
62
|
-
assert ! new_edition.respond_to?(:nodes)
|
63
|
-
end
|
64
|
-
|
65
|
-
should "select the first node as the starting node" do
|
66
|
-
edition = FactoryGirl.create(:simple_smart_answer_edition)
|
67
|
-
edition.nodes.build(:slug => "question1", :title => "Question 1", :kind => "question", :order => 1)
|
68
|
-
edition.nodes.build(:slug => "question2", :title => "Question 2", :kind => "question", :order => 2)
|
69
|
-
edition.nodes.build(:slug => "foo", :title => "Outcome 1.", :order => 3, :kind => "outcome")
|
70
|
-
edition.nodes.build(:slug => "bar", :title => "Outcome 2", :order => 4, :kind => "outcome")
|
71
|
-
|
72
|
-
assert_equal "question1", edition.initial_node.slug
|
73
|
-
end
|
74
|
-
|
75
|
-
should "create nodes with nested attributes" do
|
76
|
-
edition = FactoryGirl.create(:simple_smart_answer_edition, :nodes_attributes => [
|
77
|
-
{ slug: "question1", title: "Question 1", kind: "question", order: 1},
|
78
|
-
{ slug: "foo", title: "Outcome 1", kind: "outcome", order: 2 },
|
79
|
-
])
|
80
|
-
|
81
|
-
assert_equal 2, edition.nodes.size
|
82
|
-
assert_equal ["question1", "foo"], edition.nodes.all.map(&:slug)
|
83
|
-
end
|
84
|
-
|
85
|
-
should "destroy nodes using nested attributes" do
|
86
|
-
edition = FactoryGirl.create(:simple_smart_answer_edition)
|
87
|
-
edition.nodes.build(:slug => "question1", :title => "Question 1", :kind => "question", :order => 1)
|
88
|
-
edition.nodes.build(:slug => "question2", :title => "Question 2", :kind => "question", :order => 1)
|
89
|
-
edition.save!
|
90
|
-
|
91
|
-
assert_equal 2, edition.nodes.size
|
92
|
-
|
93
|
-
edition.update_attributes({
|
94
|
-
:nodes_attributes => {
|
95
|
-
"1" => { "id" => edition.nodes.first.id, "_destroy" => "1" }
|
96
|
-
}
|
97
|
-
})
|
98
|
-
edition.reload
|
99
|
-
|
100
|
-
assert_equal 1, edition.nodes.size
|
101
|
-
end
|
102
|
-
|
103
|
-
context "SimpleSmartAnswerEdition: Start Button" do
|
104
|
-
setup do
|
105
|
-
@edition_attributes = {
|
106
|
-
panopticon_id: @artefact.id,
|
107
|
-
body: "This is a simple smart answer with a default text for start button."
|
108
|
-
}
|
109
|
-
end
|
110
|
-
context "with default text" do
|
111
|
-
setup do
|
112
|
-
edition = FactoryGirl.build(:simple_smart_answer_edition, @edition_attributes)
|
113
|
-
edition.save!
|
114
|
-
end
|
115
|
-
|
116
|
-
should "be created with the default text for start button" do
|
117
|
-
edition = SimpleSmartAnswerEdition.first
|
118
|
-
|
119
|
-
assert_equal "Start now", edition.start_button_text
|
120
|
-
assert_equal "This is a simple smart answer with a default text for start button.", edition.body
|
121
|
-
assert_equal @artefact.id.to_s, edition.panopticon_id
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when button text changes" do
|
126
|
-
setup do
|
127
|
-
edition = FactoryGirl.build(
|
128
|
-
:simple_smart_answer_edition,
|
129
|
-
@edition_attributes.merge(start_button_text: "Click to start")
|
130
|
-
)
|
131
|
-
edition.save!
|
132
|
-
end
|
133
|
-
|
134
|
-
should "be created with the text given by the content creator" do
|
135
|
-
edition = SimpleSmartAnswerEdition.first
|
136
|
-
|
137
|
-
refute_equal "Start Now", edition.start_button_text
|
138
|
-
assert_equal "Click to start", edition.start_button_text
|
139
|
-
assert_equal "This is a simple smart answer with a default text for start button.", edition.body
|
140
|
-
assert_equal @artefact.id.to_s, edition.panopticon_id
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "update_attributes method" do
|
146
|
-
setup do
|
147
|
-
@edition = FactoryGirl.create(:simple_smart_answer_edition)
|
148
|
-
@edition.nodes.build(:slug => "question1", :title => "Question 1", :kind => "question", :order => 1)
|
149
|
-
@edition.nodes.build(:slug => "question2", :title => "Question 2", :kind => "question", :order => 1)
|
150
|
-
@edition.nodes.first.options.build(
|
151
|
-
:label => "Option 1", :next_node => "question2", :order => 1)
|
152
|
-
@edition.save!
|
153
|
-
end
|
154
|
-
|
155
|
-
should "update edition and nested node and option attributes" do
|
156
|
-
@edition.update_attributes(:title => "Smarter than the average answer",
|
157
|
-
:body => "No developers were involved in the changing of this copy",
|
158
|
-
:nodes_attributes => {
|
159
|
-
"0" => { "id" => @edition.nodes.first.id, "title" => "Question the first", "options_attributes" => {
|
160
|
-
"0" => { "id" => @edition.nodes.first.options.first.id, "label" => "Option the first" }
|
161
|
-
}
|
162
|
-
}
|
163
|
-
})
|
164
|
-
|
165
|
-
@edition.reload
|
166
|
-
|
167
|
-
assert_equal "Smarter than the average answer", @edition.title
|
168
|
-
assert_equal "No developers were involved in the changing of this copy", @edition.body
|
169
|
-
assert_equal "Question the first", @edition.nodes.first.title
|
170
|
-
assert_equal "Option the first", @edition.nodes.first.options.first.label
|
171
|
-
end
|
172
|
-
|
173
|
-
should "create and destroy nodes and options using nested attributes" do
|
174
|
-
@edition.update_attributes({
|
175
|
-
:nodes_attributes => {
|
176
|
-
"0" => { "id" => @edition.nodes.first.id, "options_attributes" => {
|
177
|
-
"0" => { "id" => @edition.nodes.first.options.first.id, "_destroy" => "1" }
|
178
|
-
}
|
179
|
-
},
|
180
|
-
"1" => { "id" => @edition.nodes.second.id, "_destroy" => "1" },
|
181
|
-
"2" => { "kind" => "question", "title" => "Question 3", "slug" => "question3", "options_attributes" => {
|
182
|
-
"0" => { "label" => "Goes to outcome 1", "next_node" => "outcome1" }
|
183
|
-
} },
|
184
|
-
"3" => { "kind" => "outcome", "title" => "Outcome 1", "slug" => "outcome1" }
|
185
|
-
}
|
186
|
-
})
|
187
|
-
|
188
|
-
@edition.reload
|
189
|
-
|
190
|
-
assert_equal 3, @edition.nodes.size
|
191
|
-
assert_equal 0, @edition.nodes.first.options.size
|
192
|
-
assert_equal "Question 3", @edition.nodes.second.title
|
193
|
-
assert_equal 1, @edition.nodes.second.options.size
|
194
|
-
assert_equal "outcome1", @edition.nodes.second.options.first.next_node
|
195
|
-
assert_equal "Outcome 1", @edition.nodes.third.title
|
196
|
-
end
|
197
|
-
|
198
|
-
should "ignore new nodes if they are to be destroyed" do
|
199
|
-
@edition.update_attributes({
|
200
|
-
:nodes_attributes => {
|
201
|
-
"0" => { "id" => @edition.nodes.first.id, "title" => "Question the first" },
|
202
|
-
"1" => { "title" => "", "slug" => "", "kind" => "outcome", "_destroy" => "1" }
|
203
|
-
}
|
204
|
-
})
|
205
|
-
@edition.reload
|
206
|
-
|
207
|
-
assert_equal "Question the first", @edition.nodes.first.title
|
208
|
-
assert_equal 2, @edition.nodes.size
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|