Skip to content

Commit 819c12b

Browse files
committed
PC-27: Render only enabled category and items
1 parent ffbc67d commit 819c12b

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

app/admin/quotes.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
f.input :customer, as: :select, collection: Customer.pluck(:company_name, :id)
3838
f.input :user, as: :select, collection: User.order(:name).pluck(:name, :id)
3939
f.input :categories, as: :check_boxes,
40-
collection: Category.order(:name).pluck(:name, :id),
40+
collection: Category.enabled.order(:name).pluck(:name, :id),
4141
wrapper_html: { class: 'categories-wrapper' }
42-
f.input :item_ids, label: 'Items Without Category', as: :check_boxes, collection: Item.where(category_id: nil).order(:name),
42+
f.input :item_ids, label: 'Items Without Category', as: :check_boxes, collection: Item.enabled.where(category_id: nil).order(:name),
4343
wrapper_html: { class: 'categories-wrapper' }
4444
f.input :total_price, as: :number, input_html: { min: 0, readonly: true }, hint: 'Total price will be calculated automatically based on quote items.'
4545
end

app/models/category.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Category < ApplicationRecord
1919
message: "must contain only ASCII characters" },
2020
if: -> { name.present? }
2121

22+
scope :enabled, -> { where(is_disabled: false) }
23+
2224
def self.ransackable_attributes(_auth_object = nil)
2325
%w[created_at description id id_value is_disabled name updated_at]
2426
end

app/models/item.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Item < ApplicationRecord
1010
validates :calculation_formula, presence: true, if: :requires_calculation_formula?
1111
validates_with ItemFormulaSyntaxValidator
1212

13+
scope :enabled, -> { where(is_disabled: false) }
14+
1315
def self.ransackable_attributes(_auth_object = nil)
1416
%w[category_id created_at id is_disabled name updated_at]
1517
end

spec/requests/admin/quotes_controller_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
it "renders the index page successfully" do
2020
get admin_quotes_path
2121
expect(response).to be_successful
22-
expect(response.body).to include("Quotes")
23-
expect(response.body).to include(customer.company_name)
24-
expect(response.body).to include(user.name)
25-
expect(response.body).to include(quote.total_price.to_s)
22+
unescaped_body = CGI.unescapeHTML(response.body)
23+
expect(unescaped_body).to include("Quotes")
24+
expect(unescaped_body).to include(customer.company_name)
25+
expect(unescaped_body).to include(user.name)
26+
expect(unescaped_body).to include(quote.total_price.to_s)
2627
end
2728
end
2829

0 commit comments

Comments
 (0)