|
2 | 2 |
|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | | -RSpec.describe BetterTogether::Seed, type: :model do # rubocop:todo Metrics/BlockLength |
| 5 | +RSpec.describe BetterTogether::Seed do |
6 | 6 | subject(:seed) { build(:better_together_seed) } |
7 | 7 |
|
8 | 8 | describe 'validations' do |
|
54 | 54 | # ------------------------------------------------------------------- |
55 | 55 | # Specs for .load_seed |
56 | 56 | # ------------------------------------------------------------------- |
57 | | - describe '.load_seed' do # rubocop:todo Metrics/BlockLength |
| 57 | + describe '.load_seed' do |
58 | 58 | let(:valid_seed_data) do |
59 | 59 | { |
60 | 60 | 'better_together' => { |
|
85 | 85 | allow(YAML).to receive(:load_file).and_call_original |
86 | 86 | end |
87 | 87 |
|
88 | | - context 'when the source is a direct file path' do # rubocop:todo Metrics/BlockLength |
89 | | - context 'and the file exists' do |
| 88 | + context 'when the source is a direct file path' do |
| 89 | + # rubocop:todo RSpec/NestedGroups |
| 90 | + context 'and the file exists' do # rubocop:todo RSpec/ContextWording, RSpec/NestedGroups |
| 91 | + # rubocop:enable RSpec/NestedGroups |
90 | 92 | before do |
91 | 93 | allow(File).to receive(:exist?).with(file_path).and_return(true) |
92 | 94 | allow(YAML).to receive(:load_file).with(file_path).and_return(valid_seed_data) |
93 | 95 | end |
94 | 96 |
|
95 | | - it 'imports the seed and returns a BetterTogether::Seed record' do |
| 97 | + it 'imports the seed and returns a BetterTogether::Seed record' do # rubocop:todo RSpec/MultipleExpectations |
96 | 98 | result = described_class.load_seed(file_path) |
97 | 99 | expect(result).to be_a(described_class) |
98 | 100 | expect(result.identifier).to eq('from_test') |
99 | 101 | expect(result.payload[:payload_key]).to eq('payload_value') |
100 | 102 | end |
101 | 103 | end |
102 | 104 |
|
103 | | - context 'but the file does not exist' do |
| 105 | + # rubocop:todo RSpec/NestedGroups |
| 106 | + context 'but the file does not exist' do # rubocop:todo RSpec/ContextWording, RSpec/NestedGroups |
| 107 | + # rubocop:enable RSpec/NestedGroups |
104 | 108 | it 'falls back to namespace logic and raises an error' do |
105 | 109 | expect do |
106 | 110 | described_class.load_seed(file_path) |
107 | 111 | end.to raise_error(RuntimeError, /Seed file not found for/) |
108 | 112 | end |
109 | 113 | end |
110 | 114 |
|
111 | | - context 'when YAML loading raises an error' do |
| 115 | + context 'when YAML loading raises an error' do # rubocop:todo RSpec/NestedGroups |
112 | 116 | before do |
113 | 117 | allow(File).to receive(:exist?).with(file_path).and_return(true) |
114 | 118 | allow(YAML).to receive(:load_file).with(file_path).and_raise(StandardError, 'Bad YAML') |
|
122 | 126 | end |
123 | 127 | end |
124 | 128 |
|
125 | | - context 'when the source is a namespace' do # rubocop:todo Metrics/BlockLength |
| 129 | + context 'when the source is a namespace' do |
126 | 130 | let(:namespace) { 'better_together/wizards/host_setup_wizard' } |
127 | 131 | let(:full_path) { Rails.root.join('config', 'seeds', "#{namespace}.yml").to_s } |
128 | 132 |
|
129 | | - context 'and the file exists' do |
| 133 | + # rubocop:todo RSpec/NestedGroups |
| 134 | + context 'and the file exists' do # rubocop:todo RSpec/ContextWording, RSpec/NestedGroups |
| 135 | + # rubocop:enable RSpec/NestedGroups |
130 | 136 | before do |
131 | 137 | allow(File).to receive(:exist?).with(namespace).and_return(false) |
132 | 138 | allow(File).to receive(:exist?).with(full_path).and_return(true) |
133 | 139 | allow(YAML).to receive(:load_file).with(full_path).and_return(valid_seed_data) |
134 | 140 | end |
135 | 141 |
|
136 | | - it 'imports the seed from the namespace path' do |
| 142 | + it 'imports the seed from the namespace path' do # rubocop:todo RSpec/MultipleExpectations |
137 | 143 | result = described_class.load_seed(namespace) |
138 | 144 | expect(result).to be_a(described_class) |
139 | 145 | expect(result.identifier).to eq('from_test') |
140 | 146 | end |
141 | 147 | end |
142 | 148 |
|
143 | | - context 'but the file does not exist' do |
| 149 | + # rubocop:todo RSpec/NestedGroups |
| 150 | + context 'but the file does not exist' do # rubocop:todo RSpec/ContextWording, RSpec/NestedGroups |
| 151 | + # rubocop:enable RSpec/NestedGroups |
144 | 152 | before do |
145 | 153 | allow(File).to receive(:exist?).with(namespace).and_return(false) |
146 | 154 | allow(File).to receive(:exist?).with(full_path).and_return(false) |
|
153 | 161 | end |
154 | 162 | end |
155 | 163 |
|
156 | | - context 'when YAML loading raises an error' do |
| 164 | + context 'when YAML loading raises an error' do # rubocop:todo RSpec/NestedGroups |
157 | 165 | before do |
158 | 166 | allow(File).to receive(:exist?).with(namespace).and_return(false) |
159 | 167 | allow(File).to receive(:exist?).with(full_path).and_return(true) |
|
178 | 186 | create(:better_together_seed) |
179 | 187 | end |
180 | 188 |
|
181 | | - it 'attaches a YAML file after creation' do |
| 189 | + it 'attaches a YAML file after creation' do # rubocop:todo RSpec/NoExpectationExample |
182 | 190 | # seed.reload # Ensures the record reloads from the DB after the commit callback |
183 | 191 | # expect(seed.yaml_file).to be_attached |
184 | 192 |
|
|
0 commit comments