Skip to content

Commit

Permalink
Fix menu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalcymerys committed Oct 27, 2023
1 parent 9b19da7 commit 0517ec4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions spec/models/spree/admin/main_menu/root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@
module Spree
module Admin
describe MainMenu::Root, type: :model do
let(:root) { described_class.new }
let(:class_under_test) { described_class.new }
let(:items) { [] }

before do
items.each { |i| root.add(i) }
items.each { |i| class_under_test.add(i) }
end

it_behaves_like 'implements item manipulation and query methods'

describe '#key' do
subject { root.key }
subject { class_under_test.key }

it 'returns root' do
expect(subject).to eq('root')
end
end

describe '#label_translation_key' do
subject { root.label_translation_key }
subject { class_under_test.label_translation_key }

it 'returns root' do
expect(subject).to eq('root')
end
end

describe '#icon_key' do
subject { root.icon_key }
subject { class_under_test.icon_key }

it 'returns nil' do
expect(subject).to be_nil
end
end

describe '#available?' do
subject { root.available?(ability, store) }
subject { class_under_test.available?(ability, store) }

let(:ability) { double }
let(:store) { double }
Expand All @@ -48,7 +48,7 @@ module Admin
end

describe '#add_to_section' do
subject { root.add_to_section(section_key, item) }
subject { class_under_test.add_to_section(section_key, item) }

let(:items) { [section] }
let(:section) { double(key: section_key) }
Expand Down
12 changes: 6 additions & 6 deletions spec/models/spree/admin/main_menu/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Spree
module Admin
describe MainMenu::Section, type: :model do
let(:section) { described_class.new(key, label_translation_key, icon_key, availability_check, items) }
let(:class_under_test) { described_class.new(key, label_translation_key, icon_key, availability_check, items) }
let(:key) { 'test-key' }
let(:label_translation_key) { 'test-translation-key' }
let(:icon_key) { 'icon-key' }
Expand All @@ -13,31 +13,31 @@ module Admin
it_behaves_like 'implements item manipulation and query methods'

describe '#key' do
subject { section.key }
subject { class_under_test.key }

it 'returns key' do
expect(subject).to eq(key)
end
end

describe '#label_translation_key' do
subject { section.label_translation_key }
subject { class_under_test.label_translation_key }

it 'returns translation key' do
expect(subject).to eq(label_translation_key)
end
end

describe '#icon_key' do
subject { section.icon_key }
subject { class_under_test.icon_key }

it 'returns icon mey' do
expect(subject).to eq(icon_key)
end
end

describe '#available?' do
subject { section.available?(ability, store) }
subject { class_under_test.available?(ability, store) }

let(:ability) { double}
let(:store) { double }
Expand Down Expand Up @@ -66,7 +66,7 @@ module Admin
end

describe '#children?' do
subject { section.children? }
subject { class_under_test.children? }

context 'when there are child items' do
let(:items) { [double] }
Expand Down
4 changes: 2 additions & 2 deletions spec/models/spree/admin/tabs/root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module Spree
module Admin
describe Tabs::Root, type: :model do
let(:root) { described_class.new }
let(:class_under_test) { described_class.new }
let(:items) { [] }

before do
items.each { |i| root.add(i) }
items.each { |i| class_under_test.add(i) }
end

it_behaves_like 'implements item manipulation and query methods'
Expand Down
28 changes: 14 additions & 14 deletions spec/support/admin/manipulation_and_query_methods.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.shared_examples "implements item manipulation and query methods" do
describe '#add' do
subject { root.add(item) }
subject { class_under_test.add(item) }
let(:item) { double(key: 'test') }

context "when there's no item with a particular key" do

it 'appends an item' do
subject
expect(root.items).to include(item)
expect(class_under_test.items).to include(item)
end
end

Expand All @@ -21,7 +21,7 @@
end

describe '#child_with_key?' do
subject { root.child_with_key?(key) }
subject { class_under_test.child_with_key?(key) }
let(:key) { 'key' }

context 'when an item with given key exists' do
Expand All @@ -42,7 +42,7 @@
end

describe '#remove' do
subject { root.remove(key) }
subject { class_under_test.remove(key) }
let(:key) { 'key' }
let(:other_key) { 'other-key' }

Expand All @@ -51,8 +51,8 @@

it 'removes the item' do
subject
expect(root.items.count).to eq(1)
expect(root.items.first.key).to eq(other_key)
expect(class_under_test.items.count).to eq(1)
expect(class_under_test.items.first.key).to eq(other_key)
end
end

Expand All @@ -66,7 +66,7 @@
end

describe '#item_for_key' do
subject { root.item_for_key(key) }
subject { class_under_test.item_for_key(key) }
let(:key) { 'key' }

context 'when an item with given key exists' do
Expand All @@ -88,7 +88,7 @@
end

describe '#insert_before' do
subject { root.insert_before(existing_key, item) }
subject { class_under_test.insert_before(existing_key, item) }

let(:item) { double(key: inserted_key) }
let(:inserted_key) { 'test-item' }
Expand All @@ -113,14 +113,14 @@

it 'inserts the item before the other item' do
subject
expect(root.items.count).to eq(3)
expect(root.items[1].key).to eq(inserted_key)
expect(class_under_test.items.count).to eq(3)
expect(class_under_test.items[1].key).to eq(inserted_key)
end
end
end

describe '#insert_after' do
subject { root.insert_after(existing_key, item) }
subject { class_under_test.insert_after(existing_key, item) }

let(:item) { double(key: inserted_key) }
let(:inserted_key) { 'test-item' }
Expand All @@ -145,9 +145,9 @@

it 'inserts the item after the other item' do
subject
expect(root.items.count).to eq(3)
expect(root.items[1].key).to eq(inserted_key)
expect(class_under_test.items.count).to eq(3)
expect(class_under_test.items[1].key).to eq(inserted_key)
end
end
end
end
end

0 comments on commit 0517ec4

Please sign in to comment.