Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Testing Github Actions #94

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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 install a prebuilt Ruby version, install dependencies, and
# run tests and linters.
name: "Ruby on Rails CI"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6.5'
bundler-cache: true
- name: Copy example test.yml database config file
run: cp config/settings/test.yml.sample config/settings/test.yml
- name: Copy example env config file
run: cp example.env .env
- name: Set up database schema
run: bin/rails db:schema:load
- name: Run DB migrate command
run: bin/rails db:migrate --trace RAILS_ENV=test
- name: Run tests rspec command
run: bin/rails spec

# lint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Install Ruby and gems
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: '2.6.5'
# bundler-cache: true
# - name: Security audit dependencies
# run: bin/bundler-audit --update
# - name: Security audit application code
# run: bin/brakeman -q -w2
# - name: Lint Ruby files
# run: bin/rubocop --parallel
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ group :development do
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller'
gem 'brakeman', require: false
gem 'bundler-audit', '>= 0.5.0', require: false
gem 'guard', '>= 2.2.2', require: false
gem 'guard-livereload', require: false
gem 'guard-minitest', require: false
Expand Down Expand Up @@ -91,7 +89,9 @@ group :test do
end

group :development, :test do
gem 'database_cleaner'
gem 'brakeman', require: false
gem 'bundler-audit', '>= 0.5.0', require: false
gem 'database_cleaner-active_record'
gem 'json-schema'
gem 'factory_bot_rails'
end
10 changes: 4 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_type (2.1.2)
active_type (2.2.0)
activerecord (>= 3.2)
activejob (5.2.8)
activesupport (= 5.2.8)
Expand Down Expand Up @@ -127,8 +127,6 @@ GEM
countries (~> 4.2)
sort_alphabetical (~> 1.1)
crass (1.0.6)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
Expand Down Expand Up @@ -340,7 +338,7 @@ GEM
minitest (5.15.0)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
multipart-post (2.2.0)
nenv (0.3.0)
nested_form (0.3.2)
netrc (0.11.0)
Expand Down Expand Up @@ -383,7 +381,7 @@ GEM
parser (3.1.2.0)
ast (~> 2.4.1)
pg (1.3.5)
pgcli-rails (0.6.2)
pgcli-rails (0.6.3)
railties (>= 4.2.0)
postmark (1.22.0)
json
Expand Down Expand Up @@ -605,7 +603,7 @@ DEPENDENCIES
config
connection_pool
country_select
database_cleaner
database_cleaner-active_record
devise (>= 4.7.1)
dotenv-rails (>= 2.0.0)
draper
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Rails.application.config.secret_key_base = ENV.fetch("SECRET_KEY_BASE")
Rails.application.config.secret_key_base = ENV.fetch("SECRET_KEY_BASE")
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ development:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

test:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: '9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4laalal19cb'

# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
Expand Down
6 changes: 5 additions & 1 deletion spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
it "should clear avatar from Slack fields if user is not Slack member" do
expect(incomplete_profile.avatar_from_slack).to eq('my_profile_picture.png')
expect(incomplete_profile.avatar_from_slack_imported).to eq(true)

expect(incomplete_profile.reload_avatar_from_slack).to be(true)

expect(incomplete_profile.avatar_from_slack).to eq('')
Expand All @@ -98,8 +98,12 @@
let(:profile) { create(:profile) }

it "should import user's avatar from Slack if user is a Slack member" do
slack_user_info = file_fixture("slack_user_info.json").read
json = JSON.parse(slack_user_info)
allow(SlackApi).to receive(:get_user_info).and_return(json)
slack_user_image = file_fixture("slack_profile_picture.png")
allow(URI).to receive(:parse).with(anything()).and_return(slack_user_image)

expect(profile.download_slack_avatar('https://api.slack.com')).to be(true)
expect(profile.avatar_from_slack_imported).to be(true)
expect(profile.avatar_from_slack_updated_at).not_to be(nil)
Expand Down
5 changes: 3 additions & 2 deletions spec/requests/api/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

response '200', 'Return verified users' do
schema '$ref' => '#/components/schemas/users'

let!(:user) { create(:user) }
let!(:api_key) { create(:api_key, user: user) }
let!(:user_1) { create(:user) }
Expand Down Expand Up @@ -90,13 +90,14 @@
schema schema '$ref' => '#/components/schemas/users'

let!(:user) { create(:user) }
let!(:member) { create(:user) }
let!(:member) { create(:user, first_name: 'user-to-find') }
let!(:api_key) { create(:api_key, user: user) }
let!("query[first_name]") { member.first_name }
let(:Authorization) { 'Bearer ' + api_key.access_token }

run_test! do |response|
data = JSON.parse(response.body)
expect(data['data'].size).to eq(1)
expect(data['data'].first['id']).to eq(member.custom_identifier)
expect(data['data'].first['type']).to eq("user")
expect(data['data'].first['attributes']['first_name']).to eq(member.first_name)
Expand Down