diff --git a/config/initializers/administrate.rb b/config/initializers/administrate.rb new file mode 100644 index 000000000..674d6c159 --- /dev/null +++ b/config/initializers/administrate.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'administrate/field/associative' + +module Administrate + module Field + class Associative < Base + module Overrides + def deprecated_option(name) + name == :class_name ? options.fetch(name) : super + end + end + end + end +end + +# Ref: https://github.com/thoughtbot/administrate/commit/f9c5f1af0bd27dbe8e98d43b2074b96004689ad5 +patch_required = Gem::Version.new(Administrate::VERSION) >= Gem::Version.new('1.0.0.beta3') +raise 'Administrate::Field::Associative::Overrides patch is no longer required' if patch_required + +Administrate::Field::Associative.prepend(Administrate::Field::Associative::Overrides) diff --git a/lib/for_education_code_generator.rb b/lib/for_education_code_generator.rb index 4130a01f5..f0da81148 100644 --- a/lib/for_education_code_generator.rb +++ b/lib/for_education_code_generator.rb @@ -3,8 +3,12 @@ class ForEducationCodeGenerator MAX_CODE = 1_000_000 + cattr_accessor :random + + self.random ||= Random.new + def self.generate - number = Random.new.rand(MAX_CODE) + number = random.rand(MAX_CODE) code = format('%06d', number) code.match(/(\d\d)(\d\d)(\d\d)/) do |m| diff --git a/spec/concepts/project/create_remix_spec.rb b/spec/concepts/project/create_remix_spec.rb index 035cf65b9..3978c47bc 100644 --- a/spec/concepts/project/create_remix_spec.rb +++ b/spec/concepts/project/create_remix_spec.rb @@ -124,7 +124,8 @@ it 'persists the new component' do remixed_project = create_remix[:project] - expect(remixed_project.components.first.attributes.symbolize_keys).to include(new_component_params) + new_component = remixed_project.components.find { |c| c.name == new_component_params[:name] } + expect(new_component.attributes.symbolize_keys).to include(new_component_params) end end diff --git a/spec/concepts/school_teacher/invite_spec.rb b/spec/concepts/school_teacher/invite_spec.rb index 6cb579110..43439010b 100644 --- a/spec/concepts/school_teacher/invite_spec.rb +++ b/spec/concepts/school_teacher/invite_spec.rb @@ -16,6 +16,11 @@ expect(response.success?).to be(true) end + it 'does not return an error in operation response' do + response = described_class.call(school:, school_teacher_params:, token:) + expect(response[:error]).to be_blank + end + it 'creates a TeacherInvitation' do expect { described_class.call(school:, school_teacher_params:, token:) }.to change(TeacherInvitation, :count) end diff --git a/spec/lib/for_education_code_generator_spec.rb b/spec/lib/for_education_code_generator_spec.rb index 4245cb5bc..2da0f6e1e 100644 --- a/spec/lib/for_education_code_generator_spec.rb +++ b/spec/lib/for_education_code_generator_spec.rb @@ -5,9 +5,7 @@ RSpec.describe ForEducationCodeGenerator do describe '.generate' do it 'uses Random#rand to generate a random number up to the maximum' do - random = instance_double(Random) - allow(random).to receive(:rand).with(ForEducationCodeGenerator::MAX_CODE).and_return(123) - allow(Random).to receive(:new).and_return(random) + allow(described_class.random).to receive(:rand).with(ForEducationCodeGenerator::MAX_CODE).and_return(123) expect(described_class.generate).to eq('00-01-23') end diff --git a/spec/models/school_project_spec.rb b/spec/models/school_project_spec.rb index 54cc3a717..1bdcd94ee 100644 --- a/spec/models/school_project_spec.rb +++ b/spec/models/school_project_spec.rb @@ -3,5 +3,6 @@ require 'rails_helper' RSpec.describe SchoolProject do - pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to belong_to(:school) } + it { is_expected.to belong_to(:project) } end diff --git a/spec/support/faker.rb b/spec/support/faker.rb new file mode 100644 index 000000000..51d8d9cf7 --- /dev/null +++ b/spec/support/faker.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.before(:suite) do + puts "Faker randomized with seed #{config.seed}" + Faker::Config.random = Random.new(config.seed) + end +end diff --git a/spec/support/for_education_code_generator.rb b/spec/support/for_education_code_generator.rb new file mode 100644 index 000000000..4f28734c3 --- /dev/null +++ b/spec/support/for_education_code_generator.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.before(:suite) do + puts "ForEducationCodeGenerator randomized with seed #{config.seed}" + ForEducationCodeGenerator.random = Random.new(config.seed) + end +end