diff --git a/app/models/create_cap_proposal.rb b/app/models/create_cap_proposal.rb index a86ca43d..68025680 100644 --- a/app/models/create_cap_proposal.rb +++ b/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'), @@ -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 @@ -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}. diff --git a/app/models/presenter/auction.rb b/app/models/presenter/auction.rb index 265a31ac..59c67a34 100644 --- a/app/models/presenter/auction.rb +++ b/app/models/presenter/auction.rb @@ -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 @@ -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?, @@ -74,6 +76,10 @@ def initialize(auction) to: :auction_rules ) + def url + "/auctions/#{id.to_s}" + end + def bids? bid_count > 0 end diff --git a/spec/models/presenter/auction_spec.rb b/spec/models/presenter/auction_spec.rb index ed36c112..7aef1c62 100644 --- a/spec/models/presenter/auction_spec.rb +++ b/spec/models/presenter/auction_spec.rb @@ -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) } @@ -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 diff --git a/spec/support/url_matcher.rb b/spec/support/url_matcher.rb new file mode 100644 index 00000000..b6848e16 --- /dev/null +++ b/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