gris 0.0.3 → 0.0.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: 8e98e164c3934c02af0e32ffbee5f545cd58c7d8
4
- data.tar.gz: 6260220164c8fbf9e56263fa810cb11940533904
3
+ metadata.gz: 04e8cf11f998e3b614460e921507e3b6c90fa9ec
4
+ data.tar.gz: ffbc14978f65bafcb8b597bde0a407f7fe7a796a
5
5
  SHA512:
6
- metadata.gz: bc2196d45fc7efb6850c5c70bdb8797d9ee4a8979df5d48590fae7e0310c80a2f244b41827b6eca8ffc3f35c0b55791fd967b75eb1c0fa4c9f40999dce38fa15
7
- data.tar.gz: ad0394f1f83f04b373f3b955849c5111290b968658563725c91b6b6b16d89d44516b909f887192864ef28829374091db37f89ec914625e3dd45f1cf85fbc5486
6
+ metadata.gz: 3a304524e59586cbd9d6a52ed4d2b104b1aed247199c73f539ce09057656c5f099129b23abbb5ccbf30c6215c3ad8ce8f376306d715d4fca3b266c4d41cd189a
7
+ data.tar.gz: 2119c505cb16a7ae8f46e6a5e4425fb625d3b994d192b374d9f36a7f49736541979400887be9c8f42e945d9ab0fc878cda79886238d7846e0a2d9d5df4d40ac7
data/.rubocop_todo.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-02-01 07:58:32 -0500 using RuboCop version 0.28.0.
2
+ # on 2015-02-08 23:29:14 -0500 using RuboCop version 0.28.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
@@ -10,13 +10,9 @@
10
10
  Lint/EndAlignment:
11
11
  Enabled: false
12
12
 
13
- # Offense count: 1
14
- Lint/LiteralInInterpolation:
15
- Enabled: false
16
-
17
- # Offense count: 4
13
+ # Offense count: 5
18
14
  Metrics/AbcSize:
19
- Max: 40
15
+ Max: 38
20
16
 
21
17
  # Offense count: 1
22
18
  # Configuration parameters: CountComments.
@@ -27,26 +23,26 @@ Metrics/ClassLength:
27
23
  Metrics/CyclomaticComplexity:
28
24
  Max: 11
29
25
 
30
- # Offense count: 34
26
+ # Offense count: 66
31
27
  # Configuration parameters: AllowURI, URISchemes.
32
28
  Metrics/LineLength:
33
29
  Max: 159
34
30
 
35
- # Offense count: 6
31
+ # Offense count: 8
36
32
  # Configuration parameters: CountComments.
37
33
  Metrics/MethodLength:
38
- Max: 29
34
+ Max: 27
39
35
 
40
36
  # Offense count: 16
41
37
  # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
42
38
  Style/CaseIndentation:
43
39
  Enabled: false
44
40
 
45
- # Offense count: 21
41
+ # Offense count: 22
46
42
  Style/Documentation:
47
43
  Enabled: false
48
44
 
49
- # Offense count: 3
45
+ # Offense count: 1
50
46
  Style/DoubleNegation:
51
47
  Enabled: false
52
48
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.0.3)
4
+ gris (0.0.4)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
6
  dotenv (~> 1.0.2, >= 1.0.2)
7
7
  git (~> 1.2, >= 1.2.8)
@@ -19,9 +19,17 @@ module Gris
19
19
  '.'
20
20
  end
21
21
 
22
+ def path_to_application_endpoint
23
+ "#{output_directory}/app/endpoints/application_endpoint.rb"
24
+ end
25
+
26
+ def path_to_root_presenter
27
+ "#{output_directory}/app/presenters/root_presenter.rb"
28
+ end
29
+
22
30
  def append_endpoint_to_application_endpoint
23
31
  say 'Mounting new endpoint on ApplicationEndpoint.'
24
- insert_into_file './app/endpoints/application_endpoint.rb', after: "# Additional mounted endpoints\n" do
32
+ insert_into_file path_to_application_endpoint, after: "# Additional mounted endpoints\n" do
25
33
  text = " mount #{name.classify.pluralize}Endpoint\n"
26
34
  text
27
35
  end
@@ -29,7 +37,7 @@ module Gris
29
37
 
30
38
  def append_endpoint_links_to_root_presenter
31
39
  say 'Appending links to RootPresenter.'
32
- insert_into_file './app/presenters/root_presenter.rb', after: "# Additional endpoint links\n" do
40
+ insert_into_file path_to_root_presenter, after: "# Additional endpoint links\n" do
33
41
  text = "\n"
34
42
  text << " link :#{name_tableize} do |opts|\n"
35
43
  text << " {\n"
data/lib/gris/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -7,6 +7,12 @@ describe Gris::Generators::ApiGenerator do
7
7
  let(:api_name) { 'foo' }
8
8
 
9
9
  before do
10
+ endpoints_directory_path = "#{generator_tmp_directory}/app/endpoints"
11
+ presenters_directory_path = "#{generator_tmp_directory}/app/presenters"
12
+ FileUtils.mkdir_p endpoints_directory_path
13
+ FileUtils.mkdir_p presenters_directory_path
14
+ File.open("#{endpoints_directory_path}/application_endpoint.rb", 'w+') { |file| file.write("# Additional mounted endpoints\n") }
15
+ File.open("#{presenters_directory_path}/root_presenter.rb", 'w+') { |file| file.write("# Additional endpoint links\n") }
10
16
  Gris::CLI::Base.new.generate('api', api_name)
11
17
  end
12
18
 
@@ -52,6 +58,19 @@ describe Gris::Generators::ApiGenerator do
52
58
  require "./#{presenter_file}"
53
59
  expect(FoosPresenter).to include(Gris::PaginatedPresenter)
54
60
  end
61
+
62
+ it 'mounts new endpoint in ApplicationEndpoint' do
63
+ expected_endpoint_file = File.join(generator_tmp_directory, 'app/endpoints/application_endpoint.rb')
64
+ endpoint_file = File.read(expected_endpoint_file)
65
+ expect(endpoint_file).to match(/mount FoosEndpoint/)
66
+ end
67
+
68
+ it 'adds links to RootPresenter' do
69
+ expected_root_presenter_file = File.join(generator_tmp_directory, 'app/presenters/root_presenter.rb')
70
+ presenter_file = File.read(expected_root_presenter_file)
71
+ expect(presenter_file).to match(/link :foo do |opts|/)
72
+ expect(presenter_file).to match(/link :foos do |opts|/)
73
+ end
55
74
  end
56
75
 
57
76
  describe 'spec' do
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gris::AuthenticationHelpers do
4
+ context 'without permitted token' do
5
+ before(:each) do
6
+ stub_const 'ENV', 'PERMITTED_TOKENS' => %w(my-token another-token)
7
+ @helper = SpecApiAuthHelper.new
8
+ end
9
+
10
+ context '#token_authentication!' do
11
+ context 'without matching tokens' do
12
+ it 'returns a 401 Forbidden error' do
13
+ allow(@helper).to receive(:params).and_return(token: nil)
14
+ allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
15
+ @helper.token_authentication!
16
+ expect(@helper.message).to eq(message: 'Forbidden', status: 401)
17
+ end
18
+ end
19
+ context 'with included params token' do
20
+ it 'returns nil' do
21
+ allow(@helper).to receive(:params).and_return(token: 'my-token')
22
+ allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
23
+ expect(@helper.token_authentication!).to be_nil
24
+ end
25
+ end
26
+ context 'with included request header token' do
27
+ it 'returns nil' do
28
+ allow(@helper).to receive(:params).and_return(token: nil)
29
+ allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => 'my-token')
30
+ expect(@helper.token_authentication!).to be_nil
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'gris/grape_extensions/error_helpers'
3
2
 
4
3
  describe Gris::ErrorHelpers do
5
4
  before do
@@ -0,0 +1,15 @@
1
+ class SpecApiAuthHelper
2
+ include Gris::AuthenticationHelpers
3
+ include Gris::ErrorHelpers
4
+
5
+ attr_accessor :params
6
+ attr_accessor :request
7
+
8
+ attr_accessor :message
9
+ attr_accessor :thrown
10
+
11
+ def throw(thrown, message)
12
+ @message = message
13
+ @thrown = thrown
14
+ end
15
+ end
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.0.3
4
+ version: 0.0.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-02-08 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -393,10 +393,12 @@ files:
393
393
  - spec/generators/api_generator_spec.rb
394
394
  - spec/generators/migration_generator_spec.rb
395
395
  - spec/generators/scaffold_generator_spec.rb
396
+ - spec/grape_extensions/authentication_helpers_spec.rb
396
397
  - spec/grape_extensions/crud_helpers_spec.rb
397
398
  - spec/grape_extensions/error_helpers_spec.rb
398
399
  - spec/identity_spec.rb
399
400
  - spec/spec_helper.rb
401
+ - spec/support/spec_api_auth_helper.rb
400
402
  - spec/support/spec_api_error_helper.rb
401
403
  - spec/support/spec_generators_helper.rb
402
404
  - spec/version_spec.rb
@@ -428,10 +430,12 @@ test_files:
428
430
  - spec/generators/api_generator_spec.rb
429
431
  - spec/generators/migration_generator_spec.rb
430
432
  - spec/generators/scaffold_generator_spec.rb
433
+ - spec/grape_extensions/authentication_helpers_spec.rb
431
434
  - spec/grape_extensions/crud_helpers_spec.rb
432
435
  - spec/grape_extensions/error_helpers_spec.rb
433
436
  - spec/identity_spec.rb
434
437
  - spec/spec_helper.rb
438
+ - spec/support/spec_api_auth_helper.rb
435
439
  - spec/support/spec_api_error_helper.rb
436
440
  - spec/support/spec_generators_helper.rb
437
441
  - spec/version_spec.rb