Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
35 changes: 35 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches: [ 'develop' ]
pull_request:
branches: ['**']

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- '3.3'
- '3.2'
Comment thread
BenTopping marked this conversation as resolved.
rails:
- '7.1'
- '7.2'
database_url:
- sqlite3:test_db
env:
RAILS_VERSION: ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
name: Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }} DB ${{ matrix.database_url }}
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rake test
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
gemspec

platforms :ruby do
gem 'sqlite3', '1.3.10'
gem 'sqlite3', '>= 1.4'
end

platforms :jruby do
Expand All @@ -17,7 +17,7 @@ when 'master'
gem 'railties', { git: 'https://github.com/rails/rails.git' }
gem 'arel', { git: 'https://github.com/rails/arel.git' }
when 'default'
gem 'railties', '>= 5.0'
gem 'railties', '~> 7.1.0'
else
gem 'railties', "~> #{version}"
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ which *should* be compatible with JSON:API compliant server implementations such

Add JR to your application's `Gemfile`:

gem 'jsonapi-resources'
gem 'sanger-jsonapi-resources'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jsonapi-resources
$ gem install sanger-jsonapi-resources

**For further usage see the [v0.9 beta Guide](http://jsonapi-resources.com/v0.9/guide/)**

Expand Down
13 changes: 7 additions & 6 deletions jsonapi-resources.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'jsonapi/resources/version'

Gem::Specification.new do |spec|
spec.name = 'jsonapi-resources'
spec.name = 'sanger-jsonapi-resources'
spec.version = JSONAPI::Resources::VERSION
spec.authors = ['Dan Gebhardt', 'Larry Gebhardt']
spec.email = ['dan@cerebris.com', 'larry@cerebris.com']
spec.authors = ['PSD Team - Wellcome Trust Sanger Institute']
spec.email = ['psd@sanger.ac.uk']
spec.summary = 'Easily support JSON API in Rails.'
spec.description = 'A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
spec.homepage = 'https://github.com/cerebris/jsonapi-resources'
spec.description = 'Forked from jsonapi-resources. A resource-centric approach to implementing the controllers, routes, and serializers needed to support the JSON API spec.'
spec.homepage = 'https://github.com/sanger/jsonapi-resources'
spec.license = 'MIT'

spec.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE.txt README.md)
Expand All @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.1'

spec.add_development_dependency 'bundler', '~> 1.5'
spec.add_development_dependency 'bundler', '>= 1.5', '< 3.0'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'minitest-spec-rails'
Expand All @@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'activerecord', '>= 4.1'
spec.add_dependency 'railties', '>= 4.1'
spec.add_dependency 'concurrent-ruby'
spec.add_runtime_dependency 'csv'
end
1 change: 1 addition & 0 deletions lib/generators/jsonapi/controller_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
module Jsonapi
class ControllerGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
Expand Down
1 change: 1 addition & 0 deletions lib/generators/jsonapi/resource_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
module Jsonapi
class ResourceGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi/resources/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module JSONAPI
module Resources
VERSION = '0.9.0'
VERSION = '0.1.1'
end
end
7 changes: 7 additions & 0 deletions lib/sanger-jsonapi-resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# As we are packaging 'sanger-jsonapi-resources' as a separate gem, RubyGems expects
# the main file to be 'lib/sanger-jsonapi-resources.rb' to match the gem name.
# Without this file, requiring the gem or Rails autoloading would fail, even if the internal code is unchanged.
# This file exists to ensure compatibility with RubyGems and Bundler.
# The easiest solution is to use this wrapper file, which simply requires the original 'jsonapi-resources' code,
# so all internal references and modules remain unchanged and compatible.
require_relative 'jsonapi-resources'
31 changes: 19 additions & 12 deletions test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@
t.timestamps null: false
end

create_table :posts_tags, force: true do |t|
t.references :post, :tag, index: true


create_table :posts_tags, force: true, id: false do |t|
t.references :post, null: false
t.references :tag, null: false
end
add_index :posts_tags, [:post_id, :tag_id], unique: true

create_table :special_post_tags, force: true do |t|
t.references :post, :tag, index: true
t.references :post, null: false, foreign_key: false
t.references :tag, null: false, foreign_key: false
end
add_index :special_post_tags, [:post_id, :tag_id], unique: true

create_table :comments_tags, force: true do |t|
t.references :comment, :tag, index: true
t.references :comment, null: false
t.references :tag, null: false
end

create_table :iso_currencies, id: false, force: true do |t|
Expand All @@ -95,7 +100,8 @@
end

create_table :planets_tags, force: true do |t|
t.references :planet, :tag, index: true
t.references :planet, null: false
t.references :tag, null: false
end
add_index :planets_tags, [:planet_id, :tag_id], unique: true

Expand Down Expand Up @@ -184,7 +190,8 @@
end

create_table :purchase_orders_order_flags, force: true do |t|
t.references :purchase_order, :order_flag, index: true
t.references :purchase_order, null: false
t.references :order_flag, null: false
end
add_index :purchase_orders_order_flags, [:purchase_order_id, :order_flag_id], unique: true, name: "po_flags_idx"

Expand Down Expand Up @@ -285,8 +292,8 @@

create_table :related_things, force: true do |t|
t.string :name
t.references :from, references: :thing
t.references :to, references: :thing
t.references :from
t.references :to

t.timestamps null: false
end
Expand Down Expand Up @@ -342,8 +349,8 @@ class Post < ActiveRecord::Base
belongs_to :writer, class_name: 'Person', foreign_key: 'author_id'
has_many :comments
has_and_belongs_to_many :tags, join_table: :posts_tags
has_many :special_post_tags, source: :tag
has_many :special_tags, through: :special_post_tags, source: :tag
has_many :special_post_tags
has_many :special_tags, through: :special_post_tags
belongs_to :section
has_one :parent_post, class_name: 'Post', foreign_key: 'parent_post_id'

Expand Down Expand Up @@ -621,8 +628,8 @@ class Thing < ActiveRecord::Base
end

class RelatedThing < ActiveRecord::Base
belongs_to :from, class_name: Thing, foreign_key: :from_id
belongs_to :to, class_name: Thing, foreign_key: :to_id
belongs_to :from, class_name: 'Thing', foreign_key: :from_id
belongs_to :to, class_name: 'Thing', foreign_key: :to_id
end

class Question < ActiveRecord::Base
Expand Down
15 changes: 9 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
end

require 'active_record/railtie'
require 'rails/test_help'
require 'minitest/mock'
require 'jsonapi-resources'
require 'pry'
Expand All @@ -38,7 +37,6 @@
config.json_key_format = :camelized_key
end

puts "Testing With RAILS VERSION #{Rails.version}"

class TestApp < Rails::Application
config.eager_load = false
Expand Down Expand Up @@ -203,9 +201,14 @@ def show_queries
end
end

# Establish the connection before loading schema
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")


TestApp.initialize!
# ✅ Now load the schema AFTER the connection is ready
require_relative 'fixtures/active_record'

require File.expand_path('../fixtures/active_record', __FILE__)

module Pets
module V1
Expand Down Expand Up @@ -417,20 +420,20 @@ def run_in_transaction?
true
end

self.fixture_path = "#{Rails.root}/fixtures"
self.fixture_paths = ["#{Rails.root}/fixtures"]
fixtures :all
end

class ActiveSupport::TestCase
self.fixture_path = "#{Rails.root}/fixtures"
self.fixture_paths = ["#{Rails.root}/fixtures"]
fixtures :all
setup do
@routes = TestApp.routes
end
end

class ActionDispatch::IntegrationTest
self.fixture_path = "#{Rails.root}/fixtures"
self.fixture_paths = ["#{Rails.root}/fixtures"]
fixtures :all

def assert_jsonapi_response(expected_status, msg = nil)
Expand Down