Skip to content

Commit

Permalink
Run tests via GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Mar 8, 2024
1 parent 69a80a5 commit fa4089c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Ruby
on:
push:
branches:
- master
- ci

pull_request:

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ source "https://rubygems.org"
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"
gem "pry"
gem 'pg'
32 changes: 30 additions & 2 deletions spec/bemi_spec.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fa4089c

Please sign in to comment.