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

Commit

Permalink
Implementing Jessie's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
adelevie committed Apr 29, 2016
1 parent 5e49623 commit a7da9ec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
26 changes: 14 additions & 12 deletions app/models/create_cap_proposal.rb
@@ -1,13 +1,15 @@
class CreateCapProposal
def initialize(auction)
if !auction.is_a?(Presenter::Auction)
fail "an instance of Auction::Presenter must be passed to CreateCapProposal::initialize"
end
OFFICE = 'DC'
PURCHASE_TYPE = 'Software'
QUANTITY = 1
RECURRING = false
URGENCY = 20

def initialize(auction)
@auction = auction
end

def configure_c2_client!
def configure_c2_client
@host = ENV.fetch('C2_HOST', 'https://cap.18f.gov')
@c2_client = C2::Client.new(
oauth_key: ENV.fetch('C2_OAUTH_KEY'),
Expand All @@ -20,7 +22,7 @@ def configure_c2_client!
end

def c2_client
@c2_client ||= configure_c2_client!
@c2_client ||= configure_c2_client
end

def perform
Expand All @@ -32,23 +34,23 @@ def perform

def c2_proposal_hash
{
office: 'DC',
purchase_type: 'Software',
office: CreateCapProposal::OFFICE,
purchase_type: CreateCapProposal::PURCHASE_TYPE,
product_name_and_description: product_name_and_description,
justification: justification,
link_to_product: link_to_product,
cost_per_unit: cost_per_unit,
quantity: 1,
recurring: false,
quantity: CreateCapProposal::QUANTITY,
recurring: CreateCapProposal::RECURRING,
date_requested: date_requested,
urgency: 20,
urgency: CreateCapProposal::URGENCY,
additional_info: additional_info
}
end

def product_name_and_description
%{
Micropurchase for '#{@auction.title}.
Micropurchase for '#{@auction.title}'.
Link: https://micropurchase.18f.gov/auctions/#{@auction.id}.
Expand Down
12 changes: 9 additions & 3 deletions app/models/presenter/auction.rb
Expand Up @@ -7,6 +7,8 @@ class Auction
include ActiveModel::SerializerSupport
include ActionView::Helpers::DateHelper
include ActionView::Helpers::NumberHelper
include Rails.application.routes.url_helpers
default_url_options[:host] = ::Rails.application.routes.default_url_options[:host]

def initialize(auction)
@auction = auction
Expand Down Expand Up @@ -44,14 +46,14 @@ def initialize(auction)
to: :lowest_bid,
prefix: :lowest_bid
)

delegate(
:bidder_duns_number,
:bidder_name,
:bidder_name,
to: :lowest_bid,
prefix: :lowest
)

delegate(
:future?,
:expiring?,
Expand All @@ -74,6 +76,10 @@ def initialize(auction)
to: :auction_rules
)

def url
"/auctions/#{id.to_s}"
end

def bids?
bid_count > 0
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/presenter/auction_spec.rb
Expand Up @@ -6,6 +6,13 @@
let(:auction) { Presenter::Auction.new(ar_auction) }
let(:user) { FactoryGirl.create(:user) }

describe '#url' do
it 'returns a valid url that includes the id of the auction' do
expect(auction.url).to be_url
expect(auction.url).to include(auction.id)
end
end

describe 'internal bid methods' do
context 'when there are no bids' do
let(:ar_auction) { FactoryGirl.create(:auction) }
Expand Down Expand Up @@ -103,6 +110,7 @@
expect(lowest_bids.map(&:id)).to eq(ar_lowest_bids.map(&:id))
expect(lowest_bids.map(&:bidder_id)).to eq(ar_lowest_bids.map(&:bidder_id))
end

end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/support/url_matcher.rb
@@ -0,0 +1,7 @@
RSpec::Matchers.define :be_url do |expected|
# The match method, returns true if valie, false if not.
match do |actual|
# Use the URI library to parse the string, returning false if this fails.
URI.parse(actual) rescue false
end
end

0 comments on commit a7da9ec

Please sign in to comment.