-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #2257 cache store url and enchance by_url scope
- Loading branch information
1 parent
6cca0f4
commit f69b8c3
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
lib/spree_cm_commissioner/test_helper/factories/store_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FactoryBot.define do | ||
factory :cm_store, class: 'Spree::Store' do | ||
sequence(:name) { |n| "Spree Test Store #{n}" } | ||
sequence(:url) { |n| "www.example#{n}.com" } | ||
meta_description { nil } | ||
meta_keywords { nil } | ||
seo_title { nil } | ||
mail_from_address { "[email protected]" } | ||
default_currency { "USD" } | ||
sequence(:code) { |n| "spree_#{n}" } | ||
default { false } | ||
supported_currencies { "USD,EUR,GBP" } | ||
facebook { "spreecommerce" } | ||
twitter { "spreecommerce" } | ||
created_at { Time.now } | ||
updated_at { Time.now } | ||
|
||
trait :default do | ||
default { true } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Spree::Store, type: :model do | ||
describe '.by_url' do | ||
let!(:store1) { create(:cm_store, url: 'api-production.bookme.plus', code: 'store1', default: false) } | ||
let!(:store2) { create(:cm_store, url: 'images.bookme.plus', code: 'store2', default: false) } | ||
let!(:store3) { create(:cm_store, url: 'static.bookme.plus', code: 'store3', default: false) } | ||
let!(:default_store) { create(:cm_store, url: 'www.example.com', code: 'default_store', default: true) } | ||
|
||
before do | ||
Rails.cache.clear | ||
end | ||
|
||
it 'returns the store with an exact match' do | ||
expect(Spree::Store.by_url('api-production.bookme.plus')).to eq(store1) | ||
end | ||
|
||
it 'returns the store with a partial match if no exact match is found' do | ||
expect(Spree::Store.by_url('bookme.plus')).to eq(store1) | ||
end | ||
|
||
it 'returns the default store if no URL is provided' do | ||
expect(Spree::Store.by_url(nil)).to eq(default_store) | ||
end | ||
|
||
it 'caches the result for 1 hour' do | ||
Spree::Store.by_url('api-production.bookme.plus') | ||
expect(Rails.cache.exist?("store_by_url_api-production.bookme.plus")).to be true | ||
end | ||
end | ||
end |