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

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge 734ae10 into 7c56873
  • Loading branch information
adelevie committed Sep 22, 2016
2 parents 7c56873 + 734ae10 commit e74816e
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 7 deletions.
11 changes: 11 additions & 0 deletions app/models/client_account_query.rb
@@ -0,0 +1,11 @@
class ClientAccountQuery
attr_reader :relation

def initialize(relation = ClientAccount.all)
@relation = relation
end

def active
relation.where(active: true)
end
end
1 change: 1 addition & 0 deletions app/services/tock_importer.rb
Expand Up @@ -6,6 +6,7 @@ def perform
tock_project = ClientAccount.find_or_initialize_by(tock_id: project["id"])
tock_project.name = project["name"]
tock_project.billable = project["billable"]
tock_project.active = project["active"]
tock_project.save!
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/view_models/admin/edit_auction_view_model.rb
Expand Up @@ -30,7 +30,7 @@ def meridiem_default(field)
end

def billable_to_options
([auction.billable_to] + ClientAccount.all.map(&:to_s)).uniq
([auction.billable_to] + ClientAccountQuery.new.live.map(&:to_s)).uniq
end

def published
Expand Down
2 changes: 1 addition & 1 deletion app/view_models/admin/new_auction_view_model.rb
Expand Up @@ -49,7 +49,7 @@ def meridiem_default(field)
end

def billable_to_options
ClientAccount.all.map(&:to_s)
ClientAccountQuery.new.live.map(&:to_s)
end

def published
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20160920153519_add_active_to_client_account.rb
@@ -0,0 +1,5 @@
class AddActiveToClientAccount < ActiveRecord::Migration
def change
add_column :client_accounts, :active, :boolean
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -73,6 +73,7 @@
t.string "name", null: false
t.boolean "billable", null: false
t.integer "tock_id", null: false
t.boolean "active"
end

add_index "client_accounts", ["tock_id"], name: "index_client_accounts_on_tock_id", unique: true, using: :btree
Expand Down
10 changes: 10 additions & 0 deletions features/admin_creates_auction.feature
Expand Up @@ -42,3 +42,13 @@ Feature: Admin creates auctions in the admins panel
And I click to create an auction
Then I should see that the form preserves the previously entered values
And I should see an alert that the start price is invalid

Scenario: Admin can only assign live Tock projects to new auction
Given I am an administrator
And there is a client account to bill to
And there is a non-live client account
And I sign in
And I visit the auctions admin page
When I click on the add auction link
Then I should not see the non-live client account
And I should see the the live client account
11 changes: 11 additions & 0 deletions features/admin_edits_auction.feature
Expand Up @@ -23,6 +23,17 @@ Feature: Admin edits auctions in the admins panel
And I should see the end time I set for the auction
And I should see new content on the page

Scenario: Only show live client accounts
Given I am an administrator
And I sign in
And there is an open auction
And there is a client account to bill to
And there is a non-live client account
And I visit the auctions admin page
When I click to edit the auction
Then I should not see the non-live client account
And I should see the the live client account

Scenario: Associating an auction with a customer
Given I am an administrator
And I sign in
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/auction_create_steps.rb
Expand Up @@ -234,3 +234,11 @@
:payment_confirmed
)
end

Then(/^I should not see the non\-live client account$/) do
expect(page).not_to have_content(@non_live.name)
end

Then(/^I should see the the live client account$/) do
expect(page).to have_content(@billable.name)
end
6 changes: 5 additions & 1 deletion features/step_definitions/tock_project_create_steps.rb
@@ -1,3 +1,7 @@
Given(/^there is a client account to bill to$/) do
@billable = FactoryGirl.create(:client_account)
@billable = FactoryGirl.create(:client_account, live: true)
end

Given(/^there is a non\-live client account$/) do
@non_live = FactoryGirl.create(:client_account, live: false)
end
3 changes: 2 additions & 1 deletion lib/tasks/dev.rake
Expand Up @@ -15,7 +15,8 @@ namespace :dev do
Skill.find_or_create_by(name: 'a-language-you-never-heard-of')
]

create(:client_account)
create(:client_account, live: true)
create(:client_account, live: false)

FactoryGirl.create(:auction, :reverse, :pending_c2_approval)
FactoryGirl.create(:auction, :reverse, :with_bids)
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/client_accounts.rb
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :client_account do
name 'Client project'
name { "#{Faker::Company.profession.capitalize} Pension Benefit Guaranty Corporation" }
billable true
tock_id 123
sequence(:tock_id) {|n| n}
end
end
16 changes: 16 additions & 0 deletions spec/models/client_account_query_spec.rb
@@ -0,0 +1,16 @@
require 'rails_helper'

describe ClientAccountQuery do
describe '#active' do
it 'only returns active client accounts' do
active = create(:client_account, active: true)
_not_active = create(:client_account, active: false)

client_accounts = ClientAccountQuery.new.active

expect(client_accounts.length).to eq(1)
expect(client_accounts.first.id).to eq(active.id)
expect(client_accounts.first).to be_active
end
end
end
8 changes: 8 additions & 0 deletions spec/services/tock_importer_spec.rb
Expand Up @@ -10,4 +10,12 @@

expect(ClientAccount.count).to eq 3
end

it "saves the 'live' field in ClientAccount" do
TockImporter.new.perform

client_account = ClientAccount.first

expect(client_account).to respond_to(:live)
end
end
38 changes: 37 additions & 1 deletion spec/support/fixtures/tock_projects.json
@@ -1 +1,37 @@
{"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 } ] }
{
"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\u00e2\u20ac\u201dinternal branding",
"billable": false,
"start_date": null,
"end_date": null,
"active": true
},
{
"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,
"start_date": null,
"end_date": null,
"active": true
},
{
"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,
"start_date": null,
"end_date": null,
"active": false
}
]
}

0 comments on commit e74816e

Please sign in to comment.