Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rails 8.0 support #3

Open
wants to merge 7 commits into
base: master
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
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ jobs:
strategy:
fail-fast: false
matrix:
gemfile: ['rails_7.0', 'rails_7.1']
ruby: [3.3, 3.2, 3.1]
gemfile: ['rails_7.0', 'rails_7.1', 'rails_8.0']
ruby: [3.3, 3.2]
include:
- gemfile: rails_7.1
ruby: '3.1'
- gemfile: rails_7.0
ruby: '3.1'
- gemfile: rails_7.0
ruby: '3.0'
- gemfile: rails_7.0
ruby: 2.7
- gemfile: rails_6.1
ruby: 2.7
- gemfile: rails_6.0
ruby: 2.7
- gemfile: rails_5.2
ruby: 2.7
- gemfile: rails_5.1
ruby: 2.7
- gemfile: rails_5.0
ruby: 2.7

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails_5.0.gemfile

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/rails_5.1.gemfile

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/rails_5.2.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "rails", "~> 7.0.2"
gem "sqlite3"
gem "sqlite3", "~> 1.4.0"

gemspec path: "../"
1 change: 0 additions & 1 deletion gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

source "https://rubygems.org"

gem "active_attr", "~> 0.16" # git: "https://github.com/mathieujobin/active_attr", branch: "rails-7.1-support"
gem "rails", "~> 7.1.1"
gem "sqlite3"

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.0.gemfile → gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rails", "~> 6.0.4"
gem "rails", "~> 8.0.1"
gem "sqlite3"

gemspec path: "../"
1 change: 0 additions & 1 deletion lib/webhook_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'active_support/all'
require 'active_record'
require 'active_job'
require 'ph_model'
require 'validate_url'
require 'faraday'
require 'faraday-encoding'
Expand Down
12 changes: 9 additions & 3 deletions lib/webhook_system/base_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ module WebhookSystem

# This is the class meant to be used as the base class for any Events sent through the Webhook system
class BaseEvent
include PhModel
include ActiveModel::Attributes
include ActiveModel::AttributeAssignment
include ActiveModel::Validations

def initialize(*args, &block)
super(*args, &block)
def initialize(...)
super
@event_id = SecureRandom.uuid.freeze
end

Expand Down Expand Up @@ -39,6 +41,10 @@ def as_json
result.deep_stringify_keys
end

def self.build(attrs)
new.tap { |instance| instance.assign_attributes(attrs) }
end

def self.key_is_reserved?(key)
key.to_s.in? %w[event event_id]
end
Expand Down
2 changes: 2 additions & 0 deletions lib/webhook_system/encoder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'base64'

module WebhookSystem

# Class in charge of encoding and decoding encrypted payload
Expand Down
4 changes: 2 additions & 2 deletions lib/webhook_system/event_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class EventLog < ActiveRecord::Base
validates :event_name, presence: true
validates :status, presence: true

serialize :request, JSON
serialize :response, JSON
serialize :request, coder: JSON
serialize :response, coder: JSON

def self.construct(subscription, event, request, response)
request_info = {
Expand Down
6 changes: 2 additions & 4 deletions lib/webhook_system/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ def topic_names=(new_topics)
new_topics.reject!(&:blank?)
add_topics = new_topics - topic_names

new_topics_attributes = []

topics.each do |topic|
new_topics_attributes << {
new_topics_attributes = topics.map do |topic|
{
id: topic.id,
name: topic.name,
_destroy: new_topics.exclude?(topic.name),
Expand Down
9 changes: 8 additions & 1 deletion spec/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
describe WebhookSystem, aggregate_failures: true do
let(:widget_class) do
Class.new do
include PhModel
include ActiveModel::Attributes
include ActiveModel::AttributeAssignment
include ActiveModel::Validations

attribute :foo
attribute :bar

def as_json
{ foo: foo, bar: bar }
end

def self.build(attrs)
new.tap { |instance| instance.assign_attributes(attrs) }
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def payload_attributes
end
end

let(:event) { event_class.build(name: 'John', age: 21) }
let(:event) { event_class.new.tap { |e| e.assign_attributes(name: 'John', age: 21) } }

let(:expected_payload) do
{
Expand Down
Binary file added test.db-shm
Binary file not shown.
Binary file added test.db-wal
Binary file not shown.
8 changes: 4 additions & 4 deletions webhook_system.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ Gem::Specification.new do |gem|
}

gem.required_ruby_version = '> 2.7.0'
gem.add_runtime_dependency 'activesupport', '> 5.0', '< 7.2'
gem.add_runtime_dependency 'activerecord', '> 5.0', '< 7.2'
gem.add_runtime_dependency 'activejob', '> 5.0', '< 7.2'
gem.add_runtime_dependency 'activemodel', '>= 6.1', '< 8.1'
gem.add_runtime_dependency 'activesupport', '>= 6.1', '< 8.1'
gem.add_runtime_dependency 'activerecord', '>= 6.1', '< 8.1'
gem.add_runtime_dependency 'activejob', '>= 6.1', '< 8.1'
gem.add_runtime_dependency 'faraday', '> 0.9'
gem.add_runtime_dependency 'faraday-encoding', '>= 0.0.2', '< 1.0'
gem.add_runtime_dependency 'ph_model'
gem.add_runtime_dependency 'validate_url', '~> 1.0'

gem.add_development_dependency 'bundler', '> 1.17', '< 2.6'
Expand Down