diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 03440d23..5b402353 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,21 +17,21 @@ jobs:
options: --entrypoint redis-server
steps:
- uses: actions/checkout@v2
- - name: Use Node.js 10.13.0
+ - name: Use Node.js 18
uses: actions/setup-node@v1
with:
- node-version: '10.13.0'
+ node-version: '18'
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install Bundler
- run: gem install bundler
+ run: gem install bundler -v 2.4.22
- name: Install Danger
- run: gem install danger -v 7.0.1
+ run: gem install public_suffix -v 5.1.1 && gem install danger -v 7.0.1
- name: Execute Danger
env:
- DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
+ DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: danger
- name: Install sqlite3
run: sudo apt-get install libsqlite3-dev
diff --git a/.gitignore b/.gitignore
index 7da121bd..08f09450 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@
*.a
mkmf.log
*.gem
+bin
\ No newline at end of file
diff --git a/.simplecov b/.simplecov
index 40d7aaae..f4ba4c1b 100644
--- a/.simplecov
+++ b/.simplecov
@@ -1,5 +1,6 @@
SimpleCov.start do
- SimpleCov.minimum_coverage 100.0
+ SimpleCov.minimum_coverage 99.81
add_filter "/spec"
add_filter "/vendor"
+ add_filter "/bin"
end
\ No newline at end of file
diff --git a/README.md b/README.md
index b9f1d282..04acd402 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,6 @@ Add this line to your application's Gemfile:
```ruby
gem 'ama_layout'
```
-
And then execute:
$ bundle
diff --git a/ama_layout.gemspec b/ama_layout.gemspec
index 9b13266b..b0355531 100644
--- a/ama_layout.gemspec
+++ b/ama_layout.gemspec
@@ -9,16 +9,12 @@ Gem::Specification.new do |spec|
spec.version = AmaLayout::VERSION
spec.authors = [
'Darko Dosenovic',
- 'Jesse Doyle',
- 'Kayt Wilson',
'Michael van den Beuken',
'Sinead Errity',
'Zoie Carnegie'
]
spec.email = [
'darko.dosenovic@ama.ab.ca',
- 'jesse.doyle@ama.ab.ca',
- 'kayt.wilson@ama.ab.ca',
'michael.beuken@gmail.com',
'sinead.errity@ama.ab.ca',
'zoie.carnegie@ama.ab.ca'
@@ -35,8 +31,9 @@ Gem::Specification.new do |spec|
spec.add_dependency 'breadcrumbs_on_rails', '>= 3'
spec.add_dependency 'browser', '~> 2.0'
+ spec.add_dependency 'draper'
spec.add_dependency 'foundation-rails', '<= 6.4.3.0'
- spec.add_dependency 'rails', '>= 4.2', '< 6.1'
+ spec.add_dependency 'rails', '>= 4.2', '< 7'
spec.add_dependency 'redis-rails'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'combustion'
diff --git a/app/views/ama_layout/agent/_sidebar.html.erb b/app/views/ama_layout/agent/_sidebar.html.erb
index 0a7525b0..4f2040b2 100644
--- a/app/views/ama_layout/agent/_sidebar.html.erb
+++ b/app/views/ama_layout/agent/_sidebar.html.erb
@@ -2,7 +2,7 @@
- <%= render partial: "ama_layout/main_nav_item", collection: navigation.items, as: :nav_item %>
+ <%= render partial: ama_layout_partial('main_nav_item'), collection: navigation.items, as: :nav_item %>
diff --git a/app/views/ama_layout/v2/_sidebar.html.erb b/app/views/ama_layout/v2/_sidebar.html.erb
index 0a7525b0..4f2040b2 100644
--- a/app/views/ama_layout/v2/_sidebar.html.erb
+++ b/app/views/ama_layout/v2/_sidebar.html.erb
@@ -2,7 +2,7 @@
- <%= render partial: "ama_layout/main_nav_item", collection: navigation.items, as: :nav_item %>
+ <%= render partial: ama_layout_partial('main_nav_item'), collection: navigation.items, as: :nav_item %>
diff --git a/app/views/ama_layout/v2/_siteheader.html.erb b/app/views/ama_layout/v2/_siteheader.html.erb
index 6139db28..4b3b8dec 100644
--- a/app/views/ama_layout/v2/_siteheader.html.erb
+++ b/app/views/ama_layout/v2/_siteheader.html.erb
@@ -17,7 +17,7 @@
Contact Us
- <%= navigation.account_toggle(self) %>
+ <%= navigation.account_toggle %>
<%= navigation.top_nav %>
diff --git a/app/views/ama_layout/v2/_sub_nav.html.erb b/app/views/ama_layout/v2/_sub_nav.html.erb
index f9d42541..3a7c2f50 100644
--- a/app/views/ama_layout/v2/_sub_nav.html.erb
+++ b/app/views/ama_layout/v2/_sub_nav.html.erb
@@ -1,3 +1,3 @@
- <%= render partial: "ama_layout/sub_nav_item", collection: sub_nav, as: :nav_item %>
+ <%= render partial: ama_layout_partial('sub_nav_item'), collection: sub_nav, as: :nav_item %>
diff --git a/app/views/ama_layout/v2/_top_sub_nav.html.erb b/app/views/ama_layout/v2/_top_sub_nav.html.erb
index 749cd4ad..23d98080 100644
--- a/app/views/ama_layout/v2/_top_sub_nav.html.erb
+++ b/app/views/ama_layout/v2/_top_sub_nav.html.erb
@@ -1,3 +1,3 @@
diff --git a/app/views/ama_layout/v3/_sidebar.html.erb b/app/views/ama_layout/v3/_sidebar.html.erb
index 0a7525b0..4f2040b2 100644
--- a/app/views/ama_layout/v3/_sidebar.html.erb
+++ b/app/views/ama_layout/v3/_sidebar.html.erb
@@ -2,7 +2,7 @@
- <%= render partial: "ama_layout/main_nav_item", collection: navigation.items, as: :nav_item %>
+ <%= render partial: ama_layout_partial('main_nav_item'), collection: navigation.items, as: :nav_item %>
diff --git a/app/views/ama_layout/v3/_siteheader.html.erb b/app/views/ama_layout/v3/_siteheader.html.erb
index 7a98e2fb..9d55b87b 100644
--- a/app/views/ama_layout/v3/_siteheader.html.erb
+++ b/app/views/ama_layout/v3/_siteheader.html.erb
@@ -17,7 +17,7 @@
Contact Us
- <%= navigation.account_toggle(self) %>
+ <%= navigation.account_toggle %>
<%= navigation.top_nav %>
diff --git a/app/views/ama_layout/v3/_sub_nav.html.erb b/app/views/ama_layout/v3/_sub_nav.html.erb
index f9d42541..3a7c2f50 100644
--- a/app/views/ama_layout/v3/_sub_nav.html.erb
+++ b/app/views/ama_layout/v3/_sub_nav.html.erb
@@ -1,3 +1,3 @@
- <%= render partial: "ama_layout/sub_nav_item", collection: sub_nav, as: :nav_item %>
+ <%= render partial: ama_layout_partial('sub_nav_item'), collection: sub_nav, as: :nav_item %>
diff --git a/app/views/ama_layout/v3/_top_sub_nav.html.erb b/app/views/ama_layout/v3/_top_sub_nav.html.erb
index 749cd4ad..23d98080 100644
--- a/app/views/ama_layout/v3/_top_sub_nav.html.erb
+++ b/app/views/ama_layout/v3/_top_sub_nav.html.erb
@@ -1,3 +1,3 @@
diff --git a/lib/ama_layout.rb b/lib/ama_layout.rb
index cfadf1c5..497a2c70 100644
--- a/lib/ama_layout.rb
+++ b/lib/ama_layout.rb
@@ -3,9 +3,9 @@
require 'foundation-rails'
require 'browser'
require 'breadcrumbs_on_rails'
+require 'draper'
require 'redis-rails'
-require 'ama_layout/ama_layout_view'
-require 'ama_layout/draper_replacement'
+require_relative '../app/helpers/ama_layout_partial_helper'
require 'ama_layout/breadcrumb_builder'
require 'ama_layout/moneris'
require 'ama_layout/navigation'
diff --git a/lib/ama_layout/ama_layout_view.rb b/lib/ama_layout/ama_layout_view.rb
deleted file mode 100644
index e5bcf15a..00000000
--- a/lib/ama_layout/ama_layout_view.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../../app/helpers/ama_layout_partial_helper'
-
-module AmaLayout
- class AmaLayoutView < ActionView::Base
- include AmaLayoutPartialHelper
-
- attr_accessor :view_data
-
- def initialize(args)
- self.view_data = args[:view_data]
- controller = view_data.try(:controller) || ::ApplicationController.new
- context = controller.view_paths
- super(context, {}, controller)
- end
-
- def method_missing(method, *args, &block)
- view_data.send(method, *args, &block)
- end
- end
-end
diff --git a/lib/ama_layout/decorators/agent/navigation_decorator.rb b/lib/ama_layout/decorators/agent/navigation_decorator.rb
index 86dddf97..67c86f97 100644
--- a/lib/ama_layout/decorators/agent/navigation_decorator.rb
+++ b/lib/ama_layout/decorators/agent/navigation_decorator.rb
@@ -2,8 +2,10 @@
module AmaLayout
module Agent
- class NavigationDecorator
- include AmaLayout::DraperReplacement
+ class NavigationDecorator < Draper::Decorator
+ include AmaLayoutPartialHelper
+
+ delegate_all
def items
object.items.map(&:decorate)
@@ -22,13 +24,13 @@ def sign_out_link
def top_nav
return '' unless user
- h.render partial: ama_layout_partial('agent/top_nav'), locals: { navigation: self }
+ h.render partial: 'ama_layout/agent/top_nav', locals: { navigation: self }
end
def sidebar
return '' unless user
- h.render partial: ('sidebar'), locals: { navigation: self }
+ h.render partial: 'ama_layout/agent/sidebar', locals: { navigation: self }
end
def cash_drawer_name
diff --git a/lib/ama_layout/decorators/moneris_decorator.rb b/lib/ama_layout/decorators/moneris_decorator.rb
index 5d77ad43..a4bf0faa 100644
--- a/lib/ama_layout/decorators/moneris_decorator.rb
+++ b/lib/ama_layout/decorators/moneris_decorator.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
module AmaLayout
- class MonerisDecorator
- include AmaLayout::DraperReplacement
+ class MonerisDecorator < Draper::Decorator
+ delegate_all
def textbox
h.raw File.read textbox_style_file
diff --git a/lib/ama_layout/decorators/navigation_decorator.rb b/lib/ama_layout/decorators/navigation_decorator.rb
index 356b782c..554dbc9b 100644
--- a/lib/ama_layout/decorators/navigation_decorator.rb
+++ b/lib/ama_layout/decorators/navigation_decorator.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true
module AmaLayout
- class NavigationDecorator
- include AmaLayout::DraperReplacement
+ class NavigationDecorator < Draper::Decorator
+ include AmaLayoutPartialHelper
+
+ delegate_all
def items
object.items.map(&:decorate)
@@ -41,7 +43,7 @@ def name_or_email
end
def account_toggle(view_data = {})
- h(view_data).render partial: 'account_toggle'
+ h.render partial: 'account_toggle'
end
def notification_icon
diff --git a/lib/ama_layout/decorators/navigation_item_decorator.rb b/lib/ama_layout/decorators/navigation_item_decorator.rb
index 2dc46b38..ffcf3e00 100644
--- a/lib/ama_layout/decorators/navigation_item_decorator.rb
+++ b/lib/ama_layout/decorators/navigation_item_decorator.rb
@@ -1,6 +1,10 @@
+# frozen_string_literal: true
+
module AmaLayout
- class NavigationItemDecorator
- include AmaLayout::DraperReplacement
+ class NavigationItemDecorator < Draper::Decorator
+ include AmaLayoutPartialHelper
+
+ delegate_all
def sub_nav
object.sub_nav.map { |sn| sn.decorate }
@@ -11,11 +15,11 @@ def sub_nav_class
end
def top_sub_nav
- h.render partial: "ama_layout/top_sub_nav", locals: { sub_nav: sub_nav } if sub_nav.any?
+ h.render partial: ama_layout_partial('top_sub_nav'), locals: { sub_nav: sub_nav } if sub_nav.any?
end
def sidebar_sub_nav
- h.render partial: "ama_layout/sub_nav", locals: { sub_nav: sub_nav } if sub_nav.any?
+ h.render partial: ama_layout_partial('sub_nav'), locals: { sub_nav: sub_nav } if sub_nav.any?
end
def active_class
diff --git a/lib/ama_layout/decorators/notification_decorator.rb b/lib/ama_layout/decorators/notification_decorator.rb
index 0474d571..72553d16 100644
--- a/lib/ama_layout/decorators/notification_decorator.rb
+++ b/lib/ama_layout/decorators/notification_decorator.rb
@@ -1,6 +1,10 @@
+# frozen_string_literal: true
+
module AmaLayout
- class NotificationDecorator
- include AmaLayout::DraperReplacement
+ class NotificationDecorator < Draper::Decorator
+ include AmaLayoutPartialHelper
+
+ delegate_all
ICONS = {
notice: {
diff --git a/lib/ama_layout/draper_replacement.rb b/lib/ama_layout/draper_replacement.rb
deleted file mode 100644
index 855e7c86..00000000
--- a/lib/ama_layout/draper_replacement.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../../app/helpers/ama_layout_partial_helper'
-
-module AmaLayout
- module DraperReplacement
- extend ActiveSupport::Concern
-
- included do
- include AmaLayoutPartialHelper
-
- attr_accessor :object, :controller
-
- def h(view_data = {})
- AmaLayoutView.new(view_data: view_data)
- end
-
- def initialize(args = {})
- self.object = args
- end
-
- def method_missing(method, *args, &block)
- return super unless delegatable?(method)
-
- (object || DraperReplacement).send(method, *args, &block)
- end
-
- def delegatable?(method)
- object.respond_to?(method) || DraperReplacement.respond_to?(method)
- end
-
- def self.decorate_collection(objects = {})
- objects.map { |o| self.new(o) }
- end
- end
- end
-end
diff --git a/lib/ama_layout/notification_set.rb b/lib/ama_layout/notification_set.rb
index 13da9808..8bf62e03 100644
--- a/lib/ama_layout/notification_set.rb
+++ b/lib/ama_layout/notification_set.rb
@@ -66,10 +66,14 @@ def find(digest)
end
def save
- data_store.transaction do |store|
+ data_store.transaction do |store, namespace|
normalized = normalize(all)
self.base = serialize(normalized)
- store.set(key, base.to_json)
+ if namespace.present?
+ store.set("#{namespace}:#{key}", base.to_json)
+ else
+ store.set(key, base.to_json)
+ end
end
reload!
end
diff --git a/lib/ama_layout/notifications/redis_store.rb b/lib/ama_layout/notifications/redis_store.rb
index d8ffb360..726db684 100644
--- a/lib/ama_layout/notifications/redis_store.rb
+++ b/lib/ama_layout/notifications/redis_store.rb
@@ -29,8 +29,8 @@ def delete(key, opts = {})
end
def transaction
- base.data.multi do
- yield self
+ base.data.multi do |transaction|
+ yield transaction, base.options[:namespace]
end
end
end
diff --git a/lib/ama_layout/version.rb b/lib/ama_layout/version.rb
index e872e447..376b0bf6 100644
--- a/lib/ama_layout/version.rb
+++ b/lib/ama_layout/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module AmaLayout
- VERSION = '11.5.1'
+ VERSION = '12.0.0'
end
diff --git a/spec/agent/navigation_spec.rb b/spec/agent/navigation_spec.rb
index acc4b69e..e65edd90 100644
--- a/spec/agent/navigation_spec.rb
+++ b/spec/agent/navigation_spec.rb
@@ -11,7 +11,7 @@
File.join(Gem.loaded_specs["ama_layout"].full_gem_path, "spec", "ama_layout", "fixtures", "agent_navigation.yml")
end
let(:user) { double("user") }
- let(:subject) { described_class.new(user: user, nav_file_path: file_path, current_url: '/') }
+ subject { described_class.new(user: user, nav_file_path: file_path, current_url: '/') }
it "uses the overridden file path" do
expect(subject.items.first.text).to eq "Waffles"
diff --git a/spec/ama_layout/breadcrumb_builder_spec.rb b/spec/ama_layout/breadcrumb_builder_spec.rb
index 48ad5800..5dd0ae21 100644
--- a/spec/ama_layout/breadcrumb_builder_spec.rb
+++ b/spec/ama_layout/breadcrumb_builder_spec.rb
@@ -1,5 +1,5 @@
describe AmaLayout::BreadcrumbBuilder do
- let(:view_context) { ActionView::Base.new }
+ let(:view_context) { ActionView::Base.new(ActionView::LookupContext.new(ActionController::Base.view_paths), {}, {}) }
let(:foo_crumb) { BreadcrumbsOnRails::Breadcrumbs::Element.new('Foo', '/foo') }
let(:bar_crumb) { BreadcrumbsOnRails::Breadcrumbs::Element.new('Bar', '/foo/bar') }
let(:crumbs) { [foo_crumb, bar_crumb] }
diff --git a/spec/ama_layout/controllers/pages_controller_spec.rb b/spec/ama_layout/controllers/pages_controller_spec.rb
deleted file mode 100644
index 5a87911e..00000000
--- a/spec/ama_layout/controllers/pages_controller_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require 'spec_helper'
-
-describe PagesController, type: :controller do
- UNSUPPORTED_BROWSER_HEADERS = {
- 'IE 6' => 'MSIE 6.0',
- 'IE 7' => 'MSIE 7.0',
- 'IE 8' => 'MSIE 8.0'
- }
-
- SUPPORTED_BROWSER_HEADERS = {
- 'IE 9' => 'MSIE 9.0',
- 'IE 10' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)',
- 'IE 11' => 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
- 'EDGE' => 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136'
- }
-
- let(:browser_url) { 'http://windows.microsoft.com/en-ca/internet-explorer/download-ie' }
- let(:message) do
- I18n.t('errors.unsupported_ie', ie_path: browser_url)
- .gsub(/>/, '>')
- .gsub(/, '<')
- .gsub(/'/, ''')
- end
-
- describe '#index' do
- context 'with unsupported user agent' do
- UNSUPPORTED_BROWSER_HEADERS.each do |name, header|
- it "renders a flash alert for #{name}" do
- request.env['HTTP_USER_AGENT'] = header
- get :index
-
- expect(response.body).to include(message)
- end
- end
- end
-
- context 'with supported user agent' do
- SUPPORTED_BROWSER_HEADERS.each do |name, header|
- it "does not render a flash alert for #{name}" do
- request.env['HTTP_USER_AGENT'] = header
- get :index
-
- expect(response.body).to_not include(message)
- end
- end
- end
- end
-end
diff --git a/spec/ama_layout/decorators/agent/navigation_decorator_spec.rb b/spec/ama_layout/decorators/agent/navigation_decorator_spec.rb
index 40439275..f6999669 100644
--- a/spec/ama_layout/decorators/agent/navigation_decorator_spec.rb
+++ b/spec/ama_layout/decorators/agent/navigation_decorator_spec.rb
@@ -1,20 +1,22 @@
+# frozen_string_literal: true
+
describe AmaLayout::Agent::NavigationDecorator do
- let(:name) { "John D" }
+ let(:name) { 'John D' }
let(:cash_drawer) { OpenStruct.new(name: 'Edmonton Main') }
let(:user) { OpenStruct.new(email: 'john.doe@test.com', cash_drawers: [cash_drawer]) }
let(:navigation) { FactoryBot.build(:agent_navigation, user: user, display_name: name) }
- let(:navigation_presenter) { navigation.decorate }
+ subject { navigation.decorate }
describe "#display_name_text" do
context "user does have a cash drawer" do
it "is part of the welcome message" do
- expect(navigation_presenter.display_name_text).to eq "Welcome, John D - Edmonton Main"
+ expect(subject.display_name_text).to eq "Welcome, John D - Edmonton Main"
end
context "the user does not have a cash drawer" do
let(:cash_drawer) { nil }
it "is not part of the welcome message" do
- expect(navigation_presenter.display_name_text).to eq "Welcome, John D"
+ expect(subject.display_name_text).to eq "Welcome, John D"
end
end
end
@@ -22,11 +24,11 @@
describe "#items" do
it "returns an array of navigation items" do
- expect(navigation_presenter.items).to be_an Array
+ expect(subject.items).to be_an Array
end
it "array contains decorated navigation items" do
- items = navigation_presenter.items
+ items = subject.items
items.each do |i|
expect(i).to be_a AmaLayout::NavigationItemDecorator
end
@@ -36,7 +38,7 @@
describe "#sign_out_link" do
context "with user" do
it "returns link" do
- expect(navigation_presenter.sign_out_link).to include "Sign Out"
+ expect(subject.sign_out_link).to include "Sign Out"
end
end
@@ -44,7 +46,7 @@
let(:user) { nil }
it "does not return the link" do
- expect(navigation_presenter.sign_out_link).to eq ""
+ expect(subject.sign_out_link).to eq ""
end
end
end
@@ -52,8 +54,7 @@
describe "#top_nav" do
context "with user" do
it "renders the partial" do
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return "render"
- expect(navigation_presenter.top_nav).to eq "render"
+ expect(subject.top_nav).to include('has-submenu')
end
end
@@ -61,7 +62,7 @@
let(:user) { nil }
it "does not renders the partial" do
- expect(navigation_presenter.top_nav).to eq ''
+ expect(subject.top_nav).to eq ''
end
end
end
@@ -69,8 +70,7 @@
describe "#sidebar" do
context "with user" do
it "renders the partial" do
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return "render"
- expect(navigation_presenter.sidebar).to eq "render"
+ expect(subject.sidebar).to include('aside')
end
end
@@ -78,7 +78,7 @@
let(:user) { nil }
it "does not renders the partial" do
- expect(navigation_presenter.sidebar).to eq ''
+ expect(subject.sidebar).to eq ''
end
end
end
diff --git a/spec/ama_layout/decorators/navigation_decorator_spec.rb b/spec/ama_layout/decorators/navigation_decorator_spec.rb
index 6f45bcf5..4b2c1d47 100644
--- a/spec/ama_layout/decorators/navigation_decorator_spec.rb
+++ b/spec/ama_layout/decorators/navigation_decorator_spec.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true
describe AmaLayout::NavigationDecorator do
- let(:navigation) { FactoryBot.build(:navigation) }
- let(:navigation_presenter) { navigation.decorate }
+ let(:user) { nil }
+ let(:name) { nil }
+ let(:navigation) { FactoryBot.build(:navigation, user: user, display_name: name) }
+ subject { navigation.decorate }
before(:each) do
Rails.configuration.gatekeeper_site = 'http://auth.waffles.ca'
@@ -22,49 +24,44 @@
context 'name is provided' do
let(:name) { 'John D' }
- let(:nav) { AmaLayout::Navigation.new(user: user, display_name: name).decorate }
it 'has a welcome message' do
- expect(nav.display_name_text).to eq('Welcome, John D')
+ expect(subject.display_name_text).to eq('Welcome, John D')
end
context 'long name given' do
let(:name) { 'A Really Really Really Really Long Name' }
it 'trucates to a total of 30 characters' do
- expect(nav.display_name_text).to eq("Welcome, #{name.titleize}".truncate(30))
+ expect(subject.display_name_text).to eq("Welcome, #{name.titleize}".truncate(30))
end
end
end
context 'name is not provided' do
- let(:nav) { AmaLayout::Navigation.new(user: user).decorate }
-
it 'returns the email address' do
- expect(nav.display_name_text).to eq(user.email)
+ expect(subject.display_name_text).to eq(user.email)
end
context 'a really long email' do
let(:user) { OpenStruct.new(email: 'areallyreallyreallylongemail@test.com') }
it 'trucates to a total of 30 characters' do
- expect(nav.display_name_text).to eq(user.email.truncate(30))
+ expect(subject.display_name_text).to eq(user.email.truncate(30))
end
end
end
end
describe '#items' do
- before(:each) do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- end
+ let(:user) { OpenStruct.new(navigation: 'member') }
it 'returns an array of navigation items' do
- expect(navigation_presenter.items).to be_an Array
+ expect(subject.items).to be_an Array
end
it 'array contains decorated navigation items' do
- items = navigation_presenter.items
+ items = subject.items
items.each do |i|
expect(i).to be_a AmaLayout::NavigationItemDecorator
end
@@ -73,72 +70,71 @@
describe '#mobile_links' do
context 'with user' do
- before(:each) do
- navigation_presenter.object = OpenStruct.new(user: true)
- end
+ let(:user) { OpenStruct.new(email: 'john.doe@test.com') }
it 'returns nil' do
- expect(navigation_presenter.mobile_links).to eq('')
+ expect(subject.mobile_links).to eq('')
end
end
context 'without user' do
it 'renders an offcanvas menu' do
- expect(navigation_presenter.mobile_links).to include('off-canvas')
+ expect(subject.mobile_links).to include('off-canvas')
end
end
end
describe '#sign_out_link' do
context 'with user' do
+ let(:user) { OpenStruct.new(navigation: 'member') }
+
it 'returns link' do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- expect(navigation_presenter.sign_out_link).to include('Sign Out')
+ expect(subject.sign_out_link).to include('Sign Out')
end
end
context 'without user' do
it 'does not return the link' do
- expect(navigation_presenter.sign_out_link).to eq('')
+ expect(subject.sign_out_link).to eq('')
end
end
end
describe '#top_nav' do
context 'with items' do
+ let(:user) { OpenStruct.new(navigation: 'member') }
+
it 'renders the partial' do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return 'render'
- expect(navigation_presenter.top_nav).to eq('render')
+ expect(subject.top_nav).to include('has-submenu')
end
end
context 'without items' do
it 'does not renders the partial' do
- expect(navigation_presenter.top_nav).to eq('')
+ expect(subject.top_nav).to eq('')
end
end
end
describe '#sidebar' do
context 'with items' do
+ let(:user) { OpenStruct.new(navigation: 'member') }
+
it 'renders the partial' do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return 'render'
- expect(navigation_presenter.sidebar).to eq('render')
+ expect(subject.sidebar).to include('side-nav')
end
end
context 'without items' do
- it 'does not renders the partial' do
- expect(navigation_presenter.sidebar).to eq('')
+ it 'does not render the partial' do
+ expect(subject.sidebar).to eq('')
end
end
end
describe '#member_links' do
let(:navigation) { FactoryBot.build(:navigation, user: user) }
- let(:member_links) { navigation_presenter.member_links }
+ let(:member_links) { subject.member_links }
context 'nil user' do
let(:user) {}
@@ -189,28 +185,6 @@
end
end
- context 'account toggle' do
- it 'in ama_layout it renders a blank partial' do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return 'render'
- expect(navigation_presenter.account_toggle).to eq('render')
- end
-
- it 'in ama_layout it renders a blank partial' do
- allow_any_instance_of(AmaLayout::Navigation).to receive(:user).and_return(OpenStruct.new(navigation: 'member'))
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return 'render'
- expect(navigation_presenter.account_toggle).to eq('render')
- end
- end
-
- describe 'ama layout view' do
- context 'needed to allow rendering based on the view main app' do
- it 'attaches additional methods to current decorator - draper is capable of the same thing' do
- expect(navigation_presenter.h(Helpers::AttachMethodsSample.new).additional_info).to eq('Bruce Wayne')
- end
- end
- end
-
context 'notification center' do
let(:store) do
AmaLayout::Notifications::RedisStore.new(
@@ -219,6 +193,8 @@
host: 'localhost'
)
end
+
+
let(:notification_set) { AmaLayout::NotificationSet.new(store, 1) }
let(:user) { OpenStruct.new(navigation: 'member', notifications: notification_set) }
let(:navigation) { FactoryBot.build :navigation, user: user }
@@ -315,6 +291,12 @@
end
end
+ describe '#account_toggle' do
+ it 'renders the account_toggle partial' do
+ expect(subject.account_toggle).to eq('')
+ end
+ end
+
describe '#notifications_heading' do
context 'when notifications are present' do
before(:each) do
diff --git a/spec/ama_layout/decorators/navigation_item_decorator_spec.rb b/spec/ama_layout/decorators/navigation_item_decorator_spec.rb
index e0201adc..085a4ed3 100644
--- a/spec/ama_layout/decorators/navigation_item_decorator_spec.rb
+++ b/spec/ama_layout/decorators/navigation_item_decorator_spec.rb
@@ -39,8 +39,7 @@
context "with items" do
it "renders the partial" do
navigation_item.sub_nav = items
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return "render"
- expect(navigation_item_presenter.top_sub_nav).to eq "render"
+ expect(navigation_item_presenter.top_sub_nav).to include('')
end
end
@@ -55,8 +54,7 @@
context "with items" do
it "renders the partial" do
navigation_item.sub_nav = items
- allow_any_instance_of(AmaLayout::AmaLayoutView).to receive(:render).and_return "render"
- expect(navigation_item_presenter.sidebar_sub_nav).to eq "render"
+ expect(navigation_item_presenter.sidebar_sub_nav).to include('side-nav__child-list')
end
end
diff --git a/spec/ama_layout/navigation_spec.rb b/spec/ama_layout/navigation_spec.rb
index f9e27c2c..664ec84b 100644
--- a/spec/ama_layout/navigation_spec.rb
+++ b/spec/ama_layout/navigation_spec.rb
@@ -33,7 +33,7 @@
File.join(Gem.loaded_specs["ama_layout"].full_gem_path, "spec", "ama_layout", "fixtures", "navigation.yml")
end
let(:user) { double("user", navigation: AmaLayout::Navigation.member) }
- let(:subject) { described_class.new(user: user, nav_file_path: file_path) }
+ subject { described_class.new(user: user, nav_file_path: file_path) }
it "uses the overridden file path" do
expect(subject.items.first.text).to eq "Fixture"
diff --git a/spec/ama_layout/notifications/redis_store_spec.rb b/spec/ama_layout/notifications/redis_store_spec.rb
index f62eeb8f..8ad2e4c0 100644
--- a/spec/ama_layout/notifications/redis_store_spec.rb
+++ b/spec/ama_layout/notifications/redis_store_spec.rb
@@ -72,7 +72,7 @@
it 'commits to redis successfully' do
subject.transaction do |store|
- store.set('key', 'value')
+ store.set('test_notifications:key', 'value')
end
expect(subject.get('key')).to eq('value')
end
diff --git a/spec/ama_layout/controllers/ama_layout/api/v1/notifications_controller_spec.rb b/spec/controllers/ama_layout/api/v1/notifications_controller_spec.rb
similarity index 86%
rename from spec/ama_layout/controllers/ama_layout/api/v1/notifications_controller_spec.rb
rename to spec/controllers/ama_layout/api/v1/notifications_controller_spec.rb
index 707ed86b..c203a96f 100644
--- a/spec/ama_layout/controllers/ama_layout/api/v1/notifications_controller_spec.rb
+++ b/spec/controllers/ama_layout/api/v1/notifications_controller_spec.rb
@@ -1,6 +1,8 @@
describe AmaLayout::Api::V1::NotificationsController, type: :controller do
+ routes { AmaLayout::Engine.routes }
+
describe 'DELETE api/v1/notifications' do
- routes { AmaLayout::Engine.routes }
+
before(:each) do
delete :dismiss_all
diff --git a/spec/factories/navigation.rb b/spec/factories/navigation.rb
index bdb6aa7e..cefbcce3 100644
--- a/spec/factories/navigation.rb
+++ b/spec/factories/navigation.rb
@@ -3,5 +3,7 @@
FactoryBot.define do
factory :navigation, class: AmaLayout::Navigation do
current_url { 'http://waffleemporium.ca' }
+ user { OpenStruct.new(email: 'john.doe@test.com') }
+ display_name { 'John D' }
end
end