Skip to content

Commit

Permalink
Add Github Actions and update Rubocop (#128)
Browse files Browse the repository at this point in the history
* Add Github Actions and update Rubocop

* Fix

* Remove support for ruby 2.3 and 2.4

* Fix
  • Loading branch information
Jesterovskiy authored Jan 29, 2022
1 parent 8648650 commit 5bf8a51
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 46 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.5, 2.6, 2.7, head, jruby-9.2.20.1, jruby-head]

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
continue-on-error: true
- name: Run tests
run: bundle exec rake
continue-on-error: true
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rake
- rubocop-rspec

AllCops:
DisplayCopNames: true
Exclude:
Expand Down
67 changes: 67 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-01-29 11:55:33 UTC using RuboCop version 1.25.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'redis-session-store.gemspec'

# Offense count: 6
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/redis_session_store_spec.rb'

# Offense count: 2
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 9

# Offense count: 5
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/redis_session_store_spec.rb'

# Offense count: 8
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 5
RSpec/MultipleExpectations:
Max: 2

# Offense count: 17
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 10

# Offense count: 13
RSpec/NestedGroups:
Max: 5

# Offense count: 2
RSpec/StubbedMock:
Exclude:
- 'spec/redis_session_store_spec.rb'

# Offense count: 20
RSpec/SubjectStub:
Exclude:
- 'spec/redis_session_store_spec.rb'

# Offense count: 16
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/redis_session_store_spec.rb'
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Redis Session Store

[![Build Status](https://travis-ci.org/roidrage/redis-session-store.svg?branch=master)](https://travis-ci.org/roidrage/redis-session-store)
[![Code Climate](https://codeclimate.com/github/roidrage/redis-session-store.svg)](https://codeclimate.com/github/roidrage/redis-session-store)
[![Gem Version](https://badge.fury.io/rb/redis-session-store.svg)](http://badge.fury.io/rb/redis-session-store)

Expand Down
8 changes: 5 additions & 3 deletions redis-session-store.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
gem.email = ['[email protected]']
gem.summary = 'A drop-in replacement for e.g. MemCacheStore to ' \
'store Rails sessions (and Rails sessions only) in Redis.'
gem.description = gem.summary + ' For great glory!'
gem.description = "#{gem.summary} For great glory!"
gem.homepage = 'https://github.com/roidrage/redis-session-store'
gem.license = 'MIT'

Expand All @@ -21,6 +21,8 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'fakeredis', '~> 0.8'
gem.add_development_dependency 'rake', '~> 13'
gem.add_development_dependency 'rspec', '~> 3'
gem.add_development_dependency 'rubocop', '~> 0.81'
gem.add_development_dependency 'simplecov', '~> 0.17'
gem.add_development_dependency 'rubocop', '~> 1.25'
gem.add_development_dependency 'rubocop-rake', '~> 0.6'
gem.add_development_dependency 'rubocop-rspec', '~> 2.8'
gem.add_development_dependency 'simplecov', '~> 0.21'
end
32 changes: 17 additions & 15 deletions spec/redis_session_store_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
require 'json'

describe RedisSessionStore do
subject(:store) { described_class.new(nil, options) }

let :random_string do
"#{rand}#{rand}#{rand}"
end
let :default_options do
store.instance_variable_get(:@default_options)
end

let :options do
{}
end

subject(:store) { RedisSessionStore.new(nil, options) }

let :default_options do
store.instance_variable_get(:@default_options)
end

it 'assigns a :namespace to @default_options' do
expect(default_options[:namespace]).to eq('rack:session')
end
Expand All @@ -35,7 +34,7 @@
end

it 'creates a redis instance' do
expect(store.instance_variable_get(:@redis)).to_not be_nil
expect(store.instance_variable_get(:@redis)).not_to be_nil
end

it 'assigns the :host option to @default_options' do
Expand Down Expand Up @@ -96,7 +95,7 @@
end

it 'creates a redis instance' do
expect(store.instance_variable_get(:@redis)).to_not be_nil
expect(store.instance_variable_get(:@redis)).not_to be_nil
end

it 'assigns the :host option to @default_options' do
Expand Down Expand Up @@ -228,13 +227,15 @@
context 'when session id is not provided' do
context 'when session id is nil' do
let(:session_id) { nil }

it 'returns false' do
expect(store.send(:session_exists?, :env)).to eq(false)
end
end

context 'when session id is empty string' do
let(:session_id) { '' }

it 'returns false' do
allow(store).to receive(:current_session_id).with(:env).and_return('')
expect(store.send(:session_exists?, :env)).to eq(false)
Expand Down Expand Up @@ -404,28 +405,29 @@

context 'marshal' do
let(:options) { { serializer: :marshal } }
it_should_behave_like 'serializer'

it_behaves_like 'serializer'
end

context 'json' do
let(:options) { { serializer: :json } }
let(:encoded_data) { '{"some":"data"}' }

it_should_behave_like 'serializer'
it_behaves_like 'serializer'
end

context 'hybrid' do
let(:options) { { serializer: :hybrid } }
let(:expected_encoding) { '{"some":"data"}' }

context 'marshal encoded data' do
it_should_behave_like 'serializer'
it_behaves_like 'serializer'
end

context 'json encoded data' do
let(:encoded_data) { '{"some":"data"}' }

it_should_behave_like 'serializer'
it_behaves_like 'serializer'
end
end

Expand All @@ -445,7 +447,7 @@ def self.dump(_value)
let(:options) { { serializer: custom_serializer } }
let(:expected_encoding) { 'somedata' }

it_should_behave_like 'serializer'
it_behaves_like 'serializer'
end
end

Expand Down Expand Up @@ -521,15 +523,15 @@ def self.dump(_value)
%w(on_redis_down on_session_load_error).each do |h|
context 'when nil' do
it 'does not explode at init' do
expect { store }.to_not raise_error
expect { store }.not_to raise_error
end
end

context 'when callable' do
let(:options) { { "#{h}": ->(*) { true } } }

it 'does not explode at init' do
expect { store }.to_not raise_error
expect { store }.not_to raise_error
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Session
class SessionId
attr_reader :public_id

def initialize(public_id)
def initialize(_public_id)
@public_id
end
end
Expand Down

0 comments on commit 5bf8a51

Please sign in to comment.