Skip to content

Commit c8f5384

Browse files
committed
Rubocop fixes
1 parent abcec97 commit c8f5384

File tree

10 files changed

+52
-42
lines changed

10 files changed

+52
-42
lines changed

app/models/concerns/better_together/seedable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def export_collection_as_seed( # rubocop:todo Metrics/MethodLength
141141
seed_hash
142142
end
143143

144-
def export_collection_as_seed_yaml(records, **opts)
145-
export_collection_as_seed(records, **opts).deep_stringify_keys.to_yaml
144+
def export_collection_as_seed_yaml(records, **)
145+
export_collection_as_seed(records, **).deep_stringify_keys.to_yaml
146146
end
147147
end
148148
end

spec/concerns/better_together/seedable_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
module BetterTogether
66
describe Seedable, type: :model do
77
# Define a test ActiveRecord model inline for this spec
8+
# rubocop:todo RSpec/LeakyConstantDeclaration
89
class TestSeedableClass < ApplicationRecord # rubocop:todo Lint/ConstantDefinitionInBlock
910
include Seedable
1011
end
12+
# rubocop:enable RSpec/LeakyConstantDeclaration
1113

12-
before(:all) do
14+
before(:all) do # rubocop:todo RSpec/BeforeAfterAll
1315
create_table(:better_together_test_seedable_classes) do |t|
1416
t.string :name
1517
end
1618
end
1719

18-
after(:all) do
20+
after(:all) do # rubocop:todo RSpec/BeforeAfterAll
1921
drop_table(:better_together_test_seedable_classes)
2022
end
2123

spec/factories/better_together/seeds.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

3-
FactoryBot.define do # rubocop:todo Metrics/BlockLength
4-
factory :better_together_seed, class: 'BetterTogether::Seed' do # rubocop:todo Metrics/BlockLength
3+
FactoryBot.define do
4+
factory :better_together_seed, class: 'BetterTogether::Seed' do
55
id { SecureRandom.uuid }
66
version { '1.0' }
77
created_by { 'Better Together Solutions' }

spec/helpers/better_together/seeds_helper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# end
1414
# end
1515
module BetterTogether
16-
RSpec.describe SeedsHelper, type: :helper do
16+
RSpec.describe SeedsHelper do
1717
pending "add some examples to (or delete) #{__FILE__}"
1818
end
1919
end

spec/models/better_together/seed_spec.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe BetterTogether::Seed, type: :model do # rubocop:todo Metrics/BlockLength
5+
RSpec.describe BetterTogether::Seed do
66
subject(:seed) { build(:better_together_seed) }
77

88
describe 'validations' do
@@ -54,7 +54,7 @@
5454
# -------------------------------------------------------------------
5555
# Specs for .load_seed
5656
# -------------------------------------------------------------------
57-
describe '.load_seed' do # rubocop:todo Metrics/BlockLength
57+
describe '.load_seed' do
5858
let(:valid_seed_data) do
5959
{
6060
'better_together' => {
@@ -85,30 +85,34 @@
8585
allow(YAML).to receive(:load_file).and_call_original
8686
end
8787

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
9092
before do
9193
allow(File).to receive(:exist?).with(file_path).and_return(true)
9294
allow(YAML).to receive(:load_file).with(file_path).and_return(valid_seed_data)
9395
end
9496

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
9698
result = described_class.load_seed(file_path)
9799
expect(result).to be_a(described_class)
98100
expect(result.identifier).to eq('from_test')
99101
expect(result.payload[:payload_key]).to eq('payload_value')
100102
end
101103
end
102104

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
104108
it 'falls back to namespace logic and raises an error' do
105109
expect do
106110
described_class.load_seed(file_path)
107111
end.to raise_error(RuntimeError, /Seed file not found for/)
108112
end
109113
end
110114

111-
context 'when YAML loading raises an error' do
115+
context 'when YAML loading raises an error' do # rubocop:todo RSpec/NestedGroups
112116
before do
113117
allow(File).to receive(:exist?).with(file_path).and_return(true)
114118
allow(YAML).to receive(:load_file).with(file_path).and_raise(StandardError, 'Bad YAML')
@@ -122,25 +126,29 @@
122126
end
123127
end
124128

125-
context 'when the source is a namespace' do # rubocop:todo Metrics/BlockLength
129+
context 'when the source is a namespace' do
126130
let(:namespace) { 'better_together/wizards/host_setup_wizard' }
127131
let(:full_path) { Rails.root.join('config', 'seeds', "#{namespace}.yml").to_s }
128132

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
130136
before do
131137
allow(File).to receive(:exist?).with(namespace).and_return(false)
132138
allow(File).to receive(:exist?).with(full_path).and_return(true)
133139
allow(YAML).to receive(:load_file).with(full_path).and_return(valid_seed_data)
134140
end
135141

136-
it 'imports the seed from the namespace path' do
142+
it 'imports the seed from the namespace path' do # rubocop:todo RSpec/MultipleExpectations
137143
result = described_class.load_seed(namespace)
138144
expect(result).to be_a(described_class)
139145
expect(result.identifier).to eq('from_test')
140146
end
141147
end
142148

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
144152
before do
145153
allow(File).to receive(:exist?).with(namespace).and_return(false)
146154
allow(File).to receive(:exist?).with(full_path).and_return(false)
@@ -153,7 +161,7 @@
153161
end
154162
end
155163

156-
context 'when YAML loading raises an error' do
164+
context 'when YAML loading raises an error' do # rubocop:todo RSpec/NestedGroups
157165
before do
158166
allow(File).to receive(:exist?).with(namespace).and_return(false)
159167
allow(File).to receive(:exist?).with(full_path).and_return(true)
@@ -178,7 +186,7 @@
178186
create(:better_together_seed)
179187
end
180188

181-
it 'attaches a YAML file after creation' do
189+
it 'attaches a YAML file after creation' do # rubocop:todo RSpec/NoExpectationExample
182190
# seed.reload # Ensures the record reloads from the DB after the commit callback
183191
# expect(seed.yaml_file).to be_attached
184192

spec/support/shared_examples/a_seedable_model.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

3-
RSpec.shared_examples 'a seedable model' do # rubocop:todo Metrics/BlockLength
3+
RSpec.shared_examples 'a seedable model' do
44
it 'includes the Seedable concern' do
55
expect(described_class.ancestors).to include(BetterTogether::Seedable)
66
end
77

8-
describe 'Seedable instance methods' do # rubocop:todo Metrics/BlockLength
8+
describe 'Seedable instance methods' do
99
# Use create(...) so the record is persisted in the test database
1010
let(:record) { create(described_class.name.underscore.to_sym) }
1111

@@ -21,7 +21,7 @@
2121
expect(record).to respond_to(:export_as_seed_yaml)
2222
end
2323

24-
context '#export_as_seed' do
24+
describe '#export_as_seed' do
2525
it 'returns a hash with the default root key' do
2626
seed_hash = record.export_as_seed
2727
expect(seed_hash.keys).to include(BetterTogether::Seed::DEFAULT_ROOT_KEY)
@@ -34,16 +34,16 @@
3434
end
3535
end
3636

37-
context '#export_as_seed_yaml' do
38-
it 'returns a valid YAML string' do
37+
describe '#export_as_seed_yaml' do
38+
it 'returns a valid YAML string' do # rubocop:todo RSpec/MultipleExpectations
3939
yaml_str = record.export_as_seed_yaml
4040
expect(yaml_str).to be_a(String)
4141
expect(yaml_str).to include(BetterTogether::Seed::DEFAULT_ROOT_KEY.to_s)
4242
end
4343
end
4444
end
4545

46-
describe 'Seedable class methods' do # rubocop:todo Metrics/BlockLength
46+
describe 'Seedable class methods' do
4747
let(:records) { build_list(described_class.name.underscore.to_sym, 3) }
4848

4949
it 'responds to .export_collection_as_seed' do
@@ -54,13 +54,13 @@
5454
expect(described_class).to respond_to(:export_collection_as_seed_yaml)
5555
end
5656

57-
context '.export_collection_as_seed' do
57+
describe '.export_collection_as_seed' do
5858
it 'returns a hash with the default root key' do
5959
collection_hash = described_class.export_collection_as_seed(records)
6060
expect(collection_hash.keys).to include(BetterTogether::Seed::DEFAULT_ROOT_KEY)
6161
end
6262

63-
it 'includes an array of records under :records' do
63+
it 'includes an array of records under :records' do # rubocop:todo RSpec/MultipleExpectations
6464
collection_hash = described_class.export_collection_as_seed(records)
6565
root_key = collection_hash.keys.first
6666
expect(collection_hash[root_key]).to have_key(:records)
@@ -69,8 +69,8 @@
6969
end
7070
end
7171

72-
context '.export_collection_as_seed_yaml' do
73-
it 'returns a valid YAML string' do
72+
describe '.export_collection_as_seed_yaml' do
73+
it 'returns a valid YAML string' do # rubocop:todo RSpec/MultipleExpectations
7474
yaml_str = described_class.export_collection_as_seed_yaml(records)
7575
expect(yaml_str).to be_a(String)
7676
expect(yaml_str).to include(BetterTogether::Seed::DEFAULT_ROOT_KEY.to_s)

spec/views/better_together/seeds/edit.html.erb_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe 'seeds/edit', type: :view do
5+
RSpec.describe 'seeds/edit' do
66
let(:seed) do
77
create(:better_together_seed)
88
end
99

10-
before(:each) do
10+
before do
1111
assign(:seed, seed)
1212
end
1313

14-
it 'renders the edit seed form' do
14+
it 'renders the edit seed form' do # rubocop:todo RSpec/NoExpectationExample
1515
# render
1616

1717
# assert_select "form[action=?][method=?]", seed_path(seed), "post" do

spec/views/better_together/seeds/index.html.erb_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe 'seeds/index', type: :view do
6-
before(:each) do
5+
RSpec.describe 'seeds/index' do
6+
before do
77
assign(:seeds, [
88
create(:better_together_seed),
99
create(:better_together_seed)
1010
])
1111
end
1212

13-
it 'renders a list of seeds' do
13+
it 'renders a list of seeds' do # rubocop:todo RSpec/NoExpectationExample
1414
# render
1515
# cell_selector = 'div>p'
1616
end

spec/views/better_together/seeds/new.html.erb_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe 'seeds/new', type: :view do
6-
before(:each) do
5+
RSpec.describe 'seeds/new' do
6+
before do
77
assign(:seed, build(:better_together_seed))
88
end
99

10-
it 'renders new seed form' do
10+
it 'renders new seed form' do # rubocop:todo RSpec/NoExpectationExample
1111
# render
1212

1313
# assert_select "form[action=?][method=?]", seeds_path, "post" do

spec/views/better_together/seeds/show.html.erb_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe 'seeds/show', type: :view do
6-
before(:each) do
5+
RSpec.describe 'seeds/show' do
6+
before do
77
assign(:seed, create(:better_together_seed))
88
end
99

10-
it 'renders attributes in <p>' do
10+
it 'renders attributes in <p>' do # rubocop:todo RSpec/NoExpectationExample
1111
# render
1212
end
1313
end

0 commit comments

Comments
 (0)