diff --git a/app/models/store_item.rb b/app/models/store_item.rb
index b25dca37..b8a82b7d 100644
--- a/app/models/store_item.rb
+++ b/app/models/store_item.rb
@@ -9,9 +9,9 @@
# **`active`** | `boolean` | `default(TRUE)`
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
+# **`in_stock`** | `boolean` |
# **`name`** | `string(255)` |
# **`price`** | `decimal(8, 2)` |
-# **`quantity`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
@@ -21,9 +21,4 @@ class StoreItem < ActiveRecord::Base
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
- def quantity_available
- unless self.quantity.nil?
- self.quantity - (self.store_purchases.where(charge: nil).pluck(:quantity_purchased).inject{|sum,x| sum + x } || 0 )
- end
- end
end
diff --git a/app/views/store/items/_item.html.erb b/app/views/store/items/_item.html.erb
index cfa8eb83..1513c183 100644
--- a/app/views/store/items/_item.html.erb
+++ b/app/views/store/items/_item.html.erb
@@ -1,7 +1,13 @@
<%= link_to item.name, item, :class => 'btn btn-info btn-xs' %> |
<%= number_to_currency item.price %> |
- <%= item.quantity_available %> |
+
+ <% if item.in_stock? %>
+ Available
+ <% else %>
+ Out of Stock
+ <% end %>
+ |
<% if can?(:create, Charge) %>
<%= link_to t('.add_to_cart', :default => t("helpers.links.add_to_cart")),
diff --git a/app/views/store/items/_items.html.erb b/app/views/store/items/_items.html.erb
index ccff6e7c..fc5a8457 100644
--- a/app/views/store/items/_items.html.erb
+++ b/app/views/store/items/_items.html.erb
@@ -4,7 +4,7 @@
|
Name |
Price |
- Quantity Available |
+ Status |
Actions |
diff --git a/app/views/store/items/show.html.erb b/app/views/store/items/show.html.erb
index 9ea11157..78e95c0c 100644
--- a/app/views/store/items/show.html.erb
+++ b/app/views/store/items/show.html.erb
@@ -3,8 +3,14 @@
<%= @store_item.name %>
<%= model_class.human_attribute_name(:price) %>:
<%= number_to_currency @store_item.price %>
- <%= model_class.human_attribute_name(:quantity) %>:
- <%= @store_item.quantity %>
+ Status:
+
+ <% if @store_item.in_stock? %>
+ Available
+ <% else %>
+ Out of Stock
+ <% end %>
+
diff --git a/db/migrate/20190417031413_change_store_item_quantity_to_in_stock.rb b/db/migrate/20190417031413_change_store_item_quantity_to_in_stock.rb
new file mode 100644
index 00000000..cf7aaf61
--- /dev/null
+++ b/db/migrate/20190417031413_change_store_item_quantity_to_in_stock.rb
@@ -0,0 +1,6 @@
+class ChangeStoreItemQuantityToInStock < ActiveRecord::Migration
+ def change
+ remove_column :store_items, :quantity, :integer
+ add_column :store_items, :in_stock, :boolean
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 21253f33..f5190852 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20190322200326) do
+ActiveRecord::Schema.define(version: 20190417031413) do
create_table "certification_types", force: :cascade do |t|
t.string "name", limit: 255
@@ -261,10 +261,10 @@
create_table "store_items", force: :cascade do |t|
t.string "name", limit: 255
t.decimal "price", precision: 8, scale: 2
- t.integer "quantity", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active", default: true
+ t.boolean "in_stock"
end
create_table "store_purchases", force: :cascade do |t|
diff --git a/db/seeds.rb b/db/seeds.rb
index e5b72a45..843c3daf 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -125,7 +125,7 @@
csv_text = File.read(Rails.root.join('lib', 'seeds', gdrive_doc + 'store.csv'))
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
- StoreItem.create(name: row['name'].strip, price: Integer(row['price'] || "0"), quantity: Integer(row['quantity'] || "0"))
+ StoreItem.create(name: row['name'].strip, price: Integer(row['price'] || "0"), in_stock: row['in_stock'] || true)
end
puts ' Tools'
diff --git a/test/unit/store_item_test.rb b/test/unit/store_item_test.rb
index c4f6d3a0..983e5455 100644
--- a/test/unit/store_item_test.rb
+++ b/test/unit/store_item_test.rb
@@ -9,9 +9,9 @@
# **`active`** | `boolean` | `default(TRUE)`
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
+# **`in_stock`** | `boolean` |
# **`name`** | `string(255)` |
# **`price`** | `decimal(8, 2)` |
-# **`quantity`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
@@ -28,7 +28,7 @@ class StoreItemTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
# Create store
- @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :quantity => 5)
+ @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :in_stock => true)
# Create charge
@charge = FactoryGirl.create(:charge, :is_approved => true)
# Create store_purchase
@@ -38,8 +38,5 @@ class StoreItemTest < ActiveSupport::TestCase
teardown do
end
- should "show that quantity_available method works correctly" do
- assert_equal 4, @store_item.quantity_available
- end
end
end
diff --git a/test/unit/store_purchase_test.rb b/test/unit/store_purchase_test.rb
index 3b31d8bd..9d02dd5f 100644
--- a/test/unit/store_purchase_test.rb
+++ b/test/unit/store_purchase_test.rb
@@ -37,7 +37,7 @@ class StorePurchaseTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
# Create store
- @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :quantity => 3)
+ @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :in_stock => true)
# Create store_purchase
@store_purchase = FactoryGirl.create(:store_purchase, :price_at_purchase => 20, :quantity_purchased => 1, :store_item_id => @store_item.id)
end