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

Commit

Permalink
Merge 4713cb4 into 201309f
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieay committed Jun 13, 2016
2 parents 201309f + 4713cb4 commit 78aa786
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 74 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/auctions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ def index
end

def show
@auction = Admin::AuctionShow.new(Auction.find(params[:id]))
@auction = Admin::AuctionShowViewModel.new(Auction.find(params[:id]))
end

def preview
auction = Auction.find(params[:id])
@auction = AuctionShowViewModel.new(auction: auction, current_user: current_user)
@auction = ::AuctionShowViewModel.new(auction: auction, current_user: current_user)
render 'auctions/show'
end

Expand Down
18 changes: 18 additions & 0 deletions app/models/tock_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class TockProject < ActiveRecord::Base
validates :name, presence: true
validates :tock_id, presence: true

def to_s
"#{name} - #{billable_to_s}"
end

private

def billable_to_s
if billable
"Billable"
else
"Not billable"
end
end
end
26 changes: 26 additions & 0 deletions app/services/tock_importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class TockImporter
TOCK_PROJECTS = "https://tock-app.18f.gov/api/projects.json".freeze

def run
projects.each do |project|
tock_project = TockProject.find_or_initialize_by(tock_id: project["id"])
tock_project.name = project["name"]
tock_project.billable = project["billable"]
tock_project.save!
end
end

private

def projects
@_projects ||= json["results"]
end

def json
JSON.parse(data)
end

def data
Net::HTTP.get(URI(TOCK_PROJECTS))
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::AuctionShow
class Admin::AuctionShowViewModel
attr_reader :auction

def initialize(auction)
Expand All @@ -13,6 +13,10 @@ def title
auction.title
end

def billable_to
auction.billable_to
end

def status_partial
if available?
'admin/auctions/available'
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/auctions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= render partial: 'datetime_fields', locals: { field: 'delivery_due' } %>
<% end %>
<%= f.input :billable_to %>
<%= f.input :billable_to, collection: TockProject.all.map(&:to_s) %>
<%= f.input :start_price %>
<%= f.input :published, collection: Auction.publisheds.keys.to_a %>
<%= f.input :purchase_card, collection: Auction.purchase_cards.keys.to_a %>
Expand Down
41 changes: 20 additions & 21 deletions app/views/admin/auctions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
</h1>

<div class='usa-grid-full'>

<% @auctions.each do |auction| %>
<div class='usa-width-one-whole auction-name'>
<%= link_to admin_auction_path(auction.id), class: 'usa-width-three-fourths' do %>
<h2><%= auction.title %></h2>
<% end %>
<%= link_to 'Edit',
edit_admin_auction_path(auction.id),
class: 'usa-width-one-fourth' %>
</div>

<div class='usa-width-one-whole auction-details'>
<div class='usa-width-one-sixth'>
<%= render partial: auction.availability_partial %>
<% @auctions.each do |auction| %>
<div class='usa-width-one-whole auction-name'>
<%= link_to admin_auction_path(auction.id) do %>
<h2><%= auction.title %></h2>
<% end %>
<%= link_to 'Edit',
edit_admin_auction_path(auction.id),
class: 'usa-width-one-fourth' %>
</div>
<div class='usa-width-one-fourth'>
<b>Starts:</b> <%= auction.formatted_start_time %>
</div>
<div class='usa-width-one-fourth'>
<b>Ends:</b> <%= auction.formatted_end_time %>

<div class='usa-width-one-whole'>
<div>
<%= render partial: auction.availability_partial %>
</div>
<div>
<b>Starts:</b> <%= auction.formatted_start_time %>
</div>
<div>
<b>Ends:</b> <%= auction.formatted_end_time %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
36 changes: 24 additions & 12 deletions app/views/admin/auctions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
<h1><%= @auction.title %></h1>

<div class='usa-width-one-whole'>
<div class='usa-width-one-sixth'>
<%= render partial: @auction.status_partial, locals: { auction: @auction } %>
</div>
<div class='usa-width-one-fourth'>
<b>Starts:</b> <%= @auction.started_at %>
</div>
<div class='usa-width-one-fourth'>
<b>Ends:</b> <%= @auction.ended_at %>
</div>
<div>
<%= render partial: @auction.status_partial, locals: { auction: @auction } %>
</div>

<div>
<b>Starts:</b> <%= @auction.started_at %>
</div>

<div>
<b>Ends:</b> <%= @auction.ended_at %>
</div>

<div>
<b>Billable to:</b> <%= @auction.billable_to %>
</div>

<div>
<h3>Summary:</h3>
<%= @auction.html_summary %>
</div>

<div>
<h3>Description:</h3>
<%= @auction.html_description %>
</div>
<p><%= @auction.html_summary %></p>
<p><%= @auction.html_description %></p>

<div class='usa-grid'>
<%= render partial: @auction.bids_partial, locals: { auction: @auction } %>
Expand Down
5 changes: 5 additions & 0 deletions config/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ module Clockwork
LosingBidderEmailSender.new(auction).delay.perform
end
end

every(1.day, "tock_projects.import", at: "02:00", tz: "UTC") do
puts "Importing Tock projects"
TockImporter.new.delay.run
end
end
1 change: 1 addition & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Rails.application.config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")
Rails.application.config.assets.precompile += %w( jquery.js )
Rails.application.config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
10 changes: 10 additions & 0 deletions db/migrate/20160613181643_create_tock_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateTockProjects < ActiveRecord::Migration
def change
create_table :tock_projects do |t|
t.timestamps null: false
t.string :name, null: false
t.boolean :billable, null: false
t.integer :tock_id, null: false
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160607225657) do
ActiveRecord::Schema.define(version: 20160613181643) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -67,6 +67,14 @@

add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree

create_table "tock_projects", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", null: false
t.boolean "billable", null: false
t.integer "tock_id", null: false
end

create_table "users", force: :cascade do |t|
t.string "github_id"
t.string "duns_number"
Expand Down
29 changes: 29 additions & 0 deletions features/admin_creates_auction.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Feature: Admin creates auctions in the admins panel
As an admin
I should be able to create auctions

Scenario: Adding an auction
Given I am an administrator
And there is a tock project to bill to
When I sign in
And I visit the auctions admin page
And I click on the "Create a new auction" link
And I edit the new auction form
And I click to create an auction
Then I should see the auction's title
And I should see the start time I set for the auction
And I should see the end time I set for the auction

Scenario: Creating an invalid auction
Given I am an administrator
And there is a tock project to bill to
And I sign in
And I visit the auctions admin page
When I click on the "Create a new auction" link
And I edit the new auction form
And I set the auction start price to $24000
And I click to create an auction
Then I should see an alert that
"""
You do not have permission to publish auctions with a start price over $3500
"""
32 changes: 4 additions & 28 deletions features/admin_edits_auction.feature
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
Feature: Admin edits auctions in the admins panel
As an admin of the Micropurchase system
I want to be able to modify existing auctions in an admin
So that I will be able to more efficiently work with the system

Scenario: Adding an auction
Given I am an administrator
When I sign in
And I visit the auctions admin page
And I click on the "Create a new auction" link
And I edit the new auction form
And I click to create an auction
Then I should see the auction's title
And I should see the start time I set for the auction
And I should see the end time I set for the auction

Scenario: Creating an invalid auction
Given I am an administrator
And I sign in
And I visit the auctions admin page
When I click on the "Create a new auction" link
And I edit the new auction form
And I set the auction start price to $24000
And I click to create an auction
Then I should see an alert that
"""
You do not have permission to publish auctions with a start price over $3500
"""
As an admin
I should be able to modify existing auctions

Scenario: Updating an auction
Given I am an administrator
And there is an open auction
When I sign in
And there is a tock project to bill to
And I sign in
And I visit the auctions admin page

When I click to edit the auction
Expand Down
2 changes: 1 addition & 1 deletion features/contracting_officer_creates_auction.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Contracting Officers
As an admin and contracting officer
As an admin and contracting officer
I should be able to create auctions over $3500

Scenario: contracting office creates auction over $3500
Expand Down
11 changes: 4 additions & 7 deletions features/step_definitions/admin_auction_form_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@
@deadline_day = DcTimePresenter.convert(@time_in_days.business_days.from_now)
fill_in("auction_due_in_days", with: @time_in_days)

@billable = "the tock line item for CALC"
fill_in("auction_billable_to", with: @billable)

select(@billable.to_s, from: "auction_billable_to")
select("published", from: "auction_published")
end

Then(/^I should see the current auction attributes in the form$/) do
expect(@auction).to_not be_nil

%w(issue_url description github_repo summary issue_url billable_to).each do |field|
form_field = find_field("auction_#{field}")
expect(form_field.value).to eq(@auction.send(field))
Expand Down Expand Up @@ -129,9 +127,7 @@
@deadline_day = DcTimePresenter.convert(Time.now + 5.days)
fill_in "auction_delivery_due_at", with: @deadline_day.strftime('%Y-%m-%d')

@billable = "the tock line item for CALC"
fill_in("auction_billable_to", with: @billable)

select(@billable.to_s, from: "auction_billable_to")
select("published", from: "auction_published")
end

Expand All @@ -148,6 +144,7 @@
expect(page).to have_text(@title)
expect(page).to have_text(@summary)
expect(page).to have_text(@description)
expect(page).to have_text(@billable.to_s)
end

Then(/^I should see that my auction was created successfully$/) do
Expand Down
3 changes: 3 additions & 0 deletions features/step_definitions/tock_project_create_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Given(/^there is a tock project to bill to$/) do
@billable = FactoryGirl.create(:tock_project)
end
7 changes: 7 additions & 0 deletions spec/factories/tock_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :tock_project do
name 'Tock project'
billable true
tock_id 123
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
config.before do
mock_github
WebMock.stub_request(:any, /api.data.gov/).to_rack(FakeSamApi)
WebMock.stub_request(:any, /tock-app.18f.gov/).to_rack(FakeTockApi)
end
end

Expand Down
13 changes: 13 additions & 0 deletions spec/services/tock_importer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

describe TockImporter do
it 'creates or updates tock projects' do
TockImporter.new.run

expect(TockProject.count).to eq 3

TockImporter.new.run

expect(TockProject.count).to eq 3
end
end
15 changes: 15 additions & 0 deletions spec/support/fake_tock_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'sinatra/base'

class FakeTockApi < Sinatra::Base
get '/api/projects.json' do
json_response 200, 'tock_projects.json'
end

private

def json_response(response_code, file_name)
content_type :json
status response_code
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
end
end
1 change: 1 addition & 0 deletions spec/support/fixtures/tock_projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"count": 3, "next": null, "previous": null, "results": [ { "id": 120, "client":"General Services Administration - 18F (Non-Billable)", "name":"18F Branding", "description":"Working on branding for 18F—internal branding", "billable":false }, { "id":97, "client":"General Services Administration - 18F (Non-Billable)", "name":"18F EDU", "description":"Self-directed training materials and proctored workshops to develop the skill sets of 18F and our partners", "billable":false }, { "id":96, "client":"General Services Administration - 18F (Non-Billable)", "name":"18F Guides", "description":" Aims to disseminate software development and bureaucracy-hacking best practices across 18F and for our partners' digital service teams", "billable":false } ] }

0 comments on commit 78aa786

Please sign in to comment.