diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..573705517 --- /dev/null +++ b/.github/dependabot.yml @@ -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" diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 000000000..60f056246 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -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' + 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 diff --git a/Gemfile b/Gemfile index c58d1c896..805949eb6 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -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 diff --git a/README.md b/README.md index c494c9c74..54df000ba 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ 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: @@ -36,7 +36,7 @@ And then execute: 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/)** diff --git a/jsonapi-resources.gemspec b/jsonapi-resources.gemspec index 3f031d173..9942ddf9e 100644 --- a/jsonapi-resources.gemspec +++ b/jsonapi-resources.gemspec @@ -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) @@ -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' @@ -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 diff --git a/lib/generators/jsonapi/controller_generator.rb b/lib/generators/jsonapi/controller_generator.rb index 41ee4eb1e..d6aba8bf9 100644 --- a/lib/generators/jsonapi/controller_generator.rb +++ b/lib/generators/jsonapi/controller_generator.rb @@ -1,3 +1,4 @@ +require 'rails/generators' module Jsonapi class ControllerGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) diff --git a/lib/generators/jsonapi/resource_generator.rb b/lib/generators/jsonapi/resource_generator.rb index 80aa24b4d..25feb14a1 100644 --- a/lib/generators/jsonapi/resource_generator.rb +++ b/lib/generators/jsonapi/resource_generator.rb @@ -1,3 +1,4 @@ +require 'rails/generators' module Jsonapi class ResourceGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) diff --git a/lib/jsonapi/resources/version.rb b/lib/jsonapi/resources/version.rb index 3b1edaa47..86e2bcf31 100644 --- a/lib/jsonapi/resources/version.rb +++ b/lib/jsonapi/resources/version.rb @@ -1,5 +1,5 @@ module JSONAPI module Resources - VERSION = '0.9.0' + VERSION = '0.1.1' end end diff --git a/lib/sanger-jsonapi-resources.rb b/lib/sanger-jsonapi-resources.rb new file mode 100644 index 000000000..2b4763cf6 --- /dev/null +++ b/lib/sanger-jsonapi-resources.rb @@ -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' diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index b5c11d72d..9a958fa2e 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -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| @@ -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 @@ -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" @@ -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 @@ -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' @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 51ba0459d..206fe8bd6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,7 +19,6 @@ end require 'active_record/railtie' -require 'rails/test_help' require 'minitest/mock' require 'jsonapi-resources' require 'pry' @@ -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 @@ -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 @@ -417,12 +420,12 @@ 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 @@ -430,7 +433,7 @@ class ActiveSupport::TestCase 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)