From 99a3bfbad11ca2245f47717a0781b4b6076fbd0d Mon Sep 17 00:00:00 2001 From: exAspArk Date: Fri, 8 Mar 2024 16:18:19 -0500 Subject: [PATCH] Run tests via GitHub Actions --- .github/workflows/main.yml | 6 +++--- Gemfile | 3 ++- spec/bemi_spec.rb | 32 ++++++++++++++++++++++++++++++-- spec/spec_helper.rb | 1 + 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a0abc4..41e6656 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Ruby on: push: branches: - - master + - main pull_request: @@ -23,5 +23,5 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Run the default task - run: bundle exec rake + - name: Run specs + run: bundle exec rspec diff --git a/Gemfile b/Gemfile index f9c9825..dfda18c 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,6 @@ source "https://rubygems.org" gemspec gem "rake", "~> 13.0" - gem "rspec", "~> 3.0" +gem "pry" +gem 'pg' diff --git a/spec/bemi_spec.rb b/spec/bemi_spec.rb index 8adcda6..20fb2fb 100644 --- a/spec/bemi_spec.rb +++ b/spec/bemi_spec.rb @@ -1,7 +1,35 @@ # frozen_string_literal: true RSpec.describe Bemi do - it "has a version number" do - expect(Bemi::VERSION).not_to eq(nil) + describe '.set_context' do + it 'sets the context' do + Bemi.set_context('test1') + expect(Bemi.context).to eq('test1') + + Bemi.set_context('test2') + expect(Bemi.context).to eq('test2') + end + end + + describe '.append_context' do + it 'appends the context to write SQL queries' do + Bemi.set_context({ foo: 'bar' }) + sql = "INSERT INTO todos (task) VALUES ('Eat')" + adapter = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new({}) + + result = Bemi.append_context.call(sql, adapter) + + expect(result).to eq("INSERT INTO todos (task) VALUES ('Eat') /*Bemi {\"foo\":\"bar\"} Bemi*/") + end + + it 'does not append the context to read SQL queries' do + Bemi.set_context({ foo: 'bar' }) + sql = "SELECT * FROM todos" + adapter = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new({}) + + result = Bemi.append_context.call(sql, adapter) + + expect(result).to eq("SELECT * FROM todos") + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f574650..214eb10 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "bemi-rails" +require "active_record/connection_adapters/postgresql_adapter" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure