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

Commit

Permalink
Use current_store instead of Spree::Store.default
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Tapia committed Feb 6, 2019
1 parent a0499e4 commit 3525195
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/spree/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class << self
deprecate current_tracker: :current, deprecator: Spree::Deprecation
end

def self.by_type(store: Spree::Store.default, type: 'google_analytics')
def self.by_type(store = nil, type = 'google_analytics')
return if !store

Spree::Tracker.where(active: true,
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/shared/_google_analytics.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% tracker = Spree::Tracker.by_type(store: Spree::Store.default, type: 'google_analytics') %>
<% tracker = Spree::Tracker.by_type(current_store, 'google_analytics') %>
<% if tracker %>
<script id='solidus_trackers_google_analytics'>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/shared/_google_manager.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% tracker = Spree::Tracker.by_type(store: Spree::Store.default, type: 'google_manager') %>
<% tracker = Spree::Tracker.by_type(current_store, 'google_manager') %>
<% if tracker %>
<script id='solidus_trackers_google_manager'>
Expand Down
11 changes: 4 additions & 7 deletions spec/models/spree/tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,21 @@

describe "by_type" do
it "returns nil if no store passed in argument" do
expect(Spree::Tracker.by_type(store: nil, type: nil)).to eq(nil)
expect(Spree::Tracker.by_type).to eq(nil)
end

it "returns the first active tracker" do
expect(Spree::Tracker.by_type(store: store,
type: tracker.tracker_type)).to eq(tracker)
expect(Spree::Tracker.by_type(store, tracker.tracker_type)).to eq(tracker)
end

it "does not return an inactive tracker" do
tracker.update_attribute(:active, false)
expect(Spree::Tracker.by_type(store: store,
type: tracker.tracker_type)).to eq(nil)
expect(Spree::Tracker.by_type(store, tracker.tracker_type)).to eq(nil)
end

it "finds tracker by store" do
tracker.update_attribute(:tracker_type, 'google_analytics')
expect(Spree::Tracker.by_type(store: store,
type: tracker.tracker_type)).to eq(tracker)
expect(Spree::Tracker.by_type(store, tracker.tracker_type)).to eq(tracker)
end
end
end

0 comments on commit 3525195

Please sign in to comment.