Skip to content

Commit

Permalink
Improve Rubocop config, fix offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Aug 31, 2024
1 parent ea98c0a commit 0e64ef0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AllCops:
Exclude:
- bin/*
- gemfiles/*
- spec/**/*
- spec/dummy/**/*

Gemspec/RequireMFA:
Enabled: false
Expand Down Expand Up @@ -47,3 +47,10 @@ Layout/EmptyLinesAroundBlockBody:

Layout/EmptyLinesAroundModuleBody:
Enabled: false

#########
# RSPEC #
#########

RSpec/MultipleExpectations:
Max: 3
28 changes: 15 additions & 13 deletions spec/acts_as_xlsx/macros_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Basic tests' do
RSpec.describe ActsAsXlsx::Macros do

describe 'to_xlsx_with_package' do
let(:p) { Post.to_xlsx }

it 'should return xslx data' do
it 'returns xslx data' do
Post.to_xlsx package: p, name: 'another posts'
expect(p.workbook.worksheets.size).to eq 2
end
Expand All @@ -14,61 +16,61 @@
describe 'to_xlsx_with_name' do
let(:p) { Post.to_xlsx name: 'bob' }

it 'should return xslx data' do
it 'returns xslx data' do
expect(p.workbook.worksheets.first.name).to eq 'bob'
end
end

describe 'xlsx_columns' do
it 'should return xslx data' do
it 'returns xslx data' do
expect(Post.xlsx_columns).to eq Post.column_names.map(&:to_sym)
end
end

describe 'to_xslx_vanilla' do
let(:p) { Post.to_xlsx }

it 'should return xslx data' do
it 'returns xslx data' do
expect(p.workbook.worksheets.first.rows.first.cells.first.value).to eq 'Id'
expect(p.workbook.worksheets.first.rows.last.cells.first.value).to eq 2
end
end

describe 'to_xslx_with_provided_data' do
let(:p) { Post.to_xlsx data: Post.where(title: "This is the first post").all }
let(:p) { Post.to_xlsx data: Post.where(title: 'This is the first post').all }

it 'should return xslx data' do
it 'returns xslx data' do
expect(p.workbook.worksheets.first.rows.first.cells.first.value).to eq 'Id'
expect(p.workbook.worksheets.first.rows.last.cells.first.value).to eq 1
end
end

describe 'columns' do
let(:p) { Post.to_xlsx columns: [:name, :title, :content, :votes] }
let(:p) { Post.to_xlsx columns: %i[name title content votes] }
let(:sheet) { p.workbook.worksheets.first }

it 'should return xslx data' do
it 'returns xslx data' do
expect(sheet.rows.first.cells.size).to eq Post.xlsx_columns.size - 3
expect(sheet.rows.first.cells.first.value).to eq 'Name'
expect(sheet.rows.last.cells.last.value).to eq 7
end
end

describe 'method_in_columns' do
let(:p) { Post.to_xlsx columns: [:name, :votes, :content, :ranking] }
let(:p) { Post.to_xlsx columns: %i[name votes content ranking] }
let(:sheet) { p.workbook.worksheets.first }

it 'should return xslx data' do
it 'returns xslx data' do
expect(sheet.rows.first.cells.first.value).to eq 'Name'
expect(sheet.rows.last.cells.last.value).to eq Post.last.ranking
end
end

describe 'chained_method' do
let(:p) { Post.to_xlsx columns: [:name, :votes, :content, :ranking, :'comments.last.content', :'comments.first.author.name'] }
let(:p) { Post.to_xlsx columns: %i[name votes content ranking comments.last.content comments.first.author.name] }
let(:sheet) { p.workbook.worksheets.first }

it 'should return xslx data' do
it 'returns xslx data' do
expect(sheet.rows.first.cells.first.value).to eq 'Name'
expect(sheet.rows.last.cells.last.value).to eq Post.last.comments.last.author.name
end
Expand Down
2 changes: 2 additions & 0 deletions spec/config_rspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Configure RSpec
RSpec.configure do |config|
# Use DB agnostic schema by default
Expand Down

0 comments on commit 0e64ef0

Please sign in to comment.