ninetails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/ninetails/page_section.rb +7 -2
- data/lib/ninetails/version.rb +1 -1
- data/spec/components/property_type_spec.rb +1 -1
- data/spec/dummy/log/test.log +4651 -0
- data/spec/models/page_section_spec.rb +69 -31
- data/spec/spec_helper.rb +2 -0
- metadata +1 -1
@@ -48,45 +48,83 @@ RSpec.describe Ninetails::PageSection, type: :model do
|
|
48
48
|
}
|
49
49
|
end
|
50
50
|
|
51
|
+
let(:json_with_missing_element) do
|
52
|
+
{
|
53
|
+
"name" => "",
|
54
|
+
"type" => "TestSection",
|
55
|
+
"tags" => { "position" => "body" },
|
56
|
+
"elements" => {
|
57
|
+
"unknown" => {
|
58
|
+
"type" => "ThisDoesntExist",
|
59
|
+
"foo" => "Bar"
|
60
|
+
},
|
61
|
+
"headline" => {
|
62
|
+
"type" => "Text",
|
63
|
+
"content" => { "text" => headline }
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
51
69
|
let(:section) { Ninetails::PageSection.new(json) }
|
70
|
+
let(:section_with_missing_element) { Ninetails::PageSection.new(json_with_missing_element) }
|
52
71
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
72
|
+
describe "when all elements exist" do
|
73
|
+
it "should create a Section instance" do
|
74
|
+
section.deserialize
|
75
|
+
expect(section.section).to be_a Section::TestSection
|
76
|
+
end
|
57
77
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
78
|
+
it "should have an array of elements_instances" do
|
79
|
+
section.deserialize
|
80
|
+
expect(section.section.elements_instances.size).to eq 3
|
81
|
+
end
|
62
82
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
83
|
+
it "should include an element for 'text', 'button', and 'link'" do
|
84
|
+
section.deserialize
|
85
|
+
expect(section.section.elements_instances[0].name).to eq :headline
|
86
|
+
expect(section.section.elements_instances[1].name).to eq :button
|
87
|
+
expect(section.section.elements_instances[2].name).to eq :messages
|
88
|
+
end
|
69
89
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
90
|
+
it "should be the correct type for 'text', 'button', and 'link'" do
|
91
|
+
section.deserialize
|
92
|
+
expect(section.section.elements_instances[0].type).to eq Element::Text
|
93
|
+
expect(section.section.elements_instances[1].type).to eq Element::Button
|
94
|
+
expect(section.section.elements_instances[2].type).to eq Element::Text
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should call deserialize on each element" do
|
98
|
+
expect(Section::TestSection.find_element("headline")).to receive(:deserialize).with(json["elements"]["headline"])
|
99
|
+
expect(Section::TestSection.find_element("button")).to receive(:deserialize).with(json["elements"]["button"])
|
100
|
+
expect(Section::TestSection.find_element("messages")).to receive(:deserialize).with(json["elements"]["messages"])
|
101
|
+
section.deserialize
|
102
|
+
end
|
76
103
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
104
|
+
it "should be possible to reserialize into json" do
|
105
|
+
section.deserialize
|
106
|
+
serialized = section.section.serialize.with_indifferent_access
|
107
|
+
expect(serialized[:elements][:headline][:content][:text]).to eq headline
|
108
|
+
expect(serialized[:elements][:messages][0][:content][:text]).to eq first_message
|
109
|
+
expect(serialized[:elements][:messages][1][:content][:text]).to eq second_message
|
110
|
+
end
|
82
111
|
end
|
83
112
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
113
|
+
describe "when some elements don't exist" do
|
114
|
+
it "should create a Section instance" do
|
115
|
+
section_with_missing_element.deserialize
|
116
|
+
expect(section_with_missing_element.section).to be_a Section::TestSection
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not include the broken element in the section elements" do
|
120
|
+
section_with_missing_element.deserialize
|
121
|
+
expect(section_with_missing_element.section.elements_instances.size).to eq 1
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should log an error that the element did not exist" do
|
125
|
+
expect(Rails.logger).to receive(:error).with("[Ninetails] TestSection does not have an element named 'unknown'. Skipping.")
|
126
|
+
section_with_missing_element.deserialize
|
127
|
+
end
|
90
128
|
end
|
91
129
|
|
92
130
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -36,6 +36,8 @@ RSpec.configure do |config|
|
|
36
36
|
# ...rather than:
|
37
37
|
# # => "be bigger than 2"
|
38
38
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
39
|
+
|
40
|
+
expectations.warn_about_potential_false_positives = false
|
39
41
|
end
|
40
42
|
|
41
43
|
# rspec-mocks config goes here. You can use an alternate test double
|