|
95 | 95 | subject['required'].should be_false
|
96 | 96 | end
|
97 | 97 | end
|
| 98 | + |
| 99 | + describe '#merge' do |
| 100 | + let(:parent_config) { described_class.new(parent) } |
| 101 | + let(:child_config) { described_class.new(child) } |
| 102 | + subject { parent_config.merge(child_config) } |
| 103 | + |
| 104 | + context 'when parent and child are empty' do |
| 105 | + let(:parent) { {} } |
| 106 | + let(:child) { {} } |
| 107 | + |
| 108 | + it 'returns a config equivalent to both' do |
| 109 | + subject.should == parent_config |
| 110 | + subject.should == child_config |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context 'when parent and child are the same' do |
| 115 | + let(:parent) { child } |
| 116 | + |
| 117 | + let(:child) do |
| 118 | + { |
| 119 | + 'plugin_directory' => 'some-directory', |
| 120 | + 'pre-commit' => { |
| 121 | + 'SomeHook' => { |
| 122 | + 'enabled' => false, |
| 123 | + } |
| 124 | + }, |
| 125 | + } |
| 126 | + end |
| 127 | + |
| 128 | + it 'returns a config equivalent to both' do |
| 129 | + subject.should == parent_config |
| 130 | + subject.should == child_config |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + context 'when parent item contains a hash' do |
| 135 | + let(:parent) { { 'pre_commit' => { 'SomeHook' => { 'some-value' => 1 } } } } |
| 136 | + |
| 137 | + context 'and child item contains a different hash under the same key' do |
| 138 | + let(:child) { { 'pre_commit' => { 'SomeOtherHook' => { 'something' => 2 } } } } |
| 139 | + |
| 140 | + it 'merges the hashes together' do |
| 141 | + subject.for_hook('SomeHook', 'pre_commit').should == { 'some-value' => 1 } |
| 142 | + subject.for_hook('SomeOtherHook', 'pre_commit').should == { 'something' => 2 } |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + context 'and child item contains a hash under a different key' do |
| 147 | + let(:child) { { 'commit_msg' => { 'SomeHook' => { 'some-value' => 2 } } } } |
| 148 | + |
| 149 | + it 'appends the item to the parent array' do |
| 150 | + subject.for_hook('SomeHook', 'pre_commit').should == { 'some-value' => 1 } |
| 151 | + subject.for_hook('SomeHook', 'commit_msg').should == { 'some-value' => 2 } |
| 152 | + end |
| 153 | + end |
| 154 | + end |
| 155 | + |
| 156 | + context 'when parent item contains an array' do |
| 157 | + let(:parent) { { 'pre_commit' => { 'SomeHook' => { 'list' => [1, 2, 3] } } } } |
| 158 | + |
| 159 | + context 'and child item contains an array' do |
| 160 | + let(:child) { { 'pre_commit' => { 'SomeHook' => { 'list' => [4, 5] } } } } |
| 161 | + |
| 162 | + it 'concatenates the arrays together' do |
| 163 | + subject.for_hook('SomeHook', 'pre_commit')['list'] == [1, 2, 3, 4, 5] |
| 164 | + end |
| 165 | + end |
| 166 | + |
| 167 | + context 'and child item contains a single item' do |
| 168 | + let(:child) { { 'pre_commit' => { 'SomeHook' => { 'list' => 4 } } } } |
| 169 | + |
| 170 | + it 'appends the item to the parent array' do |
| 171 | + subject.for_hook('SomeHook', 'pre_commit')['list'] == [1, 2, 3, 4] |
| 172 | + end |
| 173 | + end |
| 174 | + end |
| 175 | + end |
98 | 176 | end
|
0 commit comments