diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml new file mode 100644 index 0000000..9266b4b --- /dev/null +++ b/.github/workflows/rubyonrails.yml @@ -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 diff --git a/Gemfile b/Gemfile index dd27784..25447bc 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -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 \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 0a09791..b89280c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index cb0d61c..dd99e72 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -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") \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml index 7c44b43..609fc10 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -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. diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index fa16563..71fb31c 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -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('') @@ -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) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index db6e5ff..4e7df44 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -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) } @@ -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)