gris 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gris/generators/templates/api/spec/endpoints/%name_tableize%_endpoint_spec.rb.tt +25 -30
- data/lib/gris/generators/templates/scaffold/Procfile +1 -1
- data/lib/gris/generators/templates/scaffold/config/initializers/active_record.rb +2 -2
- data/lib/gris/generators/templates/scaffold/config/puma.rb +6 -0
- data/lib/gris/generators/templates/scaffold/spec/spec_helper.rb +4 -7
- data/lib/gris/generators/templates/scaffold/spec/support/app_helper.rb +27 -0
- data/lib/gris/rspec_extensions/active_record_shared_connection.rb +13 -0
- data/lib/gris/version.rb +1 -1
- metadata +5 -3
- data/lib/gris/generators/templates/scaffold/spec/support/app_helper.rb.tt +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7903911cba8da7b598dd6b4917a79a47b636b7b5
|
4
|
+
data.tar.gz: 8d7cb5ded5b95afd3a0862688c5a002feeb32d40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c04c1f98d3e9c1467507e182d317c89a7456a27f2f542d8a0f297ccd30d45bfa5090e5dfa3cfa14796a4693dc526cedc284c21982ec39d12bc6ca39797a9c67
|
7
|
+
data.tar.gz: ef360e0a06a2b4ece6de403e17640e3fd641a676221512597d67418e1233db6d3608d1b848d28d5a197e76dcfa75fe50b611f8a5145df1fd6af60cd5a13dd2fe
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
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
|
-
|
36
|
-
expect(
|
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 %>
|
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
|
-
|
46
|
-
expect(
|
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
|
-
|
52
|
-
expect(
|
53
|
-
expect(
|
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
|
-
|
59
|
-
expect(
|
60
|
-
expect(
|
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
|
-
|
65
|
-
|
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 -
|
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
|
-
|
7
|
+
# prevent deprecation warning
|
8
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
@@ -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 = :
|
21
|
-
DatabaseCleaner.clean_with(:truncation)
|
18
|
+
DatabaseCleaner.strategy = :truncation
|
22
19
|
end
|
23
20
|
|
24
|
-
config.before
|
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
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.
|
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-
|
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
|
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
|