Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieay committed Aug 5, 2016
1 parent 53c659d commit f0e35d5
Show file tree
Hide file tree
Showing 44 changed files with 475 additions and 371 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
ruby '2.3.1'

gem 'rails', '4.2.6'
gem 'uswds-rails', github: '18F/uswds-rails-gem', branch: 'jy-add-the-assets'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
@@ -1,3 +1,10 @@
GIT
remote: git://github.com/18F/uswds-rails-gem.git
revision: 513f5efa242e80cd820250d116f975aa5be0c67a
branch: jy-add-the-assets
specs:
uswds-rails (1.0.0)

GIT
remote: git://github.com/18f/c2-api-client-ruby.git
revision: 1404abe563c1a1048c91a319a488be5d6a172936
Expand Down Expand Up @@ -463,6 +470,7 @@ DEPENDENCIES
sinatra
timecop
uglifier
uswds-rails!
validate_url
web-console (~> 2.0)
webmock
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/proposals_controller.rb
@@ -1,6 +1,7 @@
class Admin::ProposalsController < Admin::BaseController
def create
if should_create_c2_proposal?
auction.update(c2_approval_status: :pending)
CreateC2ProposalJob.perform_later(auction.id)
flash[:success] = I18n.t('controllers.admin.proposals.create.success')
else
Expand Down
1 change: 1 addition & 0 deletions app/models/auction.rb
Expand Up @@ -14,6 +14,7 @@ class Auction < ActiveRecord::Base
enum type: { sealed_bid: 0, reverse: 1 }
enum published: { unpublished: 0, published: 1 }
enum purchase_card: { default: 0, other: 1 }
enum c2_approval_status: { not_requested: 0, pending: 1, pending_approval: 2, approved: 3 }

# Disable STI
self.inheritance_column = :__disabled
Expand Down
94 changes: 94 additions & 0 deletions app/models/bid_status_presenter_factory.rb
@@ -0,0 +1,94 @@
class BidStatusPresenterFactory
attr_reader :auction, :user

def initialize(auction:, user:)
@auction = auction
@user = user
end

def create
if future?
future_message
elsif over?
over_message
else
available_message
end
end

private

def available_message
if admin?
BidStatusPresenter::AvailableUserIsAdmin.new(auction: auction)
elsif guest?
BidStatusPresenter::AvailableUserIsGuest.new(auction: auction)
elsif auction.type == 'reverse'
BidStatusPresenter::AvailableUserIsWinningBidder.new(bid_amount: lowest_user_bid.try(:amount))
else # sealed bid, user is bidder
BidStatusPresenter::AvailableSealedUserIsBidder.new(bid: lowest_user_bid)
end
end

def future_message
if admin?
BidStatusPresenter::FutureUserIsAdmin.new(auction: auction)
elsif guest?
BidStatusPresenter::FutureUserIsGuest.new(auction: auction)
else
BidStatusPresenter::FutureUserIsVendor.new(auction: auction)
end
end

def over_message
if user_is_winning_bidder?
BidStatusPresenter::OverUserIsWinner.new
elsif user_is_bidder?
BidStatusPresenter::OverUserIsBidder.new
elsif auction.bids.any?
BidStatusPresenter::OverWithBids.new
else
BidStatusPresenter::OverNoBids.new
end
end

def admin?
user.decorate.admin?
end

def guest?
user.is_a?(Guest)
end

def over?
auction_status.over?
end

def available?
auction_status.available?
end

def future?
auction_status.future?
end

def auction_status
AuctionStatus.new(auction)
end

def user_is_winning_bidder?
user_bids.any? && lowest_user_bid == auction.lowest_bid
end

def user_is_bidder?
user_bids.any?
end

def lowest_user_bid
user_bids.order(amount: :asc).first
end

def user_bids
auction.bids.where(bidder: user)
end
end
15 changes: 15 additions & 0 deletions app/models/c2_status_presenter_factory.rb
@@ -0,0 +1,15 @@
class C2StatusPresenterFactory
attr_reader :auction

def initialize(auction:)
@auction = auction
end

def create
if auction.c2_approval_status == 'not_requested'
C2StatusPresenter::C2ApprovalNotRequested.new(auction: auction)
else
C2StatusPresenter::C2Pending.new
end
end
end
2 changes: 1 addition & 1 deletion app/models/status_presenter_factory.rb
Expand Up @@ -6,7 +6,7 @@ def initialize(auction)
end

def create
"StatusPresenter::#{status_name}".constantize.new(auction)
Object.const_get("StatusPresenter::#{status_name}").new(auction)
end

private
Expand Down
157 changes: 0 additions & 157 deletions app/presenters/auction_status_presenter_factory.rb

This file was deleted.

0 comments on commit f0e35d5

Please sign in to comment.