Skip to content

Commit 3e47041

Browse files
committed
Add rspec testing
1 parent 2628c63 commit 3e47041

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+252
-124
lines changed

Gemfile

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
35

@@ -10,14 +12,14 @@ gem 'rails', '~> 6.0.0'
1012
gem 'pg', '>= 0.18', '< 2.0'
1113

1214
# Build JSON APIs
13-
gem "fast_jsonapi"
15+
gem 'fast_jsonapi'
1416

1517
# Use Redis adapter to run Action Cable in production
18+
gem 'hiredis', '~> 0.6'
1619
gem 'redis', '~> 4.0'
17-
gem "hiredis", "~> 0.6"
1820

1921
# Use Active Model has_secure_password
20-
# gem 'bcrypt', '~> 3.1.7'
22+
gem 'bcrypt', '~> 3.1.7'
2123

2224
# Use Active Storage variant
2325
# gem 'image_processing', '~> 1.2'
@@ -29,14 +31,18 @@ gem 'bootsnap', '>= 1.4.2', require: false
2931
# gem 'rack-cors'
3032

3133
# Web server
32-
gem "puma"
34+
gem 'puma'
35+
36+
gem 'sidekiq'
3337

3438
group :development, :test do
3539
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
36-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
37-
gem "foreman"
38-
gem "guard-rspec"
39-
gem "rspec-rails"
40+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
41+
gem 'foreman'
42+
gem 'guard-rspec'
43+
gem 'rspec-rails'
44+
gem 'rubocop'
45+
gem "shoulda-matchers"
4046
end
4147

4248
group :development do
@@ -47,4 +53,4 @@ group :development do
4753
end
4854

4955
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
50-
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
56+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

Gemfile.lock

+30
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ GEM
5656
minitest (~> 5.1)
5757
tzinfo (~> 1.1)
5858
zeitwerk (~> 2.1, >= 2.1.8)
59+
ast (2.4.0)
60+
bcrypt (3.1.13)
5961
bootsnap (1.4.5)
6062
msgpack (~> 1.0)
6163
builder (3.2.3)
6264
byebug (11.0.1)
6365
coderay (1.1.2)
6466
concurrent-ruby (1.1.5)
67+
connection_pool (2.2.2)
6568
crass (1.0.4)
6669
diff-lcs (1.3)
6770
dotenv (0.7.0)
@@ -92,6 +95,7 @@ GEM
9295
hiredis (0.6.3)
9396
i18n (1.6.0)
9497
concurrent-ruby (~> 1.0)
98+
jaro_winkler (1.5.3)
9599
listen (3.1.5)
96100
rb-fsevent (~> 0.9, >= 0.9.4)
97101
rb-inotify (~> 0.9, >= 0.9.7)
@@ -117,13 +121,18 @@ GEM
117121
notiffany (0.1.3)
118122
nenv (~> 0.1)
119123
shellany (~> 0.0)
124+
parallel (1.17.0)
125+
parser (2.6.4.0)
126+
ast (~> 2.4.0)
120127
pg (1.1.4)
121128
pry (0.12.2)
122129
coderay (~> 1.1.0)
123130
method_source (~> 0.9.0)
124131
puma (4.1.0)
125132
nio4r (~> 2.0)
126133
rack (2.0.7)
134+
rack-protection (2.0.7)
135+
rack
127136
rack-test (1.1.0)
128137
rack (>= 1.0, < 3)
129138
rails (6.0.0)
@@ -152,6 +161,7 @@ GEM
152161
method_source
153162
rake (>= 0.8.7)
154163
thor (>= 0.20.3, < 2.0)
164+
rainbow (3.0.0)
155165
rake (12.3.3)
156166
rb-fsevent (0.10.3)
157167
rb-inotify (0.10.0)
@@ -178,8 +188,23 @@ GEM
178188
rspec-mocks (~> 3.8.0)
179189
rspec-support (~> 3.8.0)
180190
rspec-support (3.8.2)
191+
rubocop (0.74.0)
192+
jaro_winkler (~> 1.5.1)
193+
parallel (~> 1.10)
194+
parser (>= 2.6)
195+
rainbow (>= 2.2.2, < 4.0)
196+
ruby-progressbar (~> 1.7)
197+
unicode-display_width (>= 1.4.0, < 1.7)
198+
ruby-progressbar (1.10.1)
181199
ruby_dep (1.5.0)
182200
shellany (0.0.1)
201+
shoulda-matchers (4.1.2)
202+
activesupport (>= 4.2.0)
203+
sidekiq (6.0.0)
204+
connection_pool (>= 2.2.2)
205+
rack (>= 2.0.0)
206+
rack-protection (>= 2.0.0)
207+
redis (>= 4.1.0)
183208
spring (2.1.0)
184209
spring-watcher-listen (2.0.1)
185210
listen (>= 2.7, < 4.0)
@@ -195,6 +220,7 @@ GEM
195220
thread_safe (0.3.6)
196221
tzinfo (1.2.5)
197222
thread_safe (~> 0.1)
223+
unicode-display_width (1.6.0)
198224
websocket-driver (0.7.1)
199225
websocket-extensions (>= 0.1.0)
200226
websocket-extensions (0.1.4)
@@ -204,6 +230,7 @@ PLATFORMS
204230
ruby
205231

206232
DEPENDENCIES
233+
bcrypt (~> 3.1.7)
207234
bootsnap (>= 1.4.2)
208235
byebug
209236
fast_jsonapi
@@ -216,6 +243,9 @@ DEPENDENCIES
216243
rails (~> 6.0.0)
217244
redis (~> 4.0)
218245
rspec-rails
246+
rubocop
247+
shoulda-matchers
248+
sidekiq
219249
spring
220250
spring-watcher-listen (~> 2.0.0)
221251
tzinfo-data

Guardfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# A sample Guardfile
24
# More info at https://github.com/guard/guard#readme
35

@@ -24,8 +26,8 @@
2426
# * zeus: 'zeus rspec' (requires the server to be started separately)
2527
# * 'just' rspec: 'rspec'
2628

27-
guard :rspec, cmd: "bundle exec rspec" do
28-
require "guard/rspec/dsl"
29+
guard :rspec, cmd: 'bundle exec rspec' do
30+
require 'guard/rspec/dsl'
2931
dsl = Guard::RSpec::Dsl.new(self)
3032

3133
# Feel free to open issues for suggestions and improvements
@@ -41,7 +43,7 @@ guard :rspec, cmd: "bundle exec rspec" do
4143
dsl.watch_spec_files_for(ruby.lib_files)
4244

4345
# Rails files
44-
rails = dsl.rails(view_extensions: %w(erb haml slim))
46+
rails = dsl.rails(view_extensions: %w[erb haml slim])
4547
dsl.watch_spec_files_for(rails.app_files)
4648
dsl.watch_spec_files_for(rails.views)
4749

@@ -65,6 +67,6 @@ guard :rspec, cmd: "bundle exec rspec" do
6567
# Turnip features and steps
6668
watch(%r{^spec/acceptance/(.+)\.feature$})
6769
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68-
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
70+
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
6971
end
7072
end

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ Run locally: `bundle exec foreman start` and then view it on http://localhost:30
1010
## Testing
1111

1212
Run all tests: `bundle exec rspec` or running guard for continous testing `bundle exec guard`.
13+
14+
## Deployment
15+
16+
Deployment is done via [CI/CD](https://circleci.com).
17+
18+
## Errors / Exceptions
19+
20+
Errors and exceptions are collected via [Sentry.io](https://sentry.io).

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Add your own tasks in files placed in lib/tasks ending in .rake,
24
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
35

app/channels/application_cable/channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Channel < ActionCable::Channel::Base
35
end

app/channels/application_cable/connection.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Connection < ActionCable::Connection::Base
35
end
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::API
24
end

app/jobs/application_job.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationJob < ActiveJob::Base
24
# Automatically retry jobs that encountered a deadlock
35
# retry_on ActiveRecord::Deadlocked

app/mailers/application_mailer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationMailer < ActionMailer::Base
24
default from: '[email protected]'
35
layout 'mailer'

app/models/application_record.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationRecord < ActiveRecord::Base
24
self.abstract_class = true
35
end

app/models/user.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class User < ApplicationRecord
4+
has_secure_password
25
end

bin/bundle

+21-17
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,59 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require "rubygems"
11+
require 'rubygems'
1212

1313
m = Module.new do
14-
module_function
14+
module_function
1515

1616
def invoked_as_script?
17-
File.expand_path($0) == File.expand_path(__FILE__)
17+
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
1818
end
1919

2020
def env_var_version
21-
ENV["BUNDLER_VERSION"]
21+
ENV['BUNDLER_VERSION']
2222
end
2323

2424
def cli_arg_version
2525
return unless invoked_as_script? # don't want to hijack other binstubs
26-
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
26+
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27+
2728
bundler_version = nil
2829
update_index = nil
2930
ARGV.each_with_index do |a, i|
3031
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
3132
bundler_version = a
3233
end
3334
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34-
bundler_version = $1 || ">= 0.a"
35+
36+
bundler_version = Regexp.last_match(1) || '>= 0.a'
3537
update_index = i
3638
end
3739
bundler_version
3840
end
3941

4042
def gemfile
41-
gemfile = ENV["BUNDLE_GEMFILE"]
43+
gemfile = ENV['BUNDLE_GEMFILE']
4244
return gemfile if gemfile && !gemfile.empty?
4345

44-
File.expand_path("../../Gemfile", __FILE__)
46+
File.expand_path('../Gemfile', __dir__)
4547
end
4648

4749
def lockfile
4850
lockfile =
4951
case File.basename(gemfile)
50-
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
52+
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
5153
else "#{gemfile}.lock"
5254
end
5355
File.expand_path(lockfile)
5456
end
5557

5658
def lockfile_version
5759
return unless File.file?(lockfile)
60+
5861
lockfile_contents = File.read(lockfile)
5962
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
63+
6064
Regexp.last_match(1)
6165
end
6266

@@ -68,24 +72,26 @@ m = Module.new do
6872
end
6973

7074
def load_bundler!
71-
ENV["BUNDLE_GEMFILE"] ||= gemfile
75+
ENV['BUNDLE_GEMFILE'] ||= gemfile
7276

7377
# must dup string for RG < 1.8 compatibility
7478
activate_bundler(bundler_version.dup)
7579
end
7680

7781
def activate_bundler(bundler_version)
78-
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79-
bundler_version = "< 2"
82+
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0')
83+
bundler_version = '< 2'
8084
end
8185
gem_error = activation_error_handling do
82-
gem "bundler", bundler_version
86+
gem 'bundler', bundler_version
8387
end
8488
return if gem_error.nil?
89+
8590
require_error = activation_error_handling do
86-
require "bundler/version"
91+
require 'bundler/version'
8792
end
8893
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
94+
8995
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
9096
exit 42
9197
end
@@ -100,6 +106,4 @@ end
100106

101107
m.load_bundler!
102108

103-
if m.invoked_as_script?
104-
load Gem.bin_path("bundler", "bundle")
105-
end
109+
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?

bin/rails

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
begin
3-
load File.expand_path('../spring', __FILE__)
5+
load File.expand_path('spring', __dir__)
46
rescue LoadError => e
57
raise unless e.message.include?('spring')
68
end

bin/rake

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
begin
3-
load File.expand_path('../spring', __FILE__)
5+
load File.expand_path('spring', __dir__)
46
rescue LoadError => e
57
raise unless e.message.include?('spring')
68
end

bin/setup

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
require 'fileutils'
35

46
# path to your application root.

bin/spring

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

34
# This file loads Spring without using Bundler, in order to be fast.
45
# It gets overwritten when you run the `spring binstub` command.

config.ru

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# This file is used by Rack-based servers to start the application.
24

35
require_relative 'config/environment'

0 commit comments

Comments
 (0)