-
Notifications
You must be signed in to change notification settings - Fork 2
[530] Seed script generates draws in each stage #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
murphy-ariel
wants to merge
3
commits into
master
Choose a base branch
from
530_seed_script_draws_in_every_phase
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Seed script generator for Draws | ||
| class DrawGenerator | ||
| def self.generate(**overrides) | ||
| new(overrides: overrides).generate | ||
| end | ||
|
|
||
| def initialize(overrides: {}) | ||
| gen_params(overrides: overrides) | ||
| gen_params(overrides) | ||
| end | ||
|
|
||
| def generate | ||
| DrawCreator.new(params).create![:object] | ||
| Draw.create(params) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :params | ||
| attr_reader :params, :suites | ||
|
|
||
| def gen_params(overrides: {}) | ||
| check_member_existence | ||
| @params ||= { suites: Suite.all.sample(3), | ||
| students: User.where(role: 'student', draw_id: nil).sample(5), | ||
| @params ||= { suites: suites, | ||
| name: "#{FFaker::Music.artist} Draw" }.merge(overrides) | ||
| end | ||
|
|
||
| def check_member_existence | ||
| 5.times { SuiteGenerator.generate } unless Suite.all.count >= 5 | ||
| @suites = Array.new(5) { SuiteGenerator.generate } | ||
| suites.each { |s| RoomGenerator.generate(suite: s) } | ||
| 8.times { UserGenerator.generate } unless User.all.count >= 8 | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Seed script generator for Suites | ||
| class GroupGenerator | ||
| def self.generate(**params) | ||
| new(**params).generate | ||
| end | ||
|
|
||
| def initialize(draw:, overrides: {}) | ||
| gen_params(draw: draw, overrides: overrides) | ||
| end | ||
|
|
||
| def generate | ||
| Group.create!(params) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :params | ||
|
|
||
| def gen_params(draw:, overrides: {}) | ||
| size = draw.suite_sizes.sample | ||
| members = Array.new(size) do |_d| | ||
| UserGenerator.generate(draw: draw, intent: 'on_campus') | ||
| end | ||
| @params ||= { leader: members.sample, | ||
| size: size, | ||
| members: members, | ||
| draw: draw }.merge!(overrides) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Seed script generator for Draws | ||
| class LotteryDrawGenerator | ||
| def self.generate(**overrides) | ||
| new(overrides: overrides).generate | ||
| end | ||
|
|
||
| def initialize(overrides: {}); end | ||
|
|
||
| def generate(overrides: {}) | ||
| create_draw_params(overrides: overrides) | ||
| make_lottery_draw(overrides: overrides) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :params | ||
|
|
||
| def create_draw_params(overrides: {}) | ||
| suites = Array.new(5) { SuiteGenerator.generate } | ||
| suites.each { |s| RoomGenerator.generate(suite: s) } | ||
| @params ||= { suites: suites, | ||
| name: "#{FFaker::Music.artist} Draw" }.merge!(overrides) | ||
| end | ||
|
|
||
| def make_lottery_draw(overrides: {}) | ||
| Draw.create!(params).tap do |d| | ||
| d.update(status: 'pre_lottery') | ||
| groups = Array.new(3) do | ||
| GroupGenerator.generate(draw: d, overrides: overrides) | ||
| end | ||
| groups.each do |g| | ||
| GroupLocker.lock(group: g) | ||
| end | ||
| DrawLotteryStarter.start(draw: d) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Seed script generator for Draws | ||
| class PreLotteryDrawGenerator | ||
| def self.generate(**overrides) | ||
| new(overrides: overrides).generate | ||
| end | ||
|
|
||
| def initialize(overrides: {}); end | ||
|
|
||
| def generate(overrides: {}) | ||
| DrawGenerator.generate(overrides: overrides).tap do |d| | ||
| 3.times { GroupGenerator.generate(draw: d, overrides: overrides) } | ||
| d.update(status: 'pre_lottery') | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Seed script generator for Draws | ||
| class SuiteSelectionDrawGenerator | ||
| def self.generate(**overrides) | ||
| new(overrides: overrides).generate | ||
| end | ||
|
|
||
| def initialize(overrides: {}); end | ||
|
|
||
| def generate(overrides: {}) | ||
| LotteryDrawGenerator.generate(overrides: overrides).tap do |d| | ||
| d.groups.each do |g| | ||
| g.lottery_number = (g.id / 2).round | ||
| end | ||
| d.update(status: 'suite_selection') | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| describe GroupGenerator do | ||
| context 'creating' do | ||
| it 'makes a new group' do | ||
| draw = FactoryGirl.create(:draw) | ||
| draw.suites << FactoryGirl.create(:suite, size: 3) | ||
| expect { described_class.generate(draw: draw) }.to \ | ||
| change { Group.count }.by(1) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| describe LotteryDrawGenerator do | ||
| context 'creating' do | ||
| it 'makes a new draw' do | ||
| expect { described_class.generate }.to \ | ||
| change { Draw.count }.by(1) | ||
| end | ||
|
|
||
| it 'makes the draw be in pre-lottery' do | ||
| expect(described_class.generate).to be_lottery | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| describe PreLotteryDrawGenerator do | ||
| context 'creating' do | ||
| it 'makes a new draw' do | ||
| expect { described_class.generate }.to \ | ||
| change { Draw.count }.by(1) | ||
| end | ||
|
|
||
| it 'makes the draw be in pre-lottery' do | ||
| expect(described_class.generate).to be_pre_lottery | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| describe SuiteSelectionDrawGenerator do | ||
| context 'creating' do | ||
| it 'makes a new draw' do | ||
| expect { described_class.generate }.to \ | ||
| change { Draw.count }.by(1) | ||
| end | ||
|
|
||
| it 'makes the draw be in pre-lottery' do | ||
| expect(described_class.generate).to \ | ||
| be_suite_selection | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should call
create_draw_params(overrides)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i moved the create_draw_params method to the other generate method