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

Commit

Permalink
Merge 00b34c4 into ec2e716
Browse files Browse the repository at this point in the history
  • Loading branch information
saastree committed Aug 26, 2016
2 parents ec2e716 + 00b34c4 commit cb5c387
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -2,6 +2,7 @@
//= require d3.v3.min
//= require utility.js
//= require auctionToggle.js
//= require publishedToggle.js
//= require deliveryDueAt.js
//= require selectize
//= require selectizer
15 changes: 15 additions & 0 deletions app/assets/javascripts/publishedToggle.js
@@ -0,0 +1,15 @@
$(document).ready(function() {
$("#auction_purchase_card").on("change", function(event) {
c2_status = $("#auction_c2_status").val()
published_select_element = $("#auction_published")

published_option = "<option value='published'>published</option>"
unpublished_option = "<option value='unpublished'>unpublished</option>"

if(this.value === "default" && c2_status !== "approved") {
published_select_element.empty().append(unpublished_option)
} else {
published_select_element.empty().append(published_option, unpublished_option)
}
});
});
7 changes: 7 additions & 0 deletions app/models/auction.rb
Expand Up @@ -49,6 +49,13 @@ class Auction < ActiveRecord::Base
format: { with: Regexp.new("#{C2_REGEX}[0-9]") },
allow_blank: true
)
validate :publishing_auction, on: :update, if: :published_changed?

def publishing_auction
if published_was == 'unpublished' && purchase_card == 'default' && c2_status != 'approved'
errors.add(:c2_status, " is not approved.")
end
end

def sorted_skill_names
skills.order(name: :asc).map(&:name)
Expand Down
7 changes: 6 additions & 1 deletion app/view_models/admin/edit_auction_view_model.rb
Expand Up @@ -38,13 +38,18 @@ def published
end

def published_options
if closed? || auction.c2_status == 'approved'
if publishable?
Auction.publisheds.keys.to_a
else
['unpublished']
end
end

def publishable?
closed? || auction.purchase_card == 'other' ||
auction.c2_status == 'approved'
end

def customer_options
([auction.customer] + Customer.sorted).uniq.compact
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/auctions/_form.html.erb
Expand Up @@ -39,6 +39,7 @@
<div class="usa-width-one-half">
<%= f.input :purchase_card, collection: Auction.purchase_cards.keys.to_a %>
</div>
<%= f.hidden_field :c2_status %>
<div class="usa-width-one-half">
<%= f.association :customer, collection: auction.customer_options, label_method: :agency_name %>
</div>
Expand Down
10 changes: 10 additions & 0 deletions spec/models/auction_spec.rb
Expand Up @@ -70,6 +70,16 @@

expect(auction).to be_invalid
end

it 'validates presence of c2_status' do
auction = create(:auction, published: :unpublished,
purchase_card: :default)

auction.published = :published

expect(auction).to be_invalid
expect(auction.errors.messages).to eq(c2_status: [" is not approved."])
end
end
end

Expand Down

0 comments on commit cb5c387

Please sign in to comment.