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

Commit

Permalink
Merge 150d625 into 513968d
Browse files Browse the repository at this point in the history
  • Loading branch information
adelevie committed May 14, 2016
2 parents 513968d + 150d625 commit ec4f4bb
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 19 deletions.
6 changes: 2 additions & 4 deletions app/models/auction.rb
@@ -1,6 +1,4 @@
class Auction < ActiveRecord::Base
MAX_START_PRICE = 3500

belongs_to :user
has_many :bids
has_many :bidders, through: :bids
Expand Down Expand Up @@ -32,12 +30,12 @@ def lowest_amount
end

def start_price_equal_to_or_less_than_max_if_not_contracting_officer
if user && !user.contracting_officer? && start_price > MAX_START_PRICE
if user && !user.contracting_officer? && start_price > StartPriceThresholds::MICROPURCHASE
errors.add(
:start_price,
I18n.t(
'activerecord.errors.models.auction.attributes.start_price.invalid',
start_price: MAX_START_PRICE
start_price: StartPriceThresholds::MICROPURCHASE
)
)
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/eligibilities/in_sam.rb
@@ -0,0 +1,5 @@
class Eligibility::InSam
def eligible?(user)
user.sam_accepted?
end
end
5 changes: 5 additions & 0 deletions app/models/eligibilities/small_business.rb
@@ -0,0 +1,5 @@
class Eligibility::SmallBusiness
def eligible?(user)
InSamEligibility.new.eligible?(user) && user.small_business?
end
end
15 changes: 15 additions & 0 deletions app/models/eligibility_factory.rb
@@ -0,0 +1,15 @@
class EligibilityFactory
attr_reader :auction

def initialize(auction)
@auction = AuctionPresenter.new(auction)
end

def create
if auction.small_business?
SmallBusinessEligibility.new
else
InSamEligibility.new
end
end
end
5 changes: 5 additions & 0 deletions app/models/in_sam_eligibility.rb
@@ -0,0 +1,5 @@
class InSamEligibility
def eligible?(user)
user.sam_accepted?
end
end
14 changes: 12 additions & 2 deletions app/models/rules/base_rules.rb
@@ -1,10 +1,20 @@
class Rules::BaseRules < Struct.new(:auction)
class Rules::BaseRules
attr_reader :auction
attr_reader :eligibility

def initialize(auction, eligibility)
@auction = auction
@eligibility = eligibility
end

def partial_path(name, base_dir = 'auctions')
"#{base_dir}/#{partial_prefix}/#{name}.html.erb"
end

def user_can_bid?(user)
auction.available? && user.present? && user.sam_accepted?
auction.available? &&
user.present? &&
eligibility.eligible?(user)
end

def partial_prefix
Expand Down
6 changes: 4 additions & 2 deletions app/models/rules_factory.rb
Expand Up @@ -4,10 +4,12 @@ def initialize(auction)
end

def create
eligibility = EligibilityFactory.new(auction).create

if type == 'single_bid'
Rules::SealedBid.new(auction)
Rules::SealedBid.new(auction, eligibility)
elsif type == 'multi_bid'
Rules::Basic.new(auction)
Rules::Basic.new(auction, eligibility)
end
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/small_business_eligibility.rb
@@ -0,0 +1,6 @@
class SmallBusinessEligibility
def eligible?(user)
InSamEligibility.new.eligible?(user) &&
user.small_business?
end
end
17 changes: 17 additions & 0 deletions app/presenters/auction_presenter.rb
Expand Up @@ -73,6 +73,11 @@ def initialize(auction)
to: :auction_rules
)

delegate(
:small_business?,
to: :start_price_thresholds
)

def bids?
bid_count > 0
end
Expand Down Expand Up @@ -140,6 +145,14 @@ def url
"#{root_url}/auctions/#{id}"
end

def eligibility
if small_business?
'Small-business only'
else
'SAM.gov only'
end
end

private

def auction_rules
Expand Down Expand Up @@ -169,6 +182,10 @@ def auction_status
AuctionStatus.new(model)
end

def start_price_thresholds
@start_price_thresholds ||= StartPriceThresholds.new(start_price)
end

def decorated_bid(bid)
if bid.present?
BidPresenter.new(bid)
Expand Down
8 changes: 8 additions & 0 deletions app/services/start_price_thresholds.rb
@@ -0,0 +1,8 @@
class StartPriceThresholds < Struct.new(:start_price)
MICROPURCHASE = 3500
SAT = 150000

def small_business?
(MICROPURCHASE + 1..SAT).cover?(start_price)
end
end
2 changes: 2 additions & 0 deletions app/view_models/auction_view_model.rb
Expand Up @@ -9,6 +9,7 @@ class AuctionViewModel < Struct.new(:current_user, :auction_record)
:bids?,
:created_at,
:delivery_deadline,
:eligibility,
:end_datetime,
:expiring?,
:formatted_delivery_deadline,
Expand All @@ -28,6 +29,7 @@ class AuctionViewModel < Struct.new(:current_user, :auction_record)
:partial_path,
:read_attribute_for_serialization,
:show_bids?,
:small_business?,
:start_datetime,
:start_price,
:summary,
Expand Down
1 change: 1 addition & 0 deletions app/views/auctions/_list_item.html.erb
Expand Up @@ -8,6 +8,7 @@
<%=h raw auction.html_summary %><a class="issue-list-item-details" href="<%= auction_path(auction) %>">View details <icon class="fa fa-angle-double-right"></icon></a>
</p>
<p><%= auction.formatted_type.capitalize %></p>
<p><%= auction.eligibility %></p>
</div>
</div>
<div class="usa-grid issue-bid-details">
Expand Down
4 changes: 4 additions & 0 deletions app/views/auctions/show.html.erb
Expand Up @@ -23,6 +23,10 @@
<%= @view_model.auction_type.capitalize %> (<%= @view_model.auction_rules_link %>).
</p>
</div>
<div>
<p class="auction-label">Eligible vendors:</p>
<p class="auction-label-info"><%= @view_model.auction.eligibility %></p>
</div>
<div>
<p class="auction-label">Status:</p>
<p class="auction-label-info"><%= @view_model.auction_status_text %></p>
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -72,8 +72,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email"
t.string "github_login"
t.string "credit_card_form_url"
t.string "github_login"
t.integer "sam_status", default: 0, null: false
t.boolean "contracting_officer", default: false, null: false
t.boolean "small_business", default: false, null: false
Expand Down
10 changes: 10 additions & 0 deletions features/auctions.feature
Expand Up @@ -3,6 +3,16 @@ Feature: Basic Auction Views
I want to be able to view auctions on the site
So that I can learn about micropurchase

Scenario: A vendor sees small business only auctions on the auction feed
Given there is an auction with a starting price between the micropurchase threshold and simplified acquisition threshold
When I visit the home page
Then I should see that the auction indicates it is for small business only

Scenario: A vendor sees a non-small business only auctions on the auction feed
Given there is a below the micropurchase threshold auction
When I visit the home page
Then I should not see that the auction indicates it is for small business only

Scenario: Visiting the home page
Given there is an open auction
And there is also an unpublished auction
Expand Down
20 changes: 18 additions & 2 deletions features/bidding.feature
Expand Up @@ -55,7 +55,7 @@ Feature: Bidding

When I submit a bid for $999
Then I should see a confirmation for $999

When I click on the "Confirm" button
Then I should see a current bid amount of $999
And I should see I have the winning bid
Expand All @@ -70,12 +70,28 @@ Feature: Bidding
And I should not see an "Authorize With Github" button
And I should see a message about no bids

Scenario: A vendor sees small business only auctions on the auction view page
Given there is an auction with a starting price between the micropurchase threshold and simplified acquisition threshold
And I am a user with a verified SAM account who is not a small business
And I sign in
When I visit the auction page
Then I should not see the bid button
And I should see a Small-business only status

Scenario: A vendor sees a non small business only auctions on the auction view page
Given there is a below the micropurchase threshold auction
And I am a user with a verified SAM account who is not a small business
And I sign in
When I visit the auction page
Then I should see the bid button
And I should not see a Small-business only status

Scenario: When someone else has outbid me
Given there is an open auction
And I am an authenticated vendor
When I visit the home page
And I click on the "Bid" button

Then I should not see an "Authorize With Github" button
And I should be on the new bid page
And I should see a current bid amount
Expand Down
50 changes: 49 additions & 1 deletion features/step_definitions/auction_steps.rb
Expand Up @@ -19,11 +19,37 @@
FactoryGirl.create(:auction, :closed, :with_bidders, :single_bid)
when 'needs evaluation'
FactoryGirl.create(:auction, :with_bidders, :evaluation_needed)
when 'within simplified acquisition threshold'
FactoryGirl.create(:auction, :between_micropurchase_and_sat_threshold, :available)
when 'below the micropurchase threshold'
FactoryGirl.create(:auction, :below_micropurchase_threshold, :available)
else
fail "Unrecognized auction type: #{label}"
end
end

Given(/^there is an auction with a starting price between the micropurchase threshold and simplified acquisition threshold$/) do
@auction = FactoryGirl.create(:auction, :between_micropurchase_and_sat_threshold, :available)
end

Then(/^I should see that the auction indicates it is for small business only$/) do
auction_div = find('a', text: @auction.title)
.find(:xpath, "..")
.find(:xpath, "..")
.find(:xpath, "..")

expect(auction_div).to have_content('Small-business only')
end

Then(/^I should not see that the auction indicates it is for small business only$/) do
auction_div = find('a', text: @auction.title)
.find(:xpath, "..")
.find(:xpath, "..")
.find(:xpath, "..")

expect(auction_div).to_not have_content('Small-business only')
end

Given(/^there are many different auctions$/) do
FactoryGirl.create(:auction, :closed, title: Faker::Commerce.product_name)
FactoryGirl.create(:auction, :running, title: Faker::Commerce.product_name)
Expand All @@ -35,13 +61,17 @@
end

When(/^I visit the auction page$/) do
visit "/auctions/#{@auction.id}"
visit(auction_path(@auction.id))
end

When(/^I visit the unpublished auction$/) do
visit "/auctions/#{@unpublished_auction.id}"
end

When(/^I visit the auction bids page$/) do
visit(auction_bids_path(@auction.id))
end

Then(/^I should see the winning bid for the auction$/) do
auction = AuctionPresenter.new(@auction)
lowest_bid_amount = ApplicationController.helpers.number_to_currency(
Expand Down Expand Up @@ -171,8 +201,26 @@
expect(page).to have_content("Delivery deadline: #{DcTimePresenter.convert_and_format(@auction.delivery_deadline)}")
end

Then(/^I should see the bid button$/) do
within(:css, 'div.auction-info') do
expect(page).to have_content('BID')
end
end

Then(/^I should not see the bid button$/) do
within(:css, 'div.auction-info') do
expect(page).to_not have_content('BID')
end
end

Then(/^I should see an? (.+) status$/) do |label|
within(:css, 'div.auction-info') do
expect(page).to have_content(label)
end
end

Then(/^I should not see an? (.+) status$/) do |label|
within(:css, 'div.auction-info') do
expect(page).to_not have_content(label)
end
end
4 changes: 0 additions & 4 deletions features/step_definitions/page_steps.rb
Expand Up @@ -42,10 +42,6 @@
visit my_bids_path
end

When(/^I visit the auction bids page$/) do
visit(auction_bids_path(@auction.id))
end

When(/^I visit my profile page$/) do
@user = User.find_by(github_id: @github_id)
visit users_edit_path
Expand Down
12 changes: 12 additions & 0 deletions features/step_definitions/setup_steps.rb
Expand Up @@ -9,6 +9,18 @@
mock_sign_in(@user.github_id, @user.name)
end

Given(/^I am a user with a verified SAM account who is not a small business$/) do
@user = FactoryGirl.create(
:user,
sam_status: :sam_accepted,
github_id: '123451',
duns_number: FakeSamApi::VALID_DUNS,
small_business: false
)
@github_id = @user.github_id
mock_sign_in(@user.github_id, @user.name)
end

Given(/^I am a user without a verified SAM account$/) do
@user = FactoryGirl.create(
:user,
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/auctions.rb
Expand Up @@ -55,6 +55,17 @@
end
end

trait :between_micropurchase_and_sat_threshold do
association :user, factory: :contracting_officer
start_price do
rand(StartPriceThresholds::MICROPURCHASE+1..StartPriceThresholds::SAT)
end
end

trait :below_micropurchase_threshold do
start_price { rand(1..StartPriceThresholds::MICROPURCHASE) }
end

trait :available do
start_datetime { Time.now - 2.days }
end_datetime { Time.now + 2.days }
Expand Down
3 changes: 2 additions & 1 deletion spec/models/rules/basic_spec.rb
Expand Up @@ -3,8 +3,9 @@
describe Rules::Basic do
let(:ar_auction) { create(:auction, :closed, :with_bidders) }
let(:auction) { AuctionPresenter.new(ar_auction) }
let(:eligibility) { InSamEligibility.new }

subject { Rules::Basic.new(auction) }
subject { Rules::Basic.new(auction, eligibility) }

describe 'winning_bid' do
it "should be the auction's lowest_bid" do
Expand Down

0 comments on commit ec4f4bb

Please sign in to comment.