This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
WIP: Move states into separate tables #1494
Open
adelevie
wants to merge
13
commits into
develop
Choose a base branch
from
move-states-into-separate-tables
base: develop
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
Show all changes
13 commits
Select commit
Hold shift + click to select a range
827a6d6
Corrected mis-named method in auction parser spec
adelevie 70bd6f0
First step towards moving Auction states into separate objects.
adelevie 746ade0
Removed unneeded foreign_key key in states relation
adelevie 4b07a3b
Created AuctionState for archiving auctions.
adelevie 87649ec
Remove unneeded archive_params abstraction
adelevie 4c13e04
Created ChangeState class to manage state changes
adelevie 601e0b3
Move auction archive action into create_published_state
adelevie 1fab82b
Use AuctionParser#published_param to reduce branching in UpdateAuction
adelevie 630842c
Using pry-rails instead of pry
adelevie 2d7ed6a
Created CreateAuction class to wrap BuildAuction and SaveAuction
adelevie 4c07c7b
Create an unpublished auction state in CreateAuction
adelevie 7436f47
Outline breaking apart delivery_status in docs
adelevie 5b6f45e
Create a default work state in CreateAuction
adelevie 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 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 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 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 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 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 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,3 @@ | ||
class AuctionState < ActiveRecord::Base | ||
belongs_to :auction | ||
end |
This file contains 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,36 @@ | ||
class ChangeState | ||
def initialize(auction, state_name, state_value) | ||
@auction = auction | ||
@state_name = state_name | ||
@state_value = state_value | ||
end | ||
|
||
def perform | ||
state.state_value = state_value | ||
state.save | ||
end | ||
|
||
def state | ||
@state ||= find_or_build_state_record | ||
end | ||
|
||
def self.perform(auction, name, value) | ||
new(auction, name, value).perform | ||
end | ||
|
||
private | ||
|
||
attr_reader :auction, :state_name, :state_value | ||
|
||
def find_or_build_state_record | ||
find_state_record || build_state_record | ||
end | ||
|
||
def find_state_record | ||
auction.states.find {|state| state.name == state_name} | ||
end | ||
|
||
def build_state_record | ||
auction.states.build(name: state_name, state_value: state_value) | ||
end | ||
end |
This file contains 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,42 @@ | ||
class CreateAuction | ||
def initialize(params, current_user) | ||
@params = params | ||
@current_user = current_user | ||
end | ||
|
||
def perform | ||
build_auction | ||
save_auction | ||
create_auction_states | ||
|
||
auction | ||
end | ||
|
||
private | ||
|
||
attr_reader :params, :current_user, :auction | ||
|
||
def create_auction_states | ||
create_published_state | ||
create_work_state | ||
# add more states as needed | ||
end | ||
|
||
def create_published_state | ||
change_state = ChangeState.new(auction, 'published', 'unpublished') | ||
change_state.perform | ||
end | ||
|
||
def create_work_state | ||
change_state = ChangeState.new(auction, 'work', 'not_started') | ||
change_state.perform | ||
end | ||
|
||
def build_auction | ||
@auction ||= BuildAuction.new(params, current_user).perform | ||
end | ||
|
||
def save_auction | ||
SaveAuction.new(auction).perform | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -6,17 +6,33 @@ def initialize(auction:, params:, current_user:) | |
end | ||
|
||
def perform | ||
assign_attributes | ||
update_auction_ended_job | ||
perform_accepted_auction_tasks | ||
perform_rejected_auction_tasks | ||
auction.save | ||
create_auction_states | ||
|
||
if ArchiveAuction.archive_submit?(params) | ||
ArchiveAuction.new(auction: auction).perform | ||
else | ||
assign_attributes | ||
update_auction_ended_job | ||
perform_accepted_auction_tasks | ||
perform_rejected_auction_tasks | ||
auction.save | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :auction, :params, :current_user | ||
|
||
def create_auction_states | ||
create_published_state | ||
# add more state creation here, as needed | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I get! |
||
def create_published_state | ||
change_state = ChangeState.new(auction, 'published', parser.published_param) | ||
change_state.perform | ||
end | ||
|
||
def assign_attributes | ||
auction.assign_attributes(parsed_attributes) | ||
end | ||
|
@@ -71,8 +87,12 @@ def auction_rejected? | |
parsed_attributes[:status] == 'rejected' | ||
end | ||
|
||
def parser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed I need to be smarter about the memoization. I could fix this by memoizing |
||
@_parser ||= AuctionParser.new(params, user) | ||
end | ||
|
||
def parsed_attributes | ||
@_parsed_attributes ||= AuctionParser.new(params, user).attributes | ||
parser.attributes | ||
end | ||
|
||
def user | ||
|
This file contains 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,9 @@ | ||
class CreateAuctionStates < ActiveRecord::Migration | ||
def change | ||
create_table :auction_states do |t| | ||
t.integer :auction_id | ||
t.string :state_value | ||
t.string :name | ||
end | ||
end | ||
end |
This file contains 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 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,6 +1,8 @@ | ||
db: | ||
image: postgres:9 | ||
web: | ||
tty: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useful for |
||
stdin_open: true | ||
build: . | ||
env_file: .env | ||
environment: | ||
|
Oops, something went wrong.
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.
Let's consider changing the published state name to something like
visibility
.