From 2c9346cf7d2fc930b86645c63898388dc0112ff1 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sun, 28 Apr 2019 14:40:59 +0200 Subject: [PATCH 1/4] Add Rake Task to lint Factories --- lib/tasks/factorybot.rake | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 lib/tasks/factorybot.rake diff --git a/lib/tasks/factorybot.rake b/lib/tasks/factorybot.rake new file mode 100644 index 0000000..d09b34c --- /dev/null +++ b/lib/tasks/factorybot.rake @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +namespace :factorybot do + desc 'Lint FactoryBot factories' + task :lint do |_| + FactoryBot.lint + end +end From 1759e9ea0233aa770aff16695494b94cdc7ef660 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Thu, 2 May 2019 12:04:33 +0200 Subject: [PATCH 2/4] Add missing environment to lint task --- lib/tasks/factorybot.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/factorybot.rake b/lib/tasks/factorybot.rake index d09b34c..7ae5e59 100644 --- a/lib/tasks/factorybot.rake +++ b/lib/tasks/factorybot.rake @@ -2,7 +2,7 @@ namespace :factorybot do desc 'Lint FactoryBot factories' - task :lint do |_| + task lint: :environment do FactoryBot.lint end end From 9de127e75a2389edebdc7d410393b94a716f5ff9 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 13 May 2019 16:46:13 +0200 Subject: [PATCH 3/4] Change from rake Task to a single spec This has the advantage that if you run the whole suite it gets run automatically but if you run a single test it doesn't. This seems like the best of both worlds.. --- lib/tasks/factorybot.rake | 8 -------- spec/factorybot_lint_spec.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 lib/tasks/factorybot.rake create mode 100644 spec/factorybot_lint_spec.rb diff --git a/lib/tasks/factorybot.rake b/lib/tasks/factorybot.rake deleted file mode 100644 index 7ae5e59..0000000 --- a/lib/tasks/factorybot.rake +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -namespace :factorybot do - desc 'Lint FactoryBot factories' - task lint: :environment do - FactoryBot.lint - end -end diff --git a/spec/factorybot_lint_spec.rb b/spec/factorybot_lint_spec.rb new file mode 100644 index 0000000..1639768 --- /dev/null +++ b/spec/factorybot_lint_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'FactoryBot' do + it 'has valid factories' do + FactoryBot.lint + end +end From cda1cfcb501da735f6383c3f2f386efddec6b66a Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 13 May 2019 16:47:34 +0200 Subject: [PATCH 4/4] Remove deprecated Factory Tests --- spec/models/group_score_spec.rb | 4 ---- spec/models/group_spec.rb | 4 ---- spec/models/match_score_spec.rb | 4 ---- spec/models/match_spec.rb | 6 ------ spec/models/stage_spec.rb | 5 ----- spec/models/team_spec.rb | 5 ----- spec/models/tournament_spec.rb | 6 ------ spec/models/user_spec.rb | 4 ---- 8 files changed, 38 deletions(-) diff --git a/spec/models/group_score_spec.rb b/spec/models/group_score_spec.rb index 8056e32..1a995eb 100644 --- a/spec/models/group_score_spec.rb +++ b/spec/models/group_score_spec.rb @@ -7,8 +7,4 @@ RSpec.describe GroupScore, type: :model do it { should belong_to :team } it { should belong_to :group } end - - it 'has a valid factory' do - expect(build(:group_score)).to be_valid - end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index e8c8be2..99ae876 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -9,10 +9,6 @@ RSpec.describe Group, type: :model do it { should have_many :group_scores } end - it 'has a valid factory' do - expect(build(:group)).to be_valid - end - describe '#teams' do before do @group = create(:group, match_count: 1) # this is getting stubbed anyways diff --git a/spec/models/match_score_spec.rb b/spec/models/match_score_spec.rb index a48734f..b6f7bfc 100644 --- a/spec/models/match_score_spec.rb +++ b/spec/models/match_score_spec.rb @@ -7,8 +7,4 @@ RSpec.describe MatchScore, type: :model do it { should belong_to :match } it { should belong_to :team } end - - it 'has a valid factory' do - expect(build(:match_score)).to be_valid - end end diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 01d34c5..5acec23 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -76,10 +76,4 @@ RSpec.describe Match, type: :model do end end end - - it 'has a valid factory' do - expect(build(:match)).to be_valid - expect(build(:running_playoff_match)).to be_valid - expect(build(:group_match)).to be_valid - end end diff --git a/spec/models/stage_spec.rb b/spec/models/stage_spec.rb index a14fccd..ac1dc72 100644 --- a/spec/models/stage_spec.rb +++ b/spec/models/stage_spec.rb @@ -9,11 +9,6 @@ RSpec.describe Stage, type: :model do it { should have_many :groups } end - it 'has a valid factory' do - expect(build(:stage)).to be_valid - expect(build(:group_stage)).to be_valid - end - describe '#teams' do context 'group stage' do before do diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index d1e477b..c2f25e3 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -12,9 +12,4 @@ RSpec.describe Team, type: :model do it { should have_many :group_scores } it { should have_many :match_scores } end - - it 'has a valid factory' do - expect(build(:team)).to be_valid - expect(build(:detached_team)).to be_valid - end end diff --git a/spec/models/tournament_spec.rb b/spec/models/tournament_spec.rb index c437df8..20e6f6b 100644 --- a/spec/models/tournament_spec.rb +++ b/spec/models/tournament_spec.rb @@ -30,10 +30,4 @@ RSpec.describe Tournament, type: :model do it { should have_many :teams } it { should have_many :stages } end - - it 'has valid factory' do - expect(build(:tournament)).to be_valid - expect(build(:stage_tournament)).to be_valid - expect(build(:group_stage_tournament)).to be_valid - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c3ee007..7216b64 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -12,8 +12,4 @@ RSpec.describe User, type: :model do it { should validate_presence_of :username } it { should validate_uniqueness_of(:username).case_insensitive } end - - it 'has a valid factory' do - expect(build(:user)).to be_valid - end end