gris 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4098bdc1e372dca7d74e81b22f6ecc30c29983c
4
- data.tar.gz: efddb7d75fc120b81c95eada659121ebb0a8ddf4
3
+ metadata.gz: 7903911cba8da7b598dd6b4917a79a47b636b7b5
4
+ data.tar.gz: 8d7cb5ded5b95afd3a0862688c5a002feeb32d40
5
5
  SHA512:
6
- metadata.gz: d0f9914e1967856aec2e8033ebca2e4c41bd3c8d9a74f704f14d63320bdae1a0fbaf43b0f8a7e92cafa7aec5a7ffe92cc7553430993ab94ae1c0cc8086ad8b9e
7
- data.tar.gz: 6ab40f2d5bc61ba52138002f2f694159e0e223c6f06abc1861c1ea2379b5f70aa67442c01bde92e81061d83a691ea1216192070a946f58f23324394f612526d2
6
+ metadata.gz: 3c04c1f98d3e9c1467507e182d317c89a7456a27f2f542d8a0f297ccd30d45bfa5090e5dfa3cfa14796a4693dc526cedc284c21982ec39d12bc6ca39797a9c67
7
+ data.tar.gz: ef360e0a06a2b4ece6de403e17640e3fd641a676221512597d67418e1233db6d3608d1b848d28d5a197e76dcfa75fe50b611f8a5145df1fd6af60cd5a13dd2fe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.2.3)
4
+ gris (0.2.4)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
6
  chronic (~> 0.10.0)
7
7
  dalli (~> 2.7)
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe <%= name.classify.pluralize %>Endpoint do
4
4
  include Rack::Test::Methods
5
- include_context 'with a running app'
5
+ include_context 'with a running app and client'
6
6
 
7
7
  context '<%= name.tableize %>' do
8
8
  before(:each) do
@@ -12,59 +12,54 @@ describe <%= name.classify.pluralize %>Endpoint do
12
12
  end
13
13
 
14
14
  it 'returns 10 <%= name.tableize %> by default' do
15
- get '/<%= name.tableize %>'
16
- expect(response_code).to eq 200
17
- expect_embedded_results_count_of 10, <%= name.classify %>
15
+ expect(client.<%= name.tableize %>.count).to eq 10
18
16
  end
19
17
 
20
18
  it 'returns 2 <%= name.tableize %>' do
21
- get '/<%= name.tableize %>?size=2'
22
- expect(response_code).to eq 200
23
- expect_embedded_results_count_of 2, <%= name.classify %>
19
+ expect(client.<%= name.tableize %>(size: 2).count).to eq 2
24
20
  end
25
21
 
26
22
  it 'returns pagination' do
27
- get '/<%= name.tableize %>?size=2&page=2'
28
- expect(response_code).to eq 200
29
- expect(link_to_next[:href]).to eq 'http://example.org/<%= name.tableize %>?page=3&size=2'
30
- expect(link_to_previous[:href]).to eq 'http://example.org/<%= name.tableize %>?page=1&size=2'
31
- expect(link_to_self[:href]).to eq 'http://example.org/<%= name.tableize %>?page=2&size=2'
23
+ response = client.<%= name.tableize %>(size: 2, page: 2)
24
+ expect(response._links.next._url).to eq 'http://example.org/<%= name.tableize %>?page=3&size=2'
25
+ expect(response._links.prev._url).to eq 'http://example.org/<%= name.tableize %>?page=1&size=2'
26
+ expect(response._links.self._url).to eq 'http://example.org/<%= name.tableize %>?page=2&size=2'
32
27
  end
33
28
 
34
29
  it 'returns all unique ids' do
35
- get '/<%= name.tableize %>'
36
- expect(response_code).to eq 200
37
- expect(embedded_results(<%= name.classify %>).map { |s| s[:id] }.uniq.count).to eq 10
30
+ <%= name.tableize %> = client.<%= name.tableize %>
31
+ expect(<%= name.tableize %>.map(&:id).uniq.count).to eq 10
38
32
  end
39
33
  end
40
34
 
41
35
  context '<%= name.underscore %>' do
42
- let(:<%= name.underscore %>1) { Fabricate(:<%= name.underscore %>) }
36
+ let(:<%= name.underscore %>_details) do
37
+ {
38
+ replace_me: 'braque is not a talented artist'
39
+ }
40
+ end
41
+ let(:<%= name.underscore %>1) { Fabricate(:<%= name.underscore %>, attributes: <%= name.underscore %>_details) }
43
42
 
44
43
  it 'creates a <%= name.underscore %>' do
45
- post '/<%= name.tableize %>', <%= name.underscore %>: { replace: 'REPLACE ME' }
46
- expect(response_code).to eq 201
47
- expect(result[:id]).to_not be_blank
44
+ <%= name.underscore %> = client.<%= name.tableize %>._post(<%= name.underscore %>: <%= name.underscore %>_details)
45
+ expect(<%= name.underscore %>.replace_me).to eq <%= name.underscore %>_details[:replace_me]
48
46
  end
49
47
 
50
48
  it 'returns a <%= name.underscore %>' do
51
- get "/<%= name.tableize %>/#{<%= name.underscore %>1.id}"
52
- expect(response_code).to eq 200
53
- expect(result[:id]).to eq <%= name.underscore %>1.id
54
- expect(link_to_self[:href]).to eq "http://example.org/<%= name.tableize %>/#{<%= name.underscore %>1.id}"
49
+ <%= name.underscore %> = client.<%= name.underscore %>(id: <%= name.underscore %>1.id)
50
+ expect(<%= name.underscore %>.id).to eq <%= name.underscore %>1.id
51
+ expect(<%= name.underscore %>.replace_me).to eq <%= name.underscore %>_details[:replace_me]
55
52
  end
56
53
 
57
54
  it 'updates a <%= name.underscore %>' do
58
- patch "/<%= name.tableize %>/#{<%= name.underscore %>1.id}", <%= name.underscore %>: { replace: 'REPLACE ME' }
59
- expect(response_code).to eq 200
60
- expect(result[:id]).to eq <%= name.underscore %>1.id
55
+ <%= name.underscore %> = client.<%= name.underscore %>(id: <%= name.underscore %>1.id)._patch(<%= name.underscore %>: { replace_me: 'braque is a talented artist' })
56
+ expect(<%= name.underscore %>.id).to eq <%= name.underscore %>1.id
57
+ expect(<%= name.underscore %>.replace_me).to eq 'braque is a talented artist'
61
58
  end
62
59
 
63
60
  it 'deletes a <%= name.underscore %>' do
64
- expect_any_instance_of(<%= name.classify %>).to receive(:destroy)
65
- delete "/<%= name.tableize %>/#{<%= name.underscore %>1.id}"
66
- expect(response_code).to eq 200
67
- expect(result[:id]).to eq <%= name.underscore %>1.id
61
+ <%= name.underscore %> = client.<%= name.underscore %>(id: <%= name.underscore %>1.id)._delete
62
+ expect(<%= name.underscore %>.id).to eq <%= name.underscore %>1.id
68
63
  end
69
64
  end
70
65
  end
@@ -1 +1 @@
1
- web: bundle exec puma -p $PORT -e $RACK_ENV -t 0:5
1
+ web: bundle exec puma -C config/puma.rb
@@ -1,8 +1,8 @@
1
- require 'erb'
2
1
  if ENV['DATABASE_URL']
3
2
  ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
4
3
  else
5
4
  db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Gris.env]
6
5
  ActiveRecord::Base.establish_connection(db)
7
6
  end
8
- ActiveRecord::Base.include_root_in_json = false
7
+ # prevent deprecation warning
8
+ ActiveRecord::Base.raise_in_transactional_callbacks = true
@@ -0,0 +1,6 @@
1
+ workers Integer(ENV['WEB_CONCURRENCY'] || 2)
2
+ threads_count = Integer(ENV['MAX_THREADS'] || 5)
3
+ threads threads_count, threads_count
4
+
5
+ port ENV['PORT'] || 3000
6
+ environment ENV['RACK_ENV'] || 'development'
@@ -1,10 +1,8 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
2
 
3
- require 'webmock/rspec'
4
- require 'rack/test'
5
- require 'gris/rspec_extensions/response_helpers'
6
-
7
3
  require File.expand_path('../../config/application', __FILE__)
4
+ require 'gris/rspec_extensions/response_helpers'
5
+ require 'gris/rspec_extensions/active_record_shared_connection'
8
6
 
9
7
  # Requires supporting ruby files with custom matchers and macros, etc,
10
8
  # in spec/support/ and its subdirectories.
@@ -17,11 +15,10 @@ RSpec.configure do |config|
17
15
 
18
16
  config.before(:suite) do
19
17
  ActiveRecord::Migration.maintain_test_schema!
20
- DatabaseCleaner.strategy = :transaction
21
- DatabaseCleaner.clean_with(:truncation)
18
+ DatabaseCleaner.strategy = :truncation
22
19
  end
23
20
 
24
- config.before(:each) do
21
+ config.before do
25
22
  DatabaseCleaner.clean
26
23
  end
27
24
  end
@@ -0,0 +1,27 @@
1
+ shared_context 'with a running app' do
2
+ let(:app) { Rack::Builder.parse_file('config.ru').first }
3
+ end
4
+
5
+ shared_context 'with token authorization' do
6
+ before(:each) do
7
+ permitted_token = ENV['PERMITTED_TOKENS'].split(',').first if ENV['PERMITTED_TOKENS']
8
+ header 'Http-Authorization', permitted_token
9
+ end
10
+ let(:permitted_token) { ENV['PERMITTED_TOKENS'].split(',').first }
11
+ end
12
+
13
+ shared_context 'with a running app and client' do
14
+ include_context 'with a running app'
15
+ include_context 'with token authorization'
16
+
17
+ let(:client) do
18
+ Hyperclient.new('http://example.org/') do |client|
19
+ client.headers['Http-Authorization'] = permitted_token
20
+ client.connection(default: false) do |conn|
21
+ conn.request :hal_json
22
+ conn.response :json
23
+ conn.use Faraday::Adapter::Rack, app
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ class Base
3
+ mattr_accessor :shared_connection
4
+ self.shared_connection = nil
5
+
6
+ def self.connection
7
+ shared_connection || retrieve_connection
8
+ end
9
+ end
10
+ end
11
+
12
+ # Force all threads to share the same connection.
13
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
data/lib/gris/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
 
4
4
  class Version
5
5
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -375,10 +375,11 @@ files:
375
375
  - lib/gris/generators/templates/scaffold/config/boot.rb
376
376
  - lib/gris/generators/templates/scaffold/config/database.yml.tt
377
377
  - lib/gris/generators/templates/scaffold/config/initializers/active_record.rb
378
+ - lib/gris/generators/templates/scaffold/config/puma.rb
378
379
  - lib/gris/generators/templates/scaffold/db/schema.rb
379
380
  - lib/gris/generators/templates/scaffold/spec/endpoints/cors_spec.rb.tt
380
381
  - lib/gris/generators/templates/scaffold/spec/spec_helper.rb
381
- - lib/gris/generators/templates/scaffold/spec/support/app_helper.rb.tt
382
+ - lib/gris/generators/templates/scaffold/spec/support/app_helper.rb
382
383
  - lib/gris/grape_extensions/authentication_helpers.rb
383
384
  - lib/gris/grape_extensions/crud_helpers.rb
384
385
  - lib/gris/grape_extensions/date_time_helpers.rb
@@ -389,6 +390,7 @@ files:
389
390
  - lib/gris/output_formatters/presenter.rb
390
391
  - lib/gris/public/errors/404.html
391
392
  - lib/gris/public/errors/500.html
393
+ - lib/gris/rspec_extensions/active_record_shared_connection.rb
392
394
  - lib/gris/rspec_extensions/response_helpers.rb
393
395
  - lib/gris/setup.rb
394
396
  - lib/gris/version.rb
@@ -1,10 +0,0 @@
1
- shared_context 'with a running app' do
2
- let(:app) { <%= app_name.classify %>::Application.instance }
3
- end
4
-
5
- shared_context 'with token authorization' do
6
- before(:each) do
7
- permitted_token = ENV['PERMITTED_TOKENS'].split(',').first if ENV['PERMITTED_TOKENS']
8
- header 'Http-Authorization', permitted_token
9
- end
10
- end