Skip to content

Commit

Permalink
Add codespell to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
aglushkov committed Oct 24, 2023
1 parent 0e93b03 commit f5fd9e3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 43 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Install codespell
if: startsWith(matrix.ruby, '3.2') && matrix.activerecord == '7.0'
run: |
python -m pip install --upgrade pip
pip install codespell==2.2.6
- name: Check spelling with codespell
if: startsWith(matrix.ruby, '3.2') && matrix.activerecord == '7.0'
run: codespell --skip="./sig,./doc,./coverage,./vendor" || exit 1

# Check code standards only for latest MRI. It takes a lot of time for jruby or truffleruby
- name: Check Code Standards
if: startsWith(matrix.ruby, '3.2') && matrix.activerecord == '7.0'
Expand Down
6 changes: 4 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
1. Run and fix all warnings
```
bundle update \
pip3 install codespell \
&& bundle update \
&& BUNDLE_GEMFILE=gemfiles/5.2.gemfile bundle update \
&& BUNDLE_GEMFILE=gemfiles/6.1.gemfile bundle update \
&& BUNDLE_GEMFILE=gemfiles/7.0.gemfile bundle update \
&& bundle exec rspec \
&& bundle exec rubocop -A \
&& bundle exec rake examples
&& bundle exec rake examples \
&& codespell --skip="./sig,./doc,./coverage"
```
1. Update version number in VERSION file
Expand Down
6 changes: 3 additions & 3 deletions lib/serega/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def relation?
# Shows specified serializer class
# @return [Serega, nil] Attribute serializer if exists
def serializer
ser = @serializer
return ser if (ser.is_a?(Class) && (ser < Serega)) || !ser
serializer = @serializer
return serializer if (serializer.is_a?(Class) && (serializer < Serega)) || !serializer

@serializer = ser.is_a?(String) ? Object.const_get(ser, false) : ser.call
@serializer = serializer.is_a?(String) ? Object.const_get(serializer, false) : serializer.call
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/serega/utils/to_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call(value)
when NilClass, FalseClass then nil_to_hash(value)
when String then string_to_hash(value)
when Symbol then symbol_to_hash(value)
else raise SeregaError, "Cant convert #{value.class} class object to hash"
else raise SeregaError, "Can't convert #{value.class} class object to hash"
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/serega/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@
end

describe "#serializer" do
let(:ser) { Class.new(Serega) }
let(:proc_ser) { proc { ser } }
let(:serializer) { Class.new(Serega) }
let(:serializer_as_proc) { proc { serializer } }

it "returns provided :serializer option" do
expect(attribute_class.new(name: :name, opts: {serializer: ser}).serializer).to eq ser
expect(attribute_class.new(name: :name, opts: {serializer: serializer}).serializer).to eq serializer
end

it "extracts provided :serializer from Proc" do
expect(attribute_class.new(name: :name, opts: {serializer: proc_ser}).serializer).to eq ser
expect(attribute_class.new(name: :name, opts: {serializer: serializer_as_proc}).serializer).to eq serializer
end

it "extracts provided :serializer from String" do
Object.const_set(:AAA, ser)
expect(attribute_class.new(name: :name, opts: {serializer: "AAA"}).serializer).to eq ser
Object.const_set(:AAA, serializer)
expect(attribute_class.new(name: :name, opts: {serializer: "AAA"}).serializer).to eq serializer
end
end

Expand Down
46 changes: 23 additions & 23 deletions spec/serega/plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
RSpec.describe Serega::SeregaPlan do
let(:base_class) { Class.new(Serega) }
let(:a) do
ser = Class.new(base_class)
serializer = Class.new(base_class)

ser.attribute :a1
ser.attribute :a2
ser.attribute :a3, hide: true
serializer.attribute :a1
serializer.attribute :a2
serializer.attribute :a3, hide: true

ser.attribute :b, serializer: b, hide: true
ser.attribute :c, serializer: c, hide: true
ser.attribute :d, serializer: d
ser
serializer.attribute :b, serializer: b, hide: true
serializer.attribute :c, serializer: c, hide: true
serializer.attribute :d, serializer: d
serializer
end
let(:b) do
ser = Class.new(base_class)
ser.attribute :b1
ser.attribute :b2
ser.attribute :b3, hide: true
ser
serializer = Class.new(base_class)
serializer.attribute :b1
serializer.attribute :b2
serializer.attribute :b3, hide: true
serializer
end
let(:c) do
ser = Class.new(base_class)
ser.attribute :c1
ser.attribute :c2
ser.attribute :c3, hide: true
ser
serializer = Class.new(base_class)
serializer.attribute :c1
serializer.attribute :c2
serializer.attribute :c3, hide: true
serializer
end
let(:d) do
ser = Class.new(base_class)
ser.attribute :d1
ser.attribute :d2
ser.attribute :d3, hide: true
ser
serializer = Class.new(base_class)
serializer.attribute :d1
serializer.attribute :d2
serializer.attribute :d3, hide: true
serializer
end
let(:current_serializer) { a }
let(:described_class) { current_serializer::SeregaPlan }
Expand Down
2 changes: 1 addition & 1 deletion spec/serega/plugins/batch/lib/modules/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
expect(at.batch[:key].call(object)).to eq 1
end

it "returns key without changes proc taht accepts 2 params provided" do
it "returns provided key instance when it accepts 2 params" do
key = proc { |a, b| :id }
at = serializer.attribute :at, batch: {loader: :loader, key: key}
expect(at.batch[:key]).to eq key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
load_plugin_code :batch

RSpec.describe Serega::SeregaPlugins::Batch::CheckOptBatch do
subject(:check) { described_class.call(opts, block, ser) }
subject(:check) { described_class.call(opts, block, serializer) }

let(:ser) { Class.new(Serega) { plugin :batch } }
let(:serializer) { Class.new(Serega) { plugin :batch } }
let(:opts) { {} }
let(:block) { nil }

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

it "allows to skip sub option :key if default key specified" do
ser.config.batch.default_key = :id
serializer.config.batch.default_key = :id
opts[:batch] = {loader: :abc}
expect { check }.not_to raise_error
end
Expand Down Expand Up @@ -77,7 +77,7 @@

it "prohibits to use with block" do
opts[:batch] = {key: :key, loader: :loader}
expect { described_class.call(opts, proc {}, ser) }
expect { described_class.call(opts, proc {}, serializer) }
.to raise_error Serega::SeregaError, "Option :batch can not be used together with block"
end
end
2 changes: 1 addition & 1 deletion spec/serega/utils/to_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
let(:val) { true }

it "returns nested hash with symbol keys with frozen empty hash final value" do
expect { result }.to raise_error Serega::SeregaError, "Cant convert TrueClass class object to hash"
expect { result }.to raise_error Serega::SeregaError, "Can't convert TrueClass class object to hash"
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
require "serega"

def load_plugin_code(*names)
ser = Class.new(Serega)
names.each { |name| ser.plugin(name) }
serializer_class = Class.new(Serega)
names.each { |name| serializer_class.plugin(name) }
end

RSpec.configure do |config|
Expand Down

0 comments on commit f5fd9e3

Please sign in to comment.