gris 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e96164641eef10ebe5b1b0ef9585128b9dab21a2
4
- data.tar.gz: 0766137f4a9db102e5395d5bc13c6a7cab92663b
3
+ metadata.gz: 6718fa8810cdc849424f62dfad2e12c47c3b9d38
4
+ data.tar.gz: 82de9f1d439386614bcf8a037382c0c8a40eee24
5
5
  SHA512:
6
- metadata.gz: 58888cb5cc8a00967780a977879657610f50b0a362f10a931340919fcc1d479cb71eaacc45de6989b77a8ef036f57a6cbededa8c6274aa9861b11f5f0abc7a93
7
- data.tar.gz: c6e15aaa11a99516c9e4353876b9bc2b5f82bbcfe4c16c52e59bf18fc286bb23fce78676edb4643e79e4457578baff98dff086b068faa933277e3307c65d6a6c
6
+ metadata.gz: d4afc70c3a4e8f2c74283e8f9b8b4edca4c417327774d0efe1fe4fc850f681d0ab955b3def9da585580165ecbd0b8ca71a5fe312a74079559f6f5d371fc0b60c
7
+ data.tar.gz: 4fa100baca239ebe31e2a2f79862c98d4fd83ded2c1136b1741122e8b6ff1b8285282471ba8d09a64290a5f99982a918969fec401551cc6f6e3e391694738a57
data/.rubocop_todo.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-05-20 22:54:33 -0400 using RuboCop version 0.31.0.
2
+ # on 2015-08-17 12:39:38 -0400 using RuboCop version 0.31.0.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
@@ -11,9 +11,9 @@
11
11
  Lint/EndAlignment:
12
12
  Enabled: false
13
13
 
14
- # Offense count: 5
14
+ # Offense count: 6
15
15
  Metrics/AbcSize:
16
- Max: 38
16
+ Max: 33
17
17
 
18
18
  # Offense count: 1
19
19
  # Configuration parameters: CountComments.
@@ -24,27 +24,22 @@ Metrics/ClassLength:
24
24
  Metrics/CyclomaticComplexity:
25
25
  Max: 11
26
26
 
27
- # Offense count: 67
27
+ # Offense count: 74
28
28
  # Configuration parameters: AllowURI, URISchemes.
29
29
  Metrics/LineLength:
30
30
  Max: 159
31
31
 
32
- # Offense count: 9
32
+ # Offense count: 11
33
33
  # Configuration parameters: CountComments.
34
34
  Metrics/MethodLength:
35
- Max: 27
35
+ Max: 33
36
36
 
37
37
  # Offense count: 16
38
38
  # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
39
39
  Style/CaseIndentation:
40
40
  Enabled: false
41
41
 
42
- # Offense count: 1
43
- # Cop supports --auto-correct.
44
- Style/ClosingParenthesisIndentation:
45
- Enabled: false
46
-
47
- # Offense count: 24
42
+ # Offense count: 27
48
43
  Style/Documentation:
49
44
  Enabled: false
50
45
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.4.3)
4
+ gris (0.4.4)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
6
  chronic (~> 0.10.0)
7
7
  dalli (~> 2.7)
@@ -40,21 +40,7 @@ module Gris
40
40
  say 'Appending links to RootPresenter.'
41
41
  insert_into_file path_to_root_presenter, after: "# Additional endpoint links\n" do
42
42
  text = "\n"
43
- text << " link :#{name_tableize} do |opts|\n"
44
- text << " {\n"
45
- text << ' href: "#{base_url(opts)}/'
46
- text << "#{name_tableize}{?page,size}\",\n"
47
- text << " templated: true\n"
48
- text << " }\n"
49
- text << " end\n"
50
- text << "\n"
51
- text << " link :#{name_underscore} do |opts|\n"
52
- text << " {\n"
53
- text << ' href: "#{base_url(opts)}/'
54
- text << "#{name_tableize}/{id}\",\n"
55
- text << " templated: true\n"
56
- text << " }\n"
57
- text << " end\n"
43
+ text << " resource_links :#{name_underscore}\n"
58
44
  text
59
45
  end
60
46
  end
@@ -3,8 +3,7 @@ module <%= name.classify %>Presenter
3
3
 
4
4
  property :id, writeable: false, type: String, desc: '<%= name.classify %> unique ID.'
5
5
 
6
- link :self do |opts|
7
- request = Grape::Request.new(opts[:env])
8
- "#{request.base_url}/<%= name.tableize %>/#{id}"
6
+ link :self do
7
+ "#{Gris::Identity.base_url}/<%= name.tableize %>/#{id}"
9
8
  end
10
9
  end
@@ -32,9 +32,9 @@ describe <%= name.classify.pluralize %>Endpoint do
32
32
 
33
33
  it 'returns pagination' do
34
34
  response = client.<%= name.tableize %>(size: 2, page: 2)
35
- expect(response._links.next._url).to eq 'http://example.org/<%= name.tableize %>?page=3&size=2'
36
- expect(response._links.prev._url).to eq 'http://example.org/<%= name.tableize %>?page=1&size=2'
37
- expect(response._links.self._url).to eq 'http://example.org/<%= name.tableize %>?page=2&size=2'
35
+ expect(response._links.next._url).to eq "#{Gris::Identity.base_url}/<%= name.tableize %>?page=3&size=2"
36
+ expect(response._links.prev._url).to eq "#{Gris::Identity.base_url}/<%= name.tableize %>?page=1&size=2"
37
+ expect(response._links.self._url).to eq "#{Gris::Identity.base_url}/<%= name.tableize %>?page=2&size=2"
38
38
  end
39
39
 
40
40
  it 'returns all unique ids' do
@@ -1,20 +1,10 @@
1
1
  module RootPresenter
2
- include Gris::Presenter
2
+ include Gris::RootPresenter
3
3
 
4
- link :self do |opts|
5
- "#{base_url(opts)}"
6
- end
7
-
8
- link :health do |opts|
9
- { href: "#{base_url(opts)}/health" }
4
+ link :self do
5
+ Gris::Identity.base_url
10
6
  end
11
7
 
12
8
  # Additional endpoint links
13
-
14
- private
15
-
16
- def base_url(opts)
17
- request = Grape::Request.new(opts[:env])
18
- request.base_url
19
- end
9
+ endpoint_link :health
20
10
  end
@@ -24,11 +24,6 @@ module Gris
24
24
 
25
25
  private
26
26
 
27
- def request_url(opts)
28
- request = Grape::Request.new(opts[:env])
29
- "#{request.base_url}#{opts[:env]['PATH_INFO']}"
30
- end
31
-
32
27
  # replace the page parameter in the query string
33
28
  def query_string_for_page(page, opts)
34
29
  qs = Rack::Utils.parse_nested_query(opts[:env]['QUERY_STRING'])
@@ -9,6 +9,13 @@ module Gris
9
9
  include Roar::JSON::HAL
10
10
  include Roar::Hypermedia
11
11
  include Grape::Roar::Representer
12
+
13
+ private
14
+
15
+ def request_url(opts)
16
+ request = Grape::Request.new(opts[:env])
17
+ "#{request.base_url}#{opts[:env]['PATH_INFO']}"
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -0,0 +1,43 @@
1
+ module Gris
2
+ module RootPresenter
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include Gris::Presenter
6
+
7
+ def self.resource_links(name, args = [])
8
+ args += %w(page size)
9
+ link name.to_s.pluralize do
10
+ link = {
11
+ href: "#{Gris::Identity.base_url}/#{name.to_s.pluralize}#{format_args(args)}",
12
+ templated: true
13
+ }
14
+ link
15
+ end
16
+ link name do
17
+ {
18
+ href: "#{Gris::Identity.base_url}/#{name.to_s.pluralize}/{id}",
19
+ templated: true
20
+ }
21
+ end
22
+ end
23
+
24
+ def self.endpoint_link(name, args = [])
25
+ link name do
26
+ link = {
27
+ href: "#{Gris::Identity.base_url}/#{name}#{format_args(args)}"
28
+ }
29
+ link[:templated] = true unless args.blank?
30
+ link
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def format_args(args = [])
37
+ return unless args.any?
38
+ "{?#{args.join(',')}}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/gris/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
 
4
4
  class Version
5
5
  class << self
data/lib/gris.rb CHANGED
@@ -14,13 +14,14 @@ require 'hashie-forbidden_attributes'
14
14
  require 'gris/application'
15
15
  require 'gris/caching'
16
16
  require 'gris/deprecations'
17
- require 'gris/grape_extensions/crud_helpers'
18
- require 'gris/grape_extensions/error_helpers'
19
17
  require 'gris/grape_extensions/authentication_helpers'
18
+ require 'gris/grape_extensions/crud_helpers'
20
19
  require 'gris/grape_extensions/date_time_helpers'
20
+ require 'gris/grape_extensions/error_helpers'
21
21
  require 'gris/identity'
22
22
  require 'gris/middleware/health'
23
23
  require 'gris/output_formatters/paginated_presenter'
24
+ require 'gris/output_formatters/root_presenter'
24
25
  require 'gris/output_formatters/presenter'
25
26
  require 'gris/setup'
26
27
  require 'gris/version'
@@ -72,8 +72,7 @@ describe Gris::Generators::ApiGenerator do
72
72
  it 'adds links to RootPresenter' do
73
73
  expected_root_presenter_file = File.join(generator_tmp_directory, 'app/presenters/root_presenter.rb')
74
74
  presenter_file = File.read(expected_root_presenter_file)
75
- expect(presenter_file).to match(/link :article do |opts|/)
76
- expect(presenter_file).to match(/link :articles do |opts|/)
75
+ expect(presenter_file).to match(/resource_links :article/)
77
76
  end
78
77
  end
79
78
 
@@ -98,8 +98,16 @@ describe Gris::Generators::ScaffoldGenerator do
98
98
  expect(root_presenter_file).to match(/module RootPresenter/)
99
99
  end
100
100
 
101
- it 'includes Gris::Presenter' do
102
- expect(RootPresenter).to include(Gris::Presenter)
101
+ it 'includes Gris::RootPresenter' do
102
+ expect(RootPresenter).to include(Gris::RootPresenter)
103
+ end
104
+
105
+ it 'includes link to self' do
106
+ expect(root_presenter_file).to match(/link :self do/)
107
+ end
108
+
109
+ it 'includes link to health middleware' do
110
+ expect(root_presenter_file).to match(/endpoint_link :health/)
103
111
  end
104
112
  end
105
113
 
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'faraday'
3
+
4
+ describe 'application error response' do
5
+ include_context 'with a generated app'
6
+
7
+ it 'returns a json formatted message' do
8
+ request = Faraday.get "http://localhost:#{app_port}/bogus"
9
+ response = JSON.parse request.body
10
+ expect(request.status).to eq 404
11
+ expect(response['code']).to eq 404
12
+ expect(response['message']).to eq ['Not Found']
13
+ end
14
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'gris'
3
+ require 'rack/test'
4
+
5
+ describe Gris::RootPresenter do
6
+ include Rack::Test::Methods
7
+
8
+ module RootPresenter
9
+ include Gris::RootPresenter
10
+ resource_links :painter, [:sort]
11
+ endpoint_link :painting, [:account_id]
12
+ resource_links :sculptor
13
+ endpoint_link :sculpture
14
+ end
15
+
16
+ class ApplicationEndpoint < Grape::API
17
+ format :json
18
+ formatter :json, Grape::Formatter::Roar
19
+ get do
20
+ present self, with: RootPresenter
21
+ end
22
+ end
23
+
24
+ def app
25
+ ApplicationEndpoint.new
26
+ end
27
+
28
+ before do
29
+ get '/'
30
+ @result = Hashie::Mash.new JSON.parse(last_response.body)
31
+ end
32
+
33
+ it 'returns uri template for resource_links with additional arguments' do
34
+ expect(@result['_links']['painters']['href']).to eq "#{Gris::Identity.base_url}/painters{?sort,page,size}"
35
+ expect(@result['_links']['painters']['templated']).to eq true
36
+ expect(@result['_links']['painter']['href']).to eq "#{Gris::Identity.base_url}/painters/{id}"
37
+ expect(@result['_links']['painter']['templated']).to eq true
38
+ end
39
+
40
+ it 'returns uri template for resource_links without additional arguments' do
41
+ expect(@result['_links']['sculptors']['href']).to eq "#{Gris::Identity.base_url}/sculptors{?page,size}"
42
+ expect(@result['_links']['sculptors']['templated']).to eq true
43
+ expect(@result['_links']['sculptor']['href']).to eq "#{Gris::Identity.base_url}/sculptors/{id}"
44
+ expect(@result['_links']['sculptor']['templated']).to eq true
45
+ end
46
+
47
+ it 'returns uri template for endpoint_link with additional arguments' do
48
+ expect(@result['_links']['painting']['href']).to eq "#{Gris::Identity.base_url}/painting{?account_id}"
49
+ expect(@result['_links']['painting']['templated']).to eq true
50
+ end
51
+
52
+ it 'returns uri template for endpoint_link without additional arguments' do
53
+ expect(@result['_links']['sculpture']['href']).to eq "#{Gris::Identity.base_url}/sculpture"
54
+ expect(@result['_links']['sculpture']['templated']).to be_nil
55
+ end
56
+ end
@@ -16,6 +16,7 @@ shared_context 'with a generated app' do
16
16
  end
17
17
 
18
18
  def prepare_app
19
+ use_local_gris
19
20
  Bundler.with_clean_env do
20
21
  project = ChildProcess.build('bundle', 'install')
21
22
  project.io.inherit!
@@ -31,6 +32,14 @@ shared_context 'with a generated app' do
31
32
  end
32
33
  end
33
34
 
35
+ def use_local_gris
36
+ IO.write(
37
+ "#{app_name}/Gemfile", File.open("#{app_name}/Gemfile") do |f|
38
+ f.read.gsub(/gem 'gris'/, "gem 'gris', path: '../'")
39
+ end
40
+ )
41
+ end
42
+
34
43
  def start_app
35
44
  @app = ChildProcess.build('bundle', 'exec', 'rackup')
36
45
  @app.environment['PERMITTED_TOKENS'] = 'replace-me'
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.4.3
4
+ version: 0.4.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-08-15 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -376,6 +376,7 @@ files:
376
376
  - lib/gris/middleware/health.rb
377
377
  - lib/gris/output_formatters/paginated_presenter.rb
378
378
  - lib/gris/output_formatters/presenter.rb
379
+ - lib/gris/output_formatters/root_presenter.rb
379
380
  - lib/gris/rspec_extensions/active_record_shared_connection.rb
380
381
  - lib/gris/rspec_extensions/response_helpers.rb
381
382
  - lib/gris/setup.rb
@@ -392,7 +393,9 @@ files:
392
393
  - spec/grape_extensions/date_time_helpers_spec.rb
393
394
  - spec/grape_extensions/error_helpers_spec.rb
394
395
  - spec/identity_spec.rb
396
+ - spec/integration/application_error_response_spec.rb
395
397
  - spec/integration/token_authentication_spec.rb
398
+ - spec/output_formatters/root_presenter_spec.rb
396
399
  - spec/spec_helper.rb
397
400
  - spec/support/caching_helper.rb
398
401
  - spec/support/integration_setup.rb
@@ -421,7 +424,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
421
424
  version: '0'
422
425
  requirements: []
423
426
  rubyforge_project:
424
- rubygems_version: 2.4.5
427
+ rubygems_version: 2.4.8
425
428
  signing_key:
426
429
  specification_version: 4
427
430
  summary: A simple api microservice generator framework.
@@ -436,7 +439,9 @@ test_files:
436
439
  - spec/grape_extensions/date_time_helpers_spec.rb
437
440
  - spec/grape_extensions/error_helpers_spec.rb
438
441
  - spec/identity_spec.rb
442
+ - spec/integration/application_error_response_spec.rb
439
443
  - spec/integration/token_authentication_spec.rb
444
+ - spec/output_formatters/root_presenter_spec.rb
440
445
  - spec/spec_helper.rb
441
446
  - spec/support/caching_helper.rb
442
447
  - spec/support/integration_setup.rb