ninetails 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- it "should create a Section instance" do
54
- section.deserialize
55
- expect(section.section).to be_a Section::TestSection
56
- end
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
- it "should have an array of elements_instances" do
59
- section.deserialize
60
- expect(section.section.elements_instances.size).to eq 3
61
- end
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
- it "should include an element for 'text', 'button', and 'link'" do
64
- section.deserialize
65
- expect(section.section.elements_instances[0].name).to eq :headline
66
- expect(section.section.elements_instances[1].name).to eq :button
67
- expect(section.section.elements_instances[2].name).to eq :messages
68
- end
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
- it "should be the correct type for 'text', 'button', and 'link'" do
71
- section.deserialize
72
- expect(section.section.elements_instances[0].type).to eq Element::Text
73
- expect(section.section.elements_instances[1].type).to eq Element::Button
74
- expect(section.section.elements_instances[2].type).to eq Element::Text
75
- end
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
- it "should call deserialize on each element" do
78
- expect(Section::TestSection.find_element("headline")).to receive(:deserialize).with(json["elements"]["headline"])
79
- expect(Section::TestSection.find_element("button")).to receive(:deserialize).with(json["elements"]["button"])
80
- expect(Section::TestSection.find_element("messages")).to receive(:deserialize).with(json["elements"]["messages"])
81
- section.deserialize
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
- it "should be possible to reserialize into json" do
85
- section.deserialize
86
- serialized = section.section.serialize.with_indifferent_access
87
- expect(serialized[:elements][:headline][:content][:text]).to eq headline
88
- expect(serialized[:elements][:messages][0][:content][:text]).to eq first_message
89
- expect(serialized[:elements][:messages][1][:content][:text]).to eq second_message
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninetails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell