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

Commit

Permalink
Fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Tapia committed Nov 20, 2018
1 parent 94bc01e commit 118788a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions app/models/spree/tracker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Spree::Tracker < ActiveRecord::Base
belongs_to :store

validates :tracker_type, presence: true

def self.current(store = nil, type = 'analytics')
return if !store
if store.is_a?(Spree::Store)
Expand Down
6 changes: 3 additions & 3 deletions app/views/spree/admin/trackers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<div class='col-3'>
<div data-hook='tracker_type' class='field'>
<%= f.label :tacker_type %>
<%= select_tag :tracker_type, options_for_select(tracker_types, @tracker.tracker_type), include_blank: true, class: 'select2 fullwidth', name: 'tracker[tracker_type]' %>
<%= select_tag :tracker_type, options_for_select(tracker_types, @tracker.tracker_type), include_blank: true, class: 'select2 fullwidth', id: 'tracker_tracker_type', name: 'tracker[tracker_type]' %>
</div>
</div>

<div class='col-3'>
<div class='col-2'>
<div data-hook='active' class='field'>
<%= f.label :active %>
<ul>
Expand All @@ -33,7 +33,7 @@
<div class='col-3'>
<div data-hook='store_select' class='field'>
<%= f.label :store %>
<%= select_tag :store_id, options_from_collection_for_select(Spree::Store.all, :id, :name, @tracker.store_id), include_blank: true, class: 'select2 fullwidth', name: 'tracker[store_id]' %>
<%= select_tag :store_id, options_from_collection_for_select(Spree::Store.all, :id, :name, @tracker.store_id), include_blank: true, class: 'select2 fullwidth', id: 'tracker_store_id', name: 'tracker[store_id]' %>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/spree/admin/trackers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% content_for :page_actions do %>
<% if can?(:create, Spree::Tracker) %>
<li>
<%= button_link_to Spree.t(:new_tracker), new_object_url, id: 'admin_new_tracker_link' %>
<%= link_to Spree.t(:new_tracker), new_object_url, id: 'admin_new_tracker_link', class: 'btn btn-primary' %>
</li>
<% end %>
<% end %>
Expand Down Expand Up @@ -36,9 +36,9 @@
<% @trackers.each do |tracker|%>
<tr id='<%= spree_dom_id tracker %>'' data-hook='admin_trackers_index_rows' class='<%= cycle('odd', 'even')%>'>
<td><%= tracker.analytics_id %></td>
<td><%= tracker.tracker_type.capitalize %></td>
<td><%= tracker.tracker_type.try(:capitalize) %></td>
<td class='align-center'><%= tracker.active ? Spree.t(:say_yes) : Spree.t(:say_no) %></td>
<td><%= tracker.store.name %></td>
<td><%= tracker.store.try(:name) %></td>
<td class="actions">
<% if can?(:update, tracker) %>
<%= link_to_edit tracker, :no_text => true %>
Expand Down
1 change: 1 addition & 0 deletions lib/solidus_trackers/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
factory :tracker, class: Spree::Tracker do
analytics_id 'A100'
active true
tracker_type 'analytics'
end
end
15 changes: 9 additions & 6 deletions spec/features/admin/configuration/analytics_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
it "should have the right tabular values displayed" do
within_row(1) do
expect(column_text(1)).to eq("A100")
expect(column_text(2)).to eq("Yes")
expect(column_text(2)).to eq("Analytics")
expect(column_text(3)).to eq("Yes")
end

within_row(2) do
expect(column_text(1)).to eq("A100")
expect(column_text(2)).to eq("Yes")
expect(column_text(2)).to eq("Analytics")
expect(column_text(3)).to eq("Yes")
end
end
end
Expand All @@ -39,14 +41,15 @@
it "should be able to create a new analytics tracker" do
click_link "admin_new_tracker_link"
fill_in "tracker_analytics_id", with: "A100"
option = first("#tracker_store_id option").text
select option, from: "tracker_store_id"
select all("#tracker_tracker_type option")[1].text, from: "tracker_tracker_type"
select all("#tracker_store_id option")[1].text, from: "tracker_store_id"
click_button "Create"

expect(page).to have_content("successfully created!")
within_row(1) do
expect(column_text(1)).to eq("A100")
expect(column_text(2)).to eq("Yes")
expect(column_text(2)).to eq("Analytics")
expect(column_text(3)).to eq("Yes")
end
end
end
Expand All @@ -56,7 +59,7 @@
create(:tracker, store: store)

visit spree.root_path
expect(page).to have_css('#solidus_trackers', visible: false)
expect(page).to have_css('#solidus_trackers_analytics', visible: false)
end
end
end
12 changes: 6 additions & 6 deletions spec/models/spree/tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

RSpec.describe Spree::Tracker, type: :model do
let(:store) { create(:store) }
let!(:store) { create(:store) }
let!(:tracker) { create(:tracker, store: store) }
let(:other_store) { create(:store, code: 'STORE2', url: 'realfakedoors.com') }
let!(:other_tracker) { create(:tracker, store: other_store) }
Expand All @@ -12,29 +12,29 @@
end

it "returns the first active tracker" do
expect(Spree::Tracker.current(store)).to eq(tracker)
expect(Spree::Tracker.current(store)).to eq([tracker])
end

it "does not return an inactive tracker" do
tracker.update_attribute(:active, false)
expect(Spree::Tracker.current(store)).to be_nil
expect(Spree::Tracker.current(store)).to eq([])
end

it "finds tracker by store" do
expect(Spree::Tracker.current(store)).to eq tracker
expect(Spree::Tracker.current(store)).to eq([tracker])
end

it "finds tracker based on store code" do
aggregate_failures do
expect(ActiveSupport::Deprecation).to receive(:warn)
expect(Spree::Tracker.current('STORE2')).to eq other_tracker
expect(Spree::Tracker.current('STORE2')).to eq([other_tracker])
end
end

it "finds tracker based on store url" do
aggregate_failures do
expect(ActiveSupport::Deprecation).to receive(:warn)
expect(Spree::Tracker.current(store.url)).to eq tracker
expect(Spree::Tracker.current(store.url)).to eq([tracker])
end
end
end
Expand Down

0 comments on commit 118788a

Please sign in to comment.