Skip to content

Commit 50355ce

Browse files
authored
Merge pull request #37 from RadiusNetworks/add-radius-spec-and-reviewdog
Add radius-spec and reviewdog
2 parents 540b90f + 9751a10 commit 50355ce

File tree

19 files changed

+199
-27
lines changed

19 files changed

+199
-27
lines changed

.rubocop.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
inherit_mode:
2+
merge:
3+
- AllowedNames
4+
- Exclude
5+
- IgnoredPatterns
6+
7+
inherit_gem:
8+
radius-spec: common_rubocop_rails.yml
9+
10+
AllCops:
11+
TargetRubyVersion: 2.2.3 # Until we can drop support

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ sudo: false
55
before_install:
66
- gem update --system
77
- gem install bundler
8-
script: bin/rake
8+
before_script:
9+
- "bin/ci-code-review"
10+
script: bin/ci
911
rvm:
1012
- 2.5.0
1113
env:

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ gemspec
1717

1818
rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
1919
eval_gemfile rails_dependencies_gemfile
20+
21+
gem 'radius-spec', require: false, group: %i[development test] if RUBY_VERSION.to_f >= 2.5

app/controllers/kracken/sessions_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Kracken
44
class SessionsController < ActionController::Base
5+
protect_from_forgery with: :exception
56

67
def create
78
@user = user_class.find_or_create_from_auth_hash(auth_hash)

bin/ci

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# script/ci: Setup environment for CI to run tests. This is primarily
4+
# designed to run on the continuous integration server.
5+
6+
set -e
7+
cd "$(dirname "$0")/.."
8+
9+
# setup environment
10+
export DEFAULT_HOST="https://account.radiusnetworks.com"
11+
export RAILS_ROOT="$(cd "$(dirname "$0")"/.. && pwd)"
12+
export RAILS_ENV="test"
13+
export RACK_ENV="test"
14+
export RACK_ROOT="$RAILS_ROOT"
15+
16+
# Run the specs for the rails app
17+
echo " ---> Running tests"
18+
./bin/rspec --require rails_helper
19+
20+
if [ "$TRAVIS_RUBY_VERSION" = "2.5.0" ]; then
21+
# Script for running Rubocop
22+
# A Ruby static code analyzer, based on the community Ruby style guide.
23+
# http://rubocop.readthedocs.io
24+
echo " ---> Running rubocop"
25+
./bin/rubocop --config .rubocop.yml --lint
26+
fi
27+
28+
# Script for running Brakeman tests
29+
# Brakeman is a security scanner
30+
# https://github.com/presidentbeef/brakeman.
31+
echo " ---> Running breakman"
32+
gem install --no-rdoc --no-ri brakeman slim coffee-rails
33+
brakeman --run-all-checks --exit-on-warn --ignore-config config/brakeman.ignore .

bin/ci-code-review

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Requires REVIEWDOG_GITHUB_API_TOKEN to be set in the envionment. We use a
4+
# token from the admin account so that the comments look as if they come from
5+
# Radbot.
6+
7+
# See:
8+
# - https://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
9+
# - https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
10+
# - https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
11+
if [[ "$TRAVIS_PULL_REQUEST" = "false" ]] || [[ "$TRAVIS_BRANCH" = "production" ]]; then
12+
exit
13+
fi
14+
15+
if ! [ "$TRAVIS_RUBY_VERSION" = "2.5.0" ]; then
16+
exit
17+
fi
18+
19+
set -e
20+
cd "$(dirname "$0")/.."
21+
22+
REVIEWDOG_VERSION="0.9.9"
23+
24+
if ! [ "$(./bin/reviewdog -version)" = "$REVIEWDOG_VERSION" ]; then
25+
echo "Installing reviewdog version ${REVIEWDOG_VERSION}..."
26+
curl -fsSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 \
27+
-o ./bin/reviewdog
28+
chmod +x ./bin/reviewdog
29+
fi
30+
31+
echo Rubocop Version: $(./bin/rubocop --version)
32+
echo Review Dog Version: $(./bin/reviewdog -version)
33+
34+
# Add `-diff="git diff master"` to reviewdog args when running locally
35+
./bin/rubocop --config .rubocop.yml --extra-details --display-style-guide --rails | \
36+
./bin/reviewdog -f=rubocop -reporter=github-pr-check

bin/rake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rake' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rake", "rake")

bin/rspec

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rspec-core", "rspec")

bin/rubocop

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rubocop' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("rubocop", "rubocop")

kracken.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Gem::Specification.new do |s|
1515
s.summary = 'Rails engine that consumes the Kracken'
1616
s.description = 'Rails engine for use with the Radius Networks Account Server.'
1717

18-
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
18+
s.files = Dir['{app,exe,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
19+
s.bindir = "exe"
20+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
1921

2022
s.add_dependency 'rails', [">= 4.0", "< 6.0"]
2123
s.add_dependency 'omniauth', '~> 1.0'

0 commit comments

Comments
 (0)