Skip to content

Commit

Permalink
Fix coding style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Nov 14, 2019
1 parent 72de0a9 commit 99456de
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 31 deletions.
2 changes: 2 additions & 0 deletions Gemfile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'
require 'spree/testing_support/extension_rake'

Expand Down
1 change: 1 addition & 0 deletions app/controllers/spree/admin/reports_controller.rb
Expand Up @@ -67,6 +67,7 @@ def search_params

def adjust_start_date(string_date = nil)
return Time.current.beginning_of_month if string_date.blank?

Time.zone.parse(string_date).beginning_of_day
rescue ArgumentError
Time.current.beginning_of_month
Expand Down
4 changes: 3 additions & 1 deletion app/models/solidus_reports/configuration.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module SolidusReports
class Configuration < Spree::Preferences::Configuration
REPORT_TABS ||= [:reports]
REPORT_TABS ||= [:reports].freeze

new_item = Spree::BackendConfiguration::MenuItem.new(
REPORT_TABS,
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Spree::Core::Engine.routes.draw do
namespace :admin do
resources :reports, only: [:index] do
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/solidus_reports/install/install_generator.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SolidusReports
module Generators
class InstallGenerator < Rails::Generators::Base
Expand All @@ -9,8 +11,8 @@ def add_javascripts
end

def add_stylesheets
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_reports\n", before: /\*\//, verbose: true
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_reports\n", before: /\*\//, verbose: true
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_reports\n", before: %r{\*/}, verbose: true
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_reports\n", before: %r{\*/}, verbose: true
end

def add_migrations
Expand Down
2 changes: 2 additions & 0 deletions lib/solidus_reports.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'solidus_core'
require 'solidus_reports/version'
require 'solidus_reports/engine'
2 changes: 2 additions & 0 deletions lib/solidus_reports/engine.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SolidusReports
class Engine < Rails::Engine
require 'spree/core'
Expand Down
2 changes: 2 additions & 0 deletions lib/solidus_reports/factories.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

FactoryBot.define do
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/solidus_reports/version.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SolidusReports
VERSION = '1.0.0'
end
5 changes: 3 additions & 2 deletions solidus_reports.gemspec
@@ -1,5 +1,6 @@
# encoding: UTF-8
$:.push File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

$:.push File.expand_path('lib', __dir__)
require 'solidus_reports/version'

Gem::Specification.new do |s|
Expand Down
40 changes: 20 additions & 20 deletions spec/controllers/spree/admin/reports_controller_spec.rb
Expand Up @@ -5,18 +5,24 @@
describe Spree::Admin::ReportsController, type: :controller do
stub_authorization!

after do
described_class.available_reports.delete_if do |key, _value|
key != :sales_total
end
end

describe 'ReportsController.available_reports' do
it 'should contain sales_total' do
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:sales_total)).to be true
it 'contains sales_total' do
expect(described_class.available_reports.key?(:sales_total)).to be true
end
end

describe 'ReportsController.add_available_report!' do
context 'when adding the report name' do
it 'should contain the report' do
Spree::Admin::ReportsController.add_available_report!(:some_report)
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:some_report)).to be true
expect(Spree::Admin::ReportsController.available_reports[:some_report]).to eq(
it 'contains the report' do
described_class.add_available_report!(:some_report)
expect(described_class.available_reports.key?(:some_report)).to be true
expect(described_class.available_reports[:some_report]).to eq(
name: :some_report,
description: 'some_report_description'
)
Expand All @@ -25,6 +31,8 @@
end

describe 'GET sales_total' do
subject { get :sales_total, params: params }

let!(:order_complete_start_of_month) { create(:completed_order_with_totals) }
let!(:order_complete_mid_month) { create(:completed_order_with_totals) }
let!(:order_non_complete) { create(:order, completed_at: nil) }
Expand All @@ -38,29 +46,27 @@
order_complete_mid_month.save!
end

subject { get :sales_total, params: params }

shared_examples 'sales total report' do
it 'should respond with success' do
it 'responds with success' do
expect(response).to be_successful
end

it 'should set search to be a ransack search' do
it 'sets search to be a ransack search' do
subject
expect(assigns(:search)).to be_a Ransack::Search
end

it 'should set orders correctly for date parameters' do
it 'sets orders correctly for date parameters' do
subject
expect(assigns(:orders)).to eq expected_returned_orders
end

it 'does not include non-complete orders' do
subject
expect(assigns(:orders)).to_not include(order_non_complete)
expect(assigns(:orders)).not_to include(order_non_complete)
end

it 'should correctly set the totals hash' do
it 'correctlies set the totals hash' do
subject
expect(assigns(:totals)).to eq expected_totals
end
Expand Down Expand Up @@ -119,15 +125,9 @@
end

describe 'GET index' do
it 'should be ok' do
it 'is ok' do
get :index
expect(response).to be_ok
end
end

after(:each) do
Spree::Admin::ReportsController.available_reports.delete_if do |key, _value|
key != :sales_total
end
end
end
6 changes: 3 additions & 3 deletions spec/features/admin/homepage_spec.rb
Expand Up @@ -7,11 +7,11 @@
stub_authorization!

context "visiting the homepage" do
before(:each) do
before do
visit spree.admin_path
end

it "should have a link to reports" do
it "has a link to reports" do
expect(page).to have_link("Reports", href: "/admin/reports")
end
end
Expand All @@ -27,7 +27,7 @@
can [:admin, :edit, :index, :read], Spree::Order
end

it 'should only display tabs fakedispatch has access to' do
it 'onlies display tabs fakedispatch has access to' do
visit spree.admin_path
expect(page).to have_link('Orders')
expect(page).not_to have_link('Reports')
Expand Down
1 change: 1 addition & 0 deletions spec/features/admin/reports_spec.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# # frozen_string_literal: true

# require 'spec_helper'
Expand Down
4 changes: 2 additions & 2 deletions spec/models/spree/permission_sets/report_display_spec.rb
Expand Up @@ -3,10 +3,10 @@
require 'spec_helper'

RSpec.describe Spree::PermissionSets::ReportDisplay do
let(:ability) { DummyAbility.new }

subject { ability }

let(:ability) { DummyAbility.new }

context 'when activated' do
before do
described_class.new(ability).activate!
Expand Down
2 changes: 1 addition & 1 deletion spec/support/ability.rb
Expand Up @@ -10,7 +10,7 @@
class AbilityDecorator
include CanCan::Ability

def initialize(user)
def initialize(_user)
cannot :manage, Spree::Order
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/support/activemodel_mocks.rb
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'rspec-activemodel-mocks'
2 changes: 2 additions & 0 deletions spec/support/factories.rb
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'solidus_reports/factories'

0 comments on commit 99456de

Please sign in to comment.