Skip to content

Commit 5bb56cb

Browse files
authored
Merge branch 'master' into fix/processor
2 parents b444939 + e58687c commit 5bb56cb

38 files changed

+1589
-692
lines changed

.travis.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
language: ruby
22
sudo: false
33
env:
4-
- "RAILS_VERSION=4.2.7"
5-
- "RAILS_VERSION=5.0.0"
4+
- "RAILS_VERSION=4.2.8"
5+
- "RAILS_VERSION=5.0.2"
6+
- "RAILS_VERSION=5.1.0"
67
- "RAILS_VERSION=master"
78
rvm:
89
- 2.1.10
9-
- 2.2.6
10-
- 2.3.3
11-
- 2.4.0
10+
- 2.2.7
11+
- 2.3.4
12+
- 2.4.1
1213
matrix:
1314
exclude:
1415
- rvm: 2.1.10
15-
env: "RAILS_VERSION=5.0.0"
16-
- rvm: 2.4.0
17-
env: "RAILS_VERSION=4.2.7"
16+
env: "RAILS_VERSION=5.0.2"
17+
- rvm: 2.1.10
18+
env: "RAILS_VERSION=5.1.0"
19+
- rvm: 2.1.10
20+
env: "RAILS_VERSION=master"
1821
allow_failures:
1922
- env: "RAILS_VERSION=master"

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 Larry Gebhardt
1+
Copyright (c) 2014-2017 Cerebris Corporation
22

33
MIT License
44

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ Or install it yourself as:
4848
4. Push to the branch (`git push origin my-new-feature`)
4949
5. Create a new Pull Request
5050

51+
## Did you find a bug?
52+
53+
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/cerebris/jsonapi-resources/issues).
54+
55+
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/cerebris/jsonapi-resources/issues/new).
56+
Be sure to include a **title and clear description**, as much relevant information as possible,
57+
and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
58+
59+
* If possible, use the relevant bug report templates to create the issue.
60+
Simply copy the content of the appropriate template into a .rb file, make the necessary changes to demonstrate the issue,
61+
and **paste the content into the issue description**:
62+
* [**Rails 5** issues](https://github.com/cerebris/jsonapi-resources/blob/master/lib/bug_report_templates/rails_5_master.rb)
63+
64+
5165
## License
5266

53-
Copyright 2014-2016 Cerebris Corporation. MIT License (see LICENSE for details).
67+
Copyright 2014-2017 Cerebris Corporation. MIT License (see LICENSE for details).

Rakefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,28 @@ Rake::TestTask.new do |t|
88
t.test_files = FileList['test/**/*_test.rb']
99
end
1010

11-
task default: :test
11+
task default: [:test]
1212

1313
desc 'Run benchmarks'
1414
namespace :test do
1515
Rake::TestTask.new(:benchmark) do |t|
1616
t.pattern = 'test/benchmark/*_benchmark.rb'
1717
end
1818
end
19+
20+
desc 'Test bug report template'
21+
namespace :test do
22+
namespace :bug_report_template do
23+
task :rails_5 do
24+
puts 'Test bug report templates'
25+
jsonapi_resources_root = File.expand_path('..', __FILE__)
26+
chdir_path = File.join(jsonapi_resources_root, 'lib', 'bug_report_templates')
27+
report_env = {'SILENT' => 'true', 'JSONAPI_RESOURCES_PATH' => jsonapi_resources_root}
28+
Bundler.with_clean_env do
29+
Dir.chdir(chdir_path) do
30+
abort('bug report template rails_5_master fails') unless system(report_env, Gem.ruby, 'rails_5_master.rb')
31+
end
32+
end
33+
end
34+
end
35+
end
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
begin
2+
require 'bundler/inline'
3+
rescue LoadError => e
4+
STDERR.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
5+
raise e
6+
end
7+
8+
gemfile(true) do
9+
source 'https://rubygems.org'
10+
11+
gem 'rails', require: false
12+
gem 'sqlite3', platform: :mri
13+
14+
gem 'activerecord-jdbcsqlite3-adapter',
15+
git: 'https://github.com/jruby/activerecord-jdbc-adapter',
16+
branch: 'rails-5',
17+
platform: :jruby
18+
19+
gem 'jsonapi-resources', require: false
20+
end
21+
22+
# prepare active_record database
23+
require 'active_record'
24+
25+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
26+
ActiveRecord::Base.logger = Logger.new(STDOUT)
27+
28+
ActiveRecord::Schema.define do
29+
# Add your schema here
30+
create_table :your_models, force: true do |t|
31+
t.string :name
32+
end
33+
end
34+
35+
# create models
36+
class YourModel < ActiveRecord::Base
37+
end
38+
39+
# prepare rails app
40+
require 'action_controller/railtie'
41+
# require 'action_view/railtie'
42+
require 'jsonapi-resources'
43+
44+
class ApplicationController < ActionController::Base
45+
end
46+
47+
# prepare jsonapi resources and controllers
48+
class YourModelsController < ApplicationController
49+
include JSONAPI::ActsAsResourceController
50+
end
51+
52+
class YourModelResource < JSONAPI::Resource
53+
attribute :name
54+
filter :name
55+
end
56+
57+
class TestApp < Rails::Application
58+
config.root = File.dirname(__FILE__)
59+
config.logger = Logger.new(STDOUT)
60+
Rails.logger = config.logger
61+
62+
secrets.secret_token = 'secret_token'
63+
secrets.secret_key_base = 'secret_key_base'
64+
65+
config.eager_load = false
66+
end
67+
68+
# initialize app
69+
Rails.application.initialize!
70+
71+
JSONAPI.configure do |config|
72+
config.json_key_format = :underscored_key
73+
config.route_format = :underscored_key
74+
end
75+
76+
# draw routes
77+
Rails.application.routes.draw do
78+
jsonapi_resources :your_models, only: [:index, :create]
79+
end
80+
81+
# prepare tests
82+
require 'minitest/autorun'
83+
require 'rack/test'
84+
85+
# Replace this with the code necessary to make your test fail.
86+
class BugTest < Minitest::Test
87+
include Rack::Test::Methods
88+
89+
def json_api_headers
90+
{'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
91+
end
92+
93+
def test_index_your_models
94+
record = YourModel.create! name: 'John Doe'
95+
get '/your_models', nil, json_api_headers
96+
assert last_response.ok?
97+
json_response = JSON.parse(last_response.body)
98+
refute_nil json_response['data']
99+
refute_empty json_response['data']
100+
refute_empty json_response['data'].first
101+
assert record.id.to_s, json_response['data'].first['id']
102+
assert 'your_models', json_response['data'].first['type']
103+
assert({'name' => 'John Doe'}, json_response['data'].first['attributes'])
104+
end
105+
106+
def test_create_your_models
107+
json_request = {
108+
'data' => {
109+
type: 'your_models',
110+
attributes: {
111+
name: 'Jane Doe'
112+
}
113+
}
114+
}
115+
post '/your_models', json_request.to_json, json_api_headers
116+
assert last_response.created?
117+
refute_nil YourModel.find_by(name: 'Jane Doe')
118+
end
119+
120+
private
121+
122+
def app
123+
Rails.application
124+
end
125+
end
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
begin
2+
require 'bundler/inline'
3+
require 'bundler'
4+
rescue LoadError => e
5+
STDERR.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
6+
raise e
7+
end
8+
9+
gemfile(true, ui: ENV['SILENT'] ? Bundler::UI::Silent.new : Bundler::UI::Shell.new) do
10+
source 'https://rubygems.org'
11+
12+
gem 'rails', require: false
13+
gem 'sqlite3', platform: :mri
14+
15+
gem 'activerecord-jdbcsqlite3-adapter',
16+
git: 'https://github.com/jruby/activerecord-jdbc-adapter',
17+
branch: 'rails-5',
18+
platform: :jruby
19+
20+
if ENV['JSONAPI_RESOURCES_PATH']
21+
gem 'jsonapi-resources', path: ENV['JSONAPI_RESOURCES_PATH'], require: false
22+
else
23+
gem 'jsonapi-resources', git: 'https://github.com/cerebris/jsonapi-resources', require: false
24+
end
25+
26+
end
27+
28+
# prepare active_record database
29+
require 'active_record'
30+
31+
class NullLogger < Logger
32+
def initialize(*_args)
33+
end
34+
35+
def add(*_args, &_block)
36+
end
37+
end
38+
39+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
40+
ActiveRecord::Base.logger = ENV['SILENT'] ? NullLogger.new : Logger.new(STDOUT)
41+
ActiveRecord::Migration.verbose = !ENV['SILENT']
42+
43+
ActiveRecord::Schema.define do
44+
# Add your schema here
45+
create_table :your_models, force: true do |t|
46+
t.string :name
47+
end
48+
end
49+
50+
# create models
51+
class YourModel < ActiveRecord::Base
52+
end
53+
54+
# prepare rails app
55+
require 'action_controller/railtie'
56+
# require 'action_view/railtie'
57+
require 'jsonapi-resources'
58+
59+
class ApplicationController < ActionController::Base
60+
end
61+
62+
# prepare jsonapi resources and controllers
63+
class YourModelsController < ApplicationController
64+
include JSONAPI::ActsAsResourceController
65+
end
66+
67+
class YourModelResource < JSONAPI::Resource
68+
attribute :name
69+
filter :name
70+
end
71+
72+
class TestApp < Rails::Application
73+
config.root = File.dirname(__FILE__)
74+
config.logger = ENV['SILENT'] ? NullLogger.new : Logger.new(STDOUT)
75+
Rails.logger = config.logger
76+
77+
secrets.secret_token = 'secret_token'
78+
secrets.secret_key_base = 'secret_key_base'
79+
80+
config.eager_load = false
81+
end
82+
83+
# initialize app
84+
Rails.application.initialize!
85+
86+
JSONAPI.configure do |config|
87+
config.json_key_format = :underscored_key
88+
config.route_format = :underscored_key
89+
end
90+
91+
# draw routes
92+
Rails.application.routes.draw do
93+
jsonapi_resources :your_models, only: [:index, :create]
94+
end
95+
96+
# prepare tests
97+
require 'minitest/autorun'
98+
require 'rack/test'
99+
100+
# Replace this with the code necessary to make your test fail.
101+
class BugTest < Minitest::Test
102+
include Rack::Test::Methods
103+
104+
def json_api_headers
105+
{'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
106+
end
107+
108+
def test_index_your_models
109+
record = YourModel.create! name: 'John Doe'
110+
get '/your_models', nil, json_api_headers
111+
assert last_response.ok?
112+
json_response = JSON.parse(last_response.body)
113+
refute_nil json_response['data']
114+
refute_empty json_response['data']
115+
refute_empty json_response['data'].first
116+
assert record.id.to_s, json_response['data'].first['id']
117+
assert 'your_models', json_response['data'].first['type']
118+
assert({'name' => 'John Doe'}, json_response['data'].first['attributes'])
119+
end
120+
121+
def test_create_your_models
122+
json_request = {
123+
'data' => {
124+
type: 'your_models',
125+
attributes: {
126+
name: 'Jane Doe'
127+
}
128+
}
129+
}
130+
post '/your_models', json_request.to_json, json_api_headers
131+
assert last_response.created?
132+
refute_nil YourModel.find_by(name: 'Jane Doe')
133+
end
134+
135+
private
136+
137+
def app
138+
Rails.application
139+
end
140+
end

lib/jsonapi-resources.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@
2424
require 'jsonapi/operation_result'
2525
require 'jsonapi/callbacks'
2626
require 'jsonapi/link_builder'
27+
require 'jsonapi/record_accessor'
28+
require 'jsonapi/active_record_accessor'

0 commit comments

Comments
 (0)