From f0d7c988dc0fd3e0c11fff52545e5d9bfa95bbbf Mon Sep 17 00:00:00 2001 From: pappudas bairagi Date: Fri, 21 Aug 2020 16:36:19 +0530 Subject: [PATCH 01/13] resolve where, who, how checkbox issue --- app/decorators/organization_item_decorator.rb | 52 +++++++++---------- app/decorators/product_decorator.rb | 44 +++++++++++++++- 2 files changed, 69 insertions(+), 27 deletions(-) diff --git a/app/decorators/organization_item_decorator.rb b/app/decorators/organization_item_decorator.rb index 6afb77d0ea..b4b0a9ac51 100644 --- a/app/decorators/organization_item_decorator.rb +++ b/app/decorators/organization_item_decorator.rb @@ -1,18 +1,18 @@ class OrganizationItemDecorator < Draper::Decorator include MapHelper - def has_custom_seller_info? - self[:location_id].present? || self[:who_story].present? || self[:how_story].present? - end - - def location_options_for_select - # NOTE: Location options for new products are loaded on demand - return [] unless organization - - organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| - [location.name, location.id] - end - end + # def has_custom_seller_info? + # self[:location_id].present? || self[:who_story].present? || self[:how_story].present? + # end + + # def location_options_for_select + # # NOTE: Location options for new products are loaded on demand + # return [] unless organization + # + # organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| + # [location.name, location.id] + # end + # end def who_story self[:who_story].presence || (organization ? organization.who_story : nil) @@ -27,20 +27,20 @@ def location @location = (location_id && Location.visible.find_by(id: location_id)) || organization.shipping_location end - def location_map(w=300, h=200) - # if location && location.geocode - # google_static_map([location.geocode], location.geocode, w, h, 11) - # else - # "" - # end - "" - end + # def location_map(w=300, h=200) + # # if location && location.geocode + # # google_static_map([location.geocode], location.geocode, w, h, 11) + # # else + # # "" + # # end + # "" + # end - def location_label - "#{location.city}, #{location.state}" if location - end + # def location_label + # "#{location.city}, #{location.state}" if location + # end - def location_address - "

#{location.address} #{location.city}, #{location.state}

".html_safe if location - end + # def location_address + # "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + # end end diff --git a/app/decorators/product_decorator.rb b/app/decorators/product_decorator.rb index a4f9a7a457..dd4534ab9d 100644 --- a/app/decorators/product_decorator.rb +++ b/app/decorators/product_decorator.rb @@ -1,5 +1,47 @@ -class ProductDecorator < OrganizationItemDecorator +class ProductDecorator < Draper::Decorator delegate_all + def has_custom_seller_info? + self[:location_id].present? || self[:who_story].present? || self[:how_story].present? + end + + def location_options_for_select + # NOTE: Location options for new products are loaded on demand + return [] unless organization + + organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| + [location.name, location.id] + end + end + + def who_story + self[:who_story].presence + end + + def how_story + self[:how_story].presence + end + + def location + return @location if defined?(@location) + @location = (location_id && Location.visible.find_by(id: location_id)) + end + + def location_map(w=300, h=200) + # if location && location.geocode + # google_static_map([location.geocode], location.geocode, w, h, 11) + # else + # "" + # end + "" + end + + def location_label + "#{location.city}, #{location.state}" if location + end + + def location_address + "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + end def cart_item @cart_item ||= begin From 7e24feac508cf6e87e87ad3a0a9c5bb6d20b3494 Mon Sep 17 00:00:00 2001 From: manjula Date: Mon, 7 Sep 2020 18:35:53 +0530 Subject: [PATCH 02/13] Test cases fix --- .../markets/credit_cards/adding_spec.rb | 4 ++-- .../credit_cards/adding_via_stripe_spec.rb | 12 +++++------ spec/features/selling/edit_order_spec.rb | 21 ++++++++++++------- .../add_stripe_credit_card_to_entity_spec.rb | 2 +- spec/lib/packing_labels/order_info_spec.rb | 4 +++- spec/spec_helper.rb | 1 + spec/support/stripe_helpers.rb | 2 +- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/spec/features/markets/credit_cards/adding_spec.rb b/spec/features/markets/credit_cards/adding_spec.rb index 9dee364767..0069b23338 100644 --- a/spec/features/markets/credit_cards/adding_spec.rb +++ b/spec/features/markets/credit_cards/adding_spec.rb @@ -24,7 +24,7 @@ fill_in "Card Number", with: "5105105105105100" fill_in "Security Code", with: "123" select "5", from: "expiration_month" - select "2020", from: "expiration_year" + select "2029", from: "expiration_year" expect(page).not_to have_content("EIN") expect(page).not_to have_content("Full Legal Name") @@ -38,6 +38,6 @@ expect(bank_account.name).to eq("John Doe") expect(bank_account.account_number).to eq("**** **** **** 5100") expect(bank_account.account_type).to eq("Credit Card") - expect(bank_account.expiration).to eq("Expires 05/2020") + expect(bank_account.expiration).to eq("Expires 05/2029") end end diff --git a/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb b/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb index 3b96a35a01..9c04609792 100644 --- a/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb +++ b/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb @@ -20,7 +20,7 @@ fill_in 'Card Number', with: '5105105105105100' fill_in 'Security Code', with: '123' select '5', from: 'expiration_month' - select '2020', from: 'expiration_year' + select '2029', from: 'expiration_year' fill_in 'Notes', with: 'primary' expect(page).not_to have_content('EIN') @@ -35,7 +35,7 @@ expect(bank_account.name).to eq('John Doe') expect(bank_account.account_number).to eq('**** **** **** 5100') expect(bank_account.account_type).to eq('Credit Card') - expect(bank_account.expiration).to eq('Expires 05/2020') + expect(bank_account.expiration).to eq('Expires 05/2029') expect(bank_account.notes).to eq('primary') end @@ -51,7 +51,7 @@ fill_in 'Card Number', with: '5105105105105' fill_in 'Security Code', with: '123' select '5', from: 'expiration_month' - select '2020', from: 'expiration_year' + select '2029', from: 'expiration_year' click_button 'Save' @@ -68,7 +68,7 @@ fill_in 'Card Number', with: '5105105105105100' fill_in 'Security Code', with: '123' select '5', from: 'expiration_month' - select '2020', from: 'expiration_year' + select '2029', from: 'expiration_year' click_button 'Save' expect(page).to have_content('Payment method card info already exists for this organization') @@ -91,7 +91,7 @@ fill_in 'Card Number', with: '5105105105105100' fill_in 'Security Code', with: '123' select '5', from: 'expiration_month' - select '2020', from: 'expiration_year' + select '2029', from: 'expiration_year' fill_in 'Notes', with: 'primary' expect(page).not_to have_content('EIN') @@ -106,7 +106,7 @@ expect(bank_account.name).to eq('John Doe') expect(bank_account.account_number).to eq('**** **** **** 5100') expect(bank_account.account_type).to eq('Credit Card') - expect(bank_account.expiration).to eq('Expires 05/2020') + expect(bank_account.expiration).to eq('Expires 05/2029') expect(bank_account.notes).to eq('primary') end end diff --git a/spec/features/selling/edit_order_spec.rb b/spec/features/selling/edit_order_spec.rb index cc16f0882f..87385b4e16 100644 --- a/spec/features/selling/edit_order_spec.rb +++ b/spec/features/selling/edit_order_spec.rb @@ -333,13 +333,15 @@ def first_order_item click_button "Mark all delivered" page.driver.browser.switch_to.alert.accept - expect(Dom::Order::ItemRow.first.delivery_status).to eql("Delivered") + patiently do + expect(Dom::Order::ItemRow.first.delivery_status).to eql("Delivered") - click_button "Undo mark delivery" - page.driver.browser.switch_to.alert.accept + click_button "Undo mark delivery" + page.driver.browser.switch_to.alert.accept - expect(Dom::Order::ItemRow.first.delivery_status).to eql("Pending") - expect(page).to have_button("Mark all delivered") + expect(Dom::Order::ItemRow.first.delivery_status).to eql("Pending") + expect(page).to have_button("Mark all delivered") + end end end @@ -363,9 +365,12 @@ def first_order_item click_button "Update quantities" item = Dom::Order::ItemRow.first - expect(item.delivery_status).to eql("Canceled") - expect(item.payment_status).to eql("Refunded") - expect(page).to_not have_button("Mark all delivered") + patiently do + expect(item.delivery_status).to eql("Canceled") + expect(item.payment_status).to eql("Refunded") + expect(page).to_not have_button("Mark all delivered") + end + end it "can undo delivery" do diff --git a/spec/interactors/add_stripe_credit_card_to_entity_spec.rb b/spec/interactors/add_stripe_credit_card_to_entity_spec.rb index 59640c80bf..28f4aa7120 100644 --- a/spec/interactors/add_stripe_credit_card_to_entity_spec.rb +++ b/spec/interactors/add_stripe_credit_card_to_entity_spec.rb @@ -19,7 +19,7 @@ "stripe_tok"=>stripe_token.id, "account_type"=>"card", "expiration_month"=>"5", - "expiration_year"=>"2020", + "expiration_year"=>"2040", "notes"=>"primary" ) } diff --git a/spec/lib/packing_labels/order_info_spec.rb b/spec/lib/packing_labels/order_info_spec.rb index db59dcd493..46d74b77bf 100644 --- a/spec/lib/packing_labels/order_info_spec.rb +++ b/spec/lib/packing_labels/order_info_spec.rb @@ -132,6 +132,8 @@ def formatted_delivery_time(t) end describe ".make_order_infos" do + let(:market1) { create(:market) } + let!(:buyer2) { create(:organization, :buyer, name: "Small Timer", markets: [market1]) } let!(:buyer2) { create(:organization, :buyer, name: "Small Timer", markets: [market]) } let!(:product3) { create(:product, :sellable, name: "Flat Chikkens", organization: seller) } let!(:order_items2) do @@ -141,7 +143,7 @@ def formatted_delivery_time(t) end let(:order_number2) { "LO-ADA-0000002" } - let!(:order2) { create(:order, items: order_items2, organization: buyer2, market: market, delivery: delivery, order_number: order_number2, total_cost: order_items2.sum(&:gross_total)) } + let!(:order2) { create(:order, items: order_items2, organization: buyer2, market: market1, delivery: delivery, order_number: order_number2, total_cost: order_items2.sum(&:gross_total)) } let(:orders) { delivery.orders } it "generates a list of order_infos based on a list of Orders" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4076d1c9a9..bdc7553a66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,7 @@ require "rspec/rails" require "email_spec" require "pundit/rspec" +require 'capybara/slow_finder_errors' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are diff --git a/spec/support/stripe_helpers.rb b/spec/support/stripe_helpers.rb index 8886ef0dab..fa0129c090 100644 --- a/spec/support/stripe_helpers.rb +++ b/spec/support/stripe_helpers.rb @@ -160,7 +160,7 @@ def create_stripe_token(opts={}) card_params = { number: "4012888888881881", exp_month: 5, - exp_year: 2020, + exp_year: 2029, cvc: "314" }.merge(opts) From 9c0bc0fc7c81d15a233ae008243e33f8e5d87d2e Mon Sep 17 00:00:00 2001 From: manjula Date: Wed, 9 Sep 2020 01:26:28 -0700 Subject: [PATCH 03/13] cross selling manage products - products by category - checkbox not saving fix --- .../admin/cross_selling_lists_controller.rb | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/cross_selling_lists_controller.rb b/app/controllers/admin/cross_selling_lists_controller.rb index 33732f202d..2e0028eeb9 100644 --- a/app/controllers/admin/cross_selling_lists_controller.rb +++ b/app/controllers/admin/cross_selling_lists_controller.rb @@ -191,17 +191,20 @@ def update_list(cross_selling_list, id_hash = {}, params = {}) def update_parent_list(parent_list, id_hash, params) subscriber_list = get_subscribing_list(parent_list, id_hash) - starting_status = subscriber_list.status + if subscriber_list + starting_status = subscriber_list.status - # This updates the list - subscriber_list.update_attribute(:name, parent_list.name) if subscriber_list.pending? - subscriber_list.manage_status(parent_list.status) - subscriber_list.manage_dates(status) + # This updates the list + subscriber_list.update_attribute(:name, parent_list.name) if subscriber_list.pending? + subscriber_list.manage_status(parent_list.status) + subscriber_list.manage_dates(status) - # This updates the products - subscriber_list.update_attributes(params) + # This updates the products + subscriber_list.update_attributes(params) + + SendCrossSellMessages.perform({:publisher => parent_list.entity, :subscriber_list => subscriber_list, :starting_status => starting_status}) + end - SendCrossSellMessages.perform({:publisher => parent_list.entity, :subscriber_list => subscriber_list, :starting_status => starting_status}) end def update_subscribing_list(subscriber_list) @@ -280,7 +283,10 @@ def get_prods_from_categories(category_ids, scoped_products) # I'm disabling the static processing of top and implementing some 'select all # subcategories' JavaScript instead... top = [] - second = category_ids.to_h.fetch("second", []).map{|c| c.to_i} + if category_ids == [] + category_ids = category_ids.to_h + end + second = category_ids.fetch("second", []).map{|c| c.to_i} scoped_products.each do |p| category_prods.push(p.id.to_s) if (top.include?(p.top_level_category_id) || second.include?(p.second_level_category_id)) From 7ca3bb62580a73b0c1f25ca428a154858af3fa78 Mon Sep 17 00:00:00 2001 From: manjula Date: Wed, 9 Sep 2020 02:01:27 -0700 Subject: [PATCH 04/13] reverting product checkbox fix --- app/decorators/organization_item_decorator.rb | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/app/decorators/organization_item_decorator.rb b/app/decorators/organization_item_decorator.rb index b4b0a9ac51..6afb77d0ea 100644 --- a/app/decorators/organization_item_decorator.rb +++ b/app/decorators/organization_item_decorator.rb @@ -1,18 +1,18 @@ class OrganizationItemDecorator < Draper::Decorator include MapHelper - # def has_custom_seller_info? - # self[:location_id].present? || self[:who_story].present? || self[:how_story].present? - # end - - # def location_options_for_select - # # NOTE: Location options for new products are loaded on demand - # return [] unless organization - # - # organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| - # [location.name, location.id] - # end - # end + def has_custom_seller_info? + self[:location_id].present? || self[:who_story].present? || self[:how_story].present? + end + + def location_options_for_select + # NOTE: Location options for new products are loaded on demand + return [] unless organization + + organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| + [location.name, location.id] + end + end def who_story self[:who_story].presence || (organization ? organization.who_story : nil) @@ -27,20 +27,20 @@ def location @location = (location_id && Location.visible.find_by(id: location_id)) || organization.shipping_location end - # def location_map(w=300, h=200) - # # if location && location.geocode - # # google_static_map([location.geocode], location.geocode, w, h, 11) - # # else - # # "" - # # end - # "" - # end + def location_map(w=300, h=200) + # if location && location.geocode + # google_static_map([location.geocode], location.geocode, w, h, 11) + # else + # "" + # end + "" + end - # def location_label - # "#{location.city}, #{location.state}" if location - # end + def location_label + "#{location.city}, #{location.state}" if location + end - # def location_address - # "

#{location.address} #{location.city}, #{location.state}

".html_safe if location - # end + def location_address + "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + end end From 5e75f9dd89a1694fbc3f04c9d89abe59f0e70aef Mon Sep 17 00:00:00 2001 From: pappudas bairagi Date: Wed, 9 Sep 2020 14:47:09 +0530 Subject: [PATCH 05/13] revert product checkbox fixes --- app/decorators/product_decorator.rb | 46 ++--------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/app/decorators/product_decorator.rb b/app/decorators/product_decorator.rb index dd4534ab9d..839ce33ed4 100644 --- a/app/decorators/product_decorator.rb +++ b/app/decorators/product_decorator.rb @@ -1,47 +1,5 @@ -class ProductDecorator < Draper::Decorator +class ProductDecorator < OrganizationItemDecorator delegate_all - def has_custom_seller_info? - self[:location_id].present? || self[:who_story].present? || self[:how_story].present? - end - - def location_options_for_select - # NOTE: Location options for new products are loaded on demand - return [] unless organization - - organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| - [location.name, location.id] - end - end - - def who_story - self[:who_story].presence - end - - def how_story - self[:how_story].presence - end - - def location - return @location if defined?(@location) - @location = (location_id && Location.visible.find_by(id: location_id)) - end - - def location_map(w=300, h=200) - # if location && location.geocode - # google_static_map([location.geocode], location.geocode, w, h, 11) - # else - # "" - # end - "" - end - - def location_label - "#{location.city}, #{location.state}" if location - end - - def location_address - "

#{location.address} #{location.city}, #{location.state}

".html_safe if location - end def cart_item @cart_item ||= begin @@ -61,4 +19,4 @@ def name_and_unit def updated_at_dte updated_at.strftime("%A %B %e, %Y") end -end +end \ No newline at end of file From b53fcce889e86f5f0b5fac6cd0db3e6ac71aa23a Mon Sep 17 00:00:00 2001 From: manjula Date: Wed, 9 Sep 2020 04:25:08 -0700 Subject: [PATCH 06/13] Fixing organiztion payment method test case --- .../successfully_adding_a_credit_card.yml | 82 +++++++++++++++++-- .../credit_cards/adding_via_stripe_spec.rb | 5 +- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/spec/cassettes/Adding_a_credit_card_to_an_organization/as_an_organization_member/successfully_adding_a_credit_card.yml b/spec/cassettes/Adding_a_credit_card_to_an_organization/as_an_organization_member/successfully_adding_a_credit_card.yml index cf7107c4db..9e2d3327fc 100644 --- a/spec/cassettes/Adding_a_credit_card_to_an_organization/as_an_organization_member/successfully_adding_a_credit_card.yml +++ b/spec/cassettes/Adding_a_credit_card_to_an_organization/as_an_organization_member/successfully_adding_a_credit_card.yml @@ -95,7 +95,7 @@ http_interactions: "url": "/v1/customers/cus_CSqtG384ycXTp6/subscriptions" } } - http_version: + http_version: recorded_at: Sat, 10 Mar 2018 00:04:01 GMT - request: method: get @@ -190,7 +190,7 @@ http_interactions: "url": "/v1/customers/cus_CSqtG384ycXTp6/subscriptions" } } - http_version: + http_version: recorded_at: Sat, 10 Mar 2018 00:04:01 GMT - request: method: post @@ -278,7 +278,7 @@ http_interactions: "name": null, "tokenization_method": null } - http_version: + http_version: recorded_at: Sat, 10 Mar 2018 00:04:02 GMT - request: method: get @@ -399,7 +399,7 @@ http_interactions: "url": "/v1/customers/cus_CSqtG384ycXTp6/subscriptions" } } - http_version: + http_version: recorded_at: Sat, 10 Mar 2018 00:04:02 GMT - request: method: post @@ -522,6 +522,78 @@ http_interactions: "url": "/v1/customers/cus_CSqtG384ycXTp6/subscriptions" } } - http_version: + http_version: recorded_at: Sat, 10 Mar 2018 00:04:02 GMT +- request: + method: get + uri: https://api.stripe.com/v1/customers/cus_CSqtG384ycXTp6 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Stripe/v1 RubyBindings/5.14.0 + Authorization: + - Bearer sk_test_XTLCfIQMwKblsxIF1N4i7y1G + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_7ZoKjLgpoBlvfw","request_duration_ms":2}}' + Stripe-Version: + - '2019-12-03' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"5.14.0","lang":"ruby","lang_version":"2.4.10 p364 (2020-03-31)","platform":"x86_64-darwin19","engine":"ruby","publisher":"stripe","uname":"Darwin + Manju-MacBook-Pro.local 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 + PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64","hostname":"Manju-MacBook-Pro.local"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 404 + message: Not Found + headers: + Server: + - nginx + Date: + - Wed, 09 Sep 2020 10:35:39 GMT + Content-Type: + - application/json + Content-Length: + - '236' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST, HEAD, OPTIONS, DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Request-Id: + - req_8CJHYUtFdWiWMy + Stripe-Version: + - '2019-12-03' + Strict-Transport-Security: + - max-age=31556926; includeSubDomains; preload + body: + encoding: UTF-8 + string: | + { + "error": { + "code": "resource_missing", + "doc_url": "https://stripe.com/docs/error-codes/resource-missing", + "message": "No such customer: 'cus_CSqtG384ycXTp6'", + "param": "id", + "type": "invalid_request_error" + } + } + http_version: + recorded_at: Wed, 09 Sep 2020 10:35:39 GMT recorded_with: VCR 4.0.0 diff --git a/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb b/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb index 9c04609792..5e0e359a53 100644 --- a/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb +++ b/spec/features/organizations/credit_cards/adding_via_stripe_spec.rb @@ -61,11 +61,12 @@ end scenario 'duplicate credit card gives an error' do - create(:bank_account, :credit_card, name: 'John Doe', bank_name: 'MasterCard', account_type: 'card', last_four: '5100', bankable: org) + create(:bank_account, :credit_card, name: 'John Doe', bank_name: 'Visa', account_type: 'card', last_four: '4242', expiration_month: 5, expiration_year: 2029 ,bankable: org) + select 'Credit Card', from: 'provider_account_type' fill_in 'Name', with: 'John Doe' - fill_in 'Card Number', with: '5105105105105100' + fill_in 'Card Number', with: '4242424242424242' fill_in 'Security Code', with: '123' select '5', from: 'expiration_month' select '2029', from: 'expiration_year' From 3ec6b0529edfd5ec6e0e4045b8ffafbca86d03d2 Mon Sep 17 00:00:00 2001 From: pappudas bairagi Date: Thu, 10 Sep 2020 14:29:11 +0530 Subject: [PATCH 07/13] add checkbox issue changes --- app/decorators/organization_item_decorator.rb | 52 +++++++++---------- app/decorators/product_decorator.rb | 46 +++++++++++++++- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/app/decorators/organization_item_decorator.rb b/app/decorators/organization_item_decorator.rb index 6afb77d0ea..b4b0a9ac51 100644 --- a/app/decorators/organization_item_decorator.rb +++ b/app/decorators/organization_item_decorator.rb @@ -1,18 +1,18 @@ class OrganizationItemDecorator < Draper::Decorator include MapHelper - def has_custom_seller_info? - self[:location_id].present? || self[:who_story].present? || self[:how_story].present? - end - - def location_options_for_select - # NOTE: Location options for new products are loaded on demand - return [] unless organization - - organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| - [location.name, location.id] - end - end + # def has_custom_seller_info? + # self[:location_id].present? || self[:who_story].present? || self[:how_story].present? + # end + + # def location_options_for_select + # # NOTE: Location options for new products are loaded on demand + # return [] unless organization + # + # organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| + # [location.name, location.id] + # end + # end def who_story self[:who_story].presence || (organization ? organization.who_story : nil) @@ -27,20 +27,20 @@ def location @location = (location_id && Location.visible.find_by(id: location_id)) || organization.shipping_location end - def location_map(w=300, h=200) - # if location && location.geocode - # google_static_map([location.geocode], location.geocode, w, h, 11) - # else - # "" - # end - "" - end + # def location_map(w=300, h=200) + # # if location && location.geocode + # # google_static_map([location.geocode], location.geocode, w, h, 11) + # # else + # # "" + # # end + # "" + # end - def location_label - "#{location.city}, #{location.state}" if location - end + # def location_label + # "#{location.city}, #{location.state}" if location + # end - def location_address - "

#{location.address} #{location.city}, #{location.state}

".html_safe if location - end + # def location_address + # "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + # end end diff --git a/app/decorators/product_decorator.rb b/app/decorators/product_decorator.rb index 839ce33ed4..dd4534ab9d 100644 --- a/app/decorators/product_decorator.rb +++ b/app/decorators/product_decorator.rb @@ -1,5 +1,47 @@ -class ProductDecorator < OrganizationItemDecorator +class ProductDecorator < Draper::Decorator delegate_all + def has_custom_seller_info? + self[:location_id].present? || self[:who_story].present? || self[:how_story].present? + end + + def location_options_for_select + # NOTE: Location options for new products are loaded on demand + return [] unless organization + + organization.locations.visible.order("locations.default_shipping DESC").alphabetical_by_name.map do |location| + [location.name, location.id] + end + end + + def who_story + self[:who_story].presence + end + + def how_story + self[:how_story].presence + end + + def location + return @location if defined?(@location) + @location = (location_id && Location.visible.find_by(id: location_id)) + end + + def location_map(w=300, h=200) + # if location && location.geocode + # google_static_map([location.geocode], location.geocode, w, h, 11) + # else + # "" + # end + "" + end + + def location_label + "#{location.city}, #{location.state}" if location + end + + def location_address + "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + end def cart_item @cart_item ||= begin @@ -19,4 +61,4 @@ def name_and_unit def updated_at_dte updated_at.strftime("%A %B %e, %Y") end -end \ No newline at end of file +end From 4cbe24fad9b25710d1398a180db9e858fa237f72 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 04:27:09 -0700 Subject: [PATCH 08/13] add product checkbox test case fixes --- spec/features/selling/add_product_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/selling/add_product_spec.rb b/spec/features/selling/add_product_spec.rb index 9ff3719d2a..7e98749ebf 100644 --- a/spec/features/selling/add_product_spec.rb +++ b/spec/features/selling/add_product_spec.rb @@ -162,9 +162,9 @@ def fill_in_required_fields(select=:without_chosen) product = Product.last.decorate - expect(product.who_story).to eql(org.who_story) - expect(product.how_story).to eql(org.how_story) - expect(product.location).to eql(org.locations.default_shipping) + expect(product.who_story).to eql(nil) + expect(product.how_story).to eql(nil) + expect(product.location).to eql(nil) end it "it uses a default address if using who/how" do From df3f0cf6a15906f7ec50bea14cfa0b61cb9c33f6 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 04:49:50 -0700 Subject: [PATCH 09/13] general products decorator --- app/decorators/organization_item_decorator.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/decorators/organization_item_decorator.rb b/app/decorators/organization_item_decorator.rb index b4b0a9ac51..f125c89a3c 100644 --- a/app/decorators/organization_item_decorator.rb +++ b/app/decorators/organization_item_decorator.rb @@ -27,20 +27,20 @@ def location @location = (location_id && Location.visible.find_by(id: location_id)) || organization.shipping_location end - # def location_map(w=300, h=200) - # # if location && location.geocode - # # google_static_map([location.geocode], location.geocode, w, h, 11) - # # else - # # "" - # # end - # "" - # end + def location_map(w=300, h=200) + # if location && location.geocode + # google_static_map([location.geocode], location.geocode, w, h, 11) + # else + # "" + # end + "" + end - # def location_label - # "#{location.city}, #{location.state}" if location - # end + def location_label + "#{location.city}, #{location.state}" if location + end - # def location_address - # "

#{location.address} #{location.city}, #{location.state}

".html_safe if location - # end + def location_address + "

#{location.address} #{location.city}, #{location.state}

".html_safe if location + end end From 03e6b05309c456ca3a78b627385a20afa8ea08f4 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 06:19:16 -0700 Subject: [PATCH 10/13] product decorator fixes --- spec/decorators/product_decorator_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/decorators/product_decorator_spec.rb b/spec/decorators/product_decorator_spec.rb index 2912a8a09e..4041c8abc3 100644 --- a/spec/decorators/product_decorator_spec.rb +++ b/spec/decorators/product_decorator_spec.rb @@ -69,7 +69,7 @@ it "returns the organization's who story when custom who story unavailable" do product = build(:product, :decorated, organization: organization, who_story: nil) - expect(product.who_story).to eq("org-who") + expect(product.who_story).to be_nil end it "returns nil when the product has no organization" do @@ -89,7 +89,7 @@ it "returns the organization's how story when custom how story unavailable" do product = build(:product, :decorated, organization: organization, how_story: nil) - expect(product.how_story).to eq("org-how") + expect(product.how_story).to be_nil end it "returns nil when the product has no organization" do @@ -114,7 +114,7 @@ product = build(:product, :decorated, organization: organization, location: nil) - expect(product.location).to eq(organization_default_location) + expect(product.location).to be_nil end it "returns nil when the product has no organization" do From f1b8513526def2185b674540c9bcd5426b87d0c4 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 06:34:37 -0700 Subject: [PATCH 11/13] Revert "product decorator fixes" This reverts commit 03e6b05309c456ca3a78b627385a20afa8ea08f4. --- spec/decorators/product_decorator_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/decorators/product_decorator_spec.rb b/spec/decorators/product_decorator_spec.rb index 4041c8abc3..2912a8a09e 100644 --- a/spec/decorators/product_decorator_spec.rb +++ b/spec/decorators/product_decorator_spec.rb @@ -69,7 +69,7 @@ it "returns the organization's who story when custom who story unavailable" do product = build(:product, :decorated, organization: organization, who_story: nil) - expect(product.who_story).to be_nil + expect(product.who_story).to eq("org-who") end it "returns nil when the product has no organization" do @@ -89,7 +89,7 @@ it "returns the organization's how story when custom how story unavailable" do product = build(:product, :decorated, organization: organization, how_story: nil) - expect(product.how_story).to be_nil + expect(product.how_story).to eq("org-how") end it "returns nil when the product has no organization" do @@ -114,7 +114,7 @@ product = build(:product, :decorated, organization: organization, location: nil) - expect(product.location).to be_nil + expect(product.location).to eq(organization_default_location) end it "returns nil when the product has no organization" do From 94417946794577acc321bc75e8dfec30cb9d4056 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 06:36:56 -0700 Subject: [PATCH 12/13] remove unwanted test case according product checkbox issue --- spec/decorators/product_decorator_spec.rb | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/decorators/product_decorator_spec.rb b/spec/decorators/product_decorator_spec.rb index 2912a8a09e..d98d6cb036 100644 --- a/spec/decorators/product_decorator_spec.rb +++ b/spec/decorators/product_decorator_spec.rb @@ -66,11 +66,11 @@ expect(product.who_story).to eq("prod-who") end - it "returns the organization's who story when custom who story unavailable" do - product = build(:product, :decorated, organization: organization, who_story: nil) - - expect(product.who_story).to eq("org-who") - end + # it "returns the organization's who story when custom who story unavailable" do + # product = build(:product, :decorated, organization: organization, who_story: nil) + # + # expect(product.who_story).to eq("org-who") + # end it "returns nil when the product has no organization" do product = build(:product, :decorated) @@ -86,11 +86,11 @@ expect(product.how_story).to eq("prod-how") end - it "returns the organization's how story when custom how story unavailable" do - product = build(:product, :decorated, organization: organization, how_story: nil) - - expect(product.how_story).to eq("org-how") - end + # it "returns the organization's how story when custom how story unavailable" do + # product = build(:product, :decorated, organization: organization, how_story: nil) + # + # expect(product.how_story).to eq("org-how") + # end it "returns nil when the product has no organization" do product = build(:product, :decorated) @@ -108,14 +108,14 @@ expect(product.location).to eq(organization_other_location) end - it "returns the organization's default location when custom location unavailable" do - create(:location, organization: organization, deleted_at: 1.minute.ago) - organization_default_location = create(:location, organization: organization) - - product = build(:product, :decorated, organization: organization, location: nil) - - expect(product.location).to eq(organization_default_location) - end + # it "returns the organization's default location when custom location unavailable" do + # create(:location, organization: organization, deleted_at: 1.minute.ago) + # organization_default_location = create(:location, organization: organization) + # + # product = build(:product, :decorated, organization: organization, location: nil) + # + # expect(product.location).to eq(organization_default_location) + # end it "returns nil when the product has no organization" do product = build(:product, :decorated) From ce3141f30e2f3126c656a9a2f26c944c58f62980 Mon Sep 17 00:00:00 2001 From: manjula Date: Thu, 10 Sep 2020 07:11:43 -0700 Subject: [PATCH 13/13] credit spec fixes --- spec/models/credit_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/credit_spec.rb b/spec/models/credit_spec.rb index 612c38dc96..785690ed0c 100644 --- a/spec/models/credit_spec.rb +++ b/spec/models/credit_spec.rb @@ -76,7 +76,7 @@ create(:order_item, order: order, product: random_product) order.reload credit.reload - credit.amount = order.total_cost + credit.amount = order.total_cost + 1 expect(order).to be_valid credit.payer_type = Credit::ORGANIZATION expect(order).to be_valid