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

Commit

Permalink
Admins can now associate auctions with customers
Browse files Browse the repository at this point in the history
Vendors can see who the auction is associated with
  • Loading branch information
Jacob Harris committed Jul 6, 2016
1 parent 71b4c22 commit f10d5c1
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/models/auction.rb
Expand Up @@ -2,6 +2,7 @@ class Auction < ActiveRecord::Base
attr_accessor :due_in_days

belongs_to :user
belongs_to :customer
has_many :bids
has_many :bidders, through: :bids
enum result: { not_applicable: 0, accepted: 1, rejected: 2 }
Expand Down Expand Up @@ -32,6 +33,11 @@ def lowest_bids
bids.select { |b| b.amount == lowest_amount }.sort_by(&:created_at)
end

def customer_name
return nil if customer.nil?
customer.agency_name
end

private

def lowest_amount
Expand Down
3 changes: 2 additions & 1 deletion app/models/auction_parser.rb
Expand Up @@ -31,7 +31,8 @@ def auction_params
:start_price,
:summary,
:title,
:type
:type,
:customer_id
)
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/customer.rb
Expand Up @@ -2,4 +2,8 @@
class Customer < ActiveRecord::Base
validates :agency_name, presence: true, uniqueness: true
validates :email, email: true, presence: false

has_many :auctions

scope :sorted, -> { order('agency_name ASC') }
end
1 change: 1 addition & 0 deletions app/view_models/admin/auction_show_view_model.rb
Expand Up @@ -27,6 +27,7 @@ def admin_data
'GitHub issue URL' => auction.issue_url,
'Accepted at' => formatted_date(auction.accepted_at),
'Delivery URL' => auction.delivery_url,
'Customer' => auction.customer_name,
'Billable to' => auction.billable_to,
'Purchase card' => auction.purchase_card,
'Paid at' => formatted_date(auction.paid_at),
Expand Down
4 changes: 4 additions & 0 deletions app/view_models/admin/edit_auction_view_model.rb
Expand Up @@ -33,6 +33,10 @@ def billable_to_options
([auction.billable_to] + ClientAccount.all.map(&:to_s)).uniq
end

def customer_options
([auction.customer] + Customer.sorted).uniq.compact
end

private

def dc_time(field)
Expand Down
4 changes: 4 additions & 0 deletions app/view_models/admin/new_auction_view_model.rb
Expand Up @@ -31,6 +31,10 @@ def billable_to_options
ClientAccount.all.map(&:to_s)
end

def customer_options
Customer.sorted
end

private

def default_date_time
Expand Down
9 changes: 7 additions & 2 deletions app/view_models/auction_show_view_model.rb
Expand Up @@ -31,8 +31,9 @@ def auction_data
start_label => formatted_date(auction.started_at),
deadline_label => formatted_date(auction.ended_at),
'Delivery deadline' => formatted_date(auction.delivery_due_at),
'Eligible vendors' => eligibility_label
}
'Eligible vendors' => eligibility_label,
'Customer' => customer_label
}.compact
end

def issue_url
Expand Down Expand Up @@ -222,6 +223,10 @@ def eligibility_label
end
end

def customer_label
auction.customer_name
end

def formatted_date(date)
DcTimePresenter.convert_and_format(date)
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/auctions/_form.html.erb
Expand Up @@ -7,6 +7,7 @@
<%= render partial: 'datetime_fields', locals: { field: 'started', auction: auction } %>
<%= render partial: 'datetime_fields', locals: { field: 'ended', auction: auction } %>
<%= render partial: auction.delivery_due_partial, locals: { f: f, auction: auction } %>
<%= f.input :customer_id, collection: auction.customer_options, label_method: :agency_name, value_method: :id %>
<%= f.input :billable_to, collection: auction.billable_to_options %>
<%= f.input :start_price %>
<%= f.input :published, collection: Auction.publisheds.keys.to_a %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20160706014644_add_customer_id_to_auctions.rb
@@ -0,0 +1,6 @@
class AddCustomerIdToAuctions < ActiveRecord::Migration
def change
add_column :auctions, :customer_id, :integer
add_index :auctions, :customer_id
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160705175025) do
ActiveRecord::Schema.define(version: 20160706014644) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -40,8 +40,10 @@
t.datetime "paid_at"
t.datetime "accepted_at"
t.datetime "rejected_at"
t.integer "customer_id"
end

add_index "auctions", ["customer_id"], name: "index_auctions_on_customer_id", using: :btree
add_index "auctions", ["user_id"], name: "index_auctions_on_user_id", using: :btree

create_table "bids", force: :cascade do |t|
Expand Down
45 changes: 45 additions & 0 deletions features/admin_associates_customer_with_auction.feature
@@ -0,0 +1,45 @@
Feature: Admin associates customer with auction
As an administrator
I want to be able to associate auctions with customers
So that users and admins can see who is creating certain projects

Scenario: Associating an auction with a customer
Given I am an administrator
And I sign in
And there is an open auction
And there is a customer
And I visit the auctions admin page

When I click to edit the auction
Then I should see a select box with all the customers in the system

When I select a customer on the form
And I click on the "Update" button
Then I expect the customer to have been saved

When I click to edit the auction
Then I should see the customer selected for the auction

Scenario: Seeing the customer on the auction page
Given I am an administrator
And I sign in
And there is an auction with an associated customer
When I visit the auction page
Then I should see the customer name on the page

When I visit the admin auction page for that auction
Then I should see the customer name on the page

Scenario: Vendor sees the customer
Given I am a user with a verified SAM account
And I sign in
And there is an auction with an associated customer
When I visit the auction page
Then I should see the customer name on the page

Scenario: Do not display the customer label if not set
Given I am a user with a verified SAM account
And I sign in
And there is an open auction
When I visit the auction page
Then I should not see a label for the customer on the page
9 changes: 6 additions & 3 deletions features/admin_edits_auction.feature
Expand Up @@ -2,11 +2,13 @@ Feature: Admin edits auctions in the admins panel
As an admin
I should be able to modify existing auctions

Scenario: Updating an auction
Background:
Given I am an administrator
And there is an open auction
And there is a client account to bill to
And I sign in

Scenario: Updating an auction
Given there is an open auction
And there is a client account to bill to
And I visit the auctions admin page

When I click to edit the auction
Expand All @@ -21,3 +23,4 @@ Feature: Admin edits auctions in the admins panel

When I click on the auction's title
Then I should see new content on the page

21 changes: 21 additions & 0 deletions features/step_definitions/admin_auction_form_steps.rb
Expand Up @@ -159,3 +159,24 @@
expect(DcTimePresenter.convert_and_format(@auction.ended_at)).to eq(DcTimePresenter.convert_and_format(@end_time))
expect(page).to have_text(DcTimePresenter.convert_and_format(@end_time))
end

Then(/^I should see a select box with all the customers in the system$/) do
#customers = Customer.sorted.all
find_field('Customer')
end

When(/^I select a customer on the form$/) do
@customer_select = Customer.first
select(@customer_select.agency_name, :from => 'Customer')
end

Then(/^I expect the customer to have been saved$/) do
@auction.reload
expect(@auction.customer).to_not be_nil
expect(@auction.customer).to eq(@customer_select)
end

Then(/^I should see the customer selected for the auction$/) do
field = find_field('Customer')
expect(field.value.to_i).to eq(@customer.id)
end
5 changes: 5 additions & 0 deletions features/step_definitions/auction_create_steps.rb
Expand Up @@ -107,3 +107,8 @@
Given(/^there is a paid auction$/) do
@auction = FactoryGirl.create(:auction, :closed, :paid)
end

Given(/^there is an auction with an associated customer$/) do
@customer = FactoryGirl.create(:customer)
@auction = FactoryGirl.create(:auction, customer: @customer)
end
11 changes: 11 additions & 0 deletions features/step_definitions/customer_create_steps.rb
@@ -0,0 +1,11 @@
Given(/^there is a customer$/) do
@customer = FactoryGirl.create(:customer)
end

Then(/^I should see the customer name on the page$/) do
page.find('p.auction-label-info', text: @customer.agency_name)
end

Then(/^I should not see a label for the customer on the page$/) do
expect(page.first('h6', text: 'Customer')).to be_nil
end

0 comments on commit f10d5c1

Please sign in to comment.