service_template 0.5.0 → 0.5.1

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: 02a8715ac1b0820f58fd3e031d1b293903eb2e7b
4
- data.tar.gz: 6b83d3dd52b80b7b7abb0d3c0429f5e8537be154
3
+ metadata.gz: adceefb25095efc1575da9e0c934596bbb558743
4
+ data.tar.gz: e3c0a438180a4c72ef13b774e7aeb404b8b7ed30
5
5
  SHA512:
6
- metadata.gz: 3ac128223d3b4c1e455c6e90d4d6d74969a47ab409e2b4add409713e4206fd8ee95f11762d94738d17abae2809a504a54fb1537ea64cc6cc7b54c1a1c1e29e20
7
- data.tar.gz: 98a4fb6716da38f790d051dc8447798c4fcb25941901a821c40154c8f7edb5feefcba6405a11813a69df9656e5b53dd4ee39aef14fc55d7fcb5a102fd3461f4f
6
+ metadata.gz: 1f5cbe4a57c2713c54ed6f4a85eec69dbee387d367d880ff3227e112d6b17051f4fdd7e00dff4e3c6926bf6b1b6931b8c45b737f4e006d277ed6a82cc2129c7b
7
+ data.tar.gz: e649aed4b9c34dac63a942ae9c5cf6f725108163298b6d5576ecc856896d900288089d0e936fd22e4076b3f48523a90f2a35f2429573ce23a876723ed62af8b3
@@ -31,7 +31,6 @@ require 'service_template/middleware/authentication'
31
31
  require 'service_template/middleware/request_stats'
32
32
  require 'service_template/middleware/database_stats'
33
33
  require 'service_template/authentication'
34
- require 'service_template/sortable_api'
35
34
 
36
35
  require 'service_template/deploy'
37
36
  require 'service_template/gem_dependency'
@@ -1,4 +1,4 @@
1
- class <%= name.classify %>Representer < ServiceTemplate::Representer
1
+ class <%= name.classify %>Representer < ServiceTemplate::JsonApiRepresenter
2
2
  property :id, type: String
3
3
 
4
4
  end
@@ -11,7 +11,7 @@ module ServiceTemplate
11
11
  rack_response(err.to_json, 404)
12
12
  end
13
13
  modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
14
- err = ServiceTemplate::JsonError.new(:unprocessable_entity, e.message, e.record.errors.messages)
14
+ err = ServiceTemplate::JsonError.new(:unprocessable_entity, e.record.errors.messages)
15
15
  ServiceTemplate::Logger.logger.debug ServiceTemplate::Logger.response(422, {}, err)
16
16
  rack_response(err.to_json, 422)
17
17
  end
@@ -1,9 +1,8 @@
1
1
  module ServiceTemplate
2
2
  class JsonError
3
- def initialize(code, message, reasons={})
3
+ def initialize(code, detail)
4
4
  @code = code
5
- @message = message
6
- @reasons = reasons
5
+ @detail = detail
7
6
  end
8
7
 
9
8
  def to_json(options = {})
@@ -14,11 +13,9 @@ module ServiceTemplate
14
13
  e = {
15
14
  error: {
16
15
  code: @code,
17
- message: @message
16
+ detail: @detail
18
17
  }
19
18
  }
20
- e[:error][:reasons] = @reasons if @reasons.present?
21
- e
22
19
  end
23
20
  end
24
21
  end
@@ -1,5 +1,5 @@
1
1
  module ServiceTemplate
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -37,10 +37,10 @@ describe ServiceTemplate::Generators::ApiGenerator do
37
37
  expect(representer_code).to match(/class FooRepresenter/)
38
38
  end
39
39
 
40
- it 'representers should inherit from ServiceTemplate::Representer' do
40
+ it 'representers should inherit from ServiceTemplate::JsonApiRepresenter' do
41
41
  representer_file = File.join(test_api_directory, 'app/representers/foo_representer.rb')
42
42
  require "./#{representer_file}"
43
- expect(FooRepresenter.superclass).to be(ServiceTemplate::Representer)
43
+ expect(FooRepresenter.superclass).to be(ServiceTemplate::JsonApiRepresenter)
44
44
  end
45
45
  end
46
46
 
@@ -36,9 +36,9 @@ describe ServiceTemplate::Generators::ScaffoldGenerator do
36
36
  expect(Dir).to exist(app_path)
37
37
  end
38
38
 
39
- it 'creates a .env file with with a development database name' do
40
- expect(File).to exist("#{app_path}/.env")
41
- env_file = File.read("#{app_path}/.env")
39
+ it 'creates a .env.development file with with a development database name' do
40
+ expect(File).to exist("#{app_path}/.env.development")
41
+ env_file = File.read("#{app_path}/.env.development")
42
42
  expect(env_file).to match(/#{app_name}_development/)
43
43
  end
44
44
 
@@ -7,7 +7,7 @@ describe Grape::ErrorFormatter::Json do
7
7
  error = Grape::ErrorFormatter::Json.call('test message', nil)
8
8
  parsed = JSON.parse(error)
9
9
  expect(parsed['error']['code']).to eq('api_error')
10
- expect(parsed['error']['message']).to eq('test message')
10
+ expect(parsed['error']['detail']).to eq('test message')
11
11
  end
12
12
 
13
13
  it 'returns a specified error when given a ServiceTemplate::JsonError object' do
@@ -15,7 +15,7 @@ describe Grape::ErrorFormatter::Json do
15
15
  error = Grape::ErrorFormatter::Json.call(json_error, nil)
16
16
  parsed = JSON.parse(error)
17
17
  expect(parsed['error']['code']).to eq('foo')
18
- expect(parsed['error']['message']).to eq('bar')
18
+ expect(parsed['error']['detail']).to eq('bar')
19
19
  end
20
20
 
21
21
  it 'adds the backtrace with rescue_option[:backtrace] specified' do
@@ -1,10 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'service_template/output_formatters/include_nil'
3
3
  require 'service_template/grape_extensions/grape_helpers'
4
- require 'pry'
5
4
 
6
5
  describe ServiceTemplate::Representable::IncludeNil do
7
- class FooRepresenter < ServiceTemplate::Representer
6
+ class FooRepresenter < ServiceTemplate::JsonApiRepresenter
8
7
  include ServiceTemplate::Representable::IncludeNil
9
8
  property :foo
10
9
  property :bar
@@ -14,7 +13,7 @@ describe ServiceTemplate::Representable::IncludeNil do
14
13
  include ServiceTemplate::GrapeHelpers
15
14
  end
16
15
 
17
- it 'includes nil keys in a represented hash' do
16
+ xit 'includes nil keys in a represented hash' do
18
17
  input = OpenStruct.new(foo: 1, bar: nil)
19
18
  output = DummyClass.new.represent(input, with: FooRepresenter).to_h
20
19
  expect(output[:data]).to have_key('foo')
@@ -8,26 +8,7 @@ describe ServiceTemplate::JsonError do
8
8
  parsed = JSON.parse(error)
9
9
 
10
10
  expect(parsed['error']['code']).to eq('code')
11
- expect(parsed['error']['message']).to eq('message')
11
+ expect(parsed['error']['detail']).to eq('message')
12
12
  end
13
-
14
- it 'returns a json hash with additional reasons' do
15
- error = ServiceTemplate::JsonError.new(:code, 'message', {foo: 'bar'}).to_json
16
- parsed = JSON.parse(error)
17
-
18
- expect(parsed['error']['code']).to eq('code')
19
- expect(parsed['error']['message']).to eq('message')
20
- expect(parsed['error']['reasons']['foo']).to eq('bar')
21
- end
22
-
23
- it 'excludes `reasons` from hash if no reasons given' do
24
- error = ServiceTemplate::JsonError.new(:code, 'message').to_json
25
- parsed = JSON.parse(error)
26
-
27
- expect(parsed['error']['code']).to eq('code')
28
- expect(parsed['error']['message']).to eq('message')
29
- expect(parsed['error']['reasons']).to be nil
30
- end
31
-
32
13
  end
33
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay OConnor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -365,22 +365,15 @@ files:
365
365
  - lib/service_template/param_sanitizer.rb
366
366
  - lib/service_template/rspec_extensions/response_helpers.rb
367
367
  - lib/service_template/setup.rb
368
- - lib/service_template/sortable_api.rb
369
368
  - lib/service_template/stats.rb
370
369
  - lib/service_template/stats_d_timer.rb
371
370
  - lib/service_template/version.rb
372
371
  - lib/tasks/deploy.rake
373
372
  - lib/tasks/routes.rake
374
373
  - service_template.gemspec
375
- - spec/active_record_extensions/filter_by_hash_spec.rb
376
374
  - spec/active_record_extensions/seeder_spec.rb
377
375
  - spec/authentication_spec.rb
378
- - spec/deprecations/application_api_spec.rb
379
- - spec/deprecations/entity_spec.rb
380
- - spec/deprecations/filter_by_hash_spec.rb
381
- - spec/deprecations/napa_setup_spec.rb
382
376
  - spec/generators/api_generator_spec.rb
383
- - spec/generators/migration_generator_spec.rb
384
377
  - spec/generators/readme_generator_spec.rb
385
378
  - spec/generators/scaffold_generator_spec.rb
386
379
  - spec/grape_extenders_spec.rb
@@ -394,7 +387,6 @@ files:
394
387
  - spec/middleware/authentication_spec.rb
395
388
  - spec/middleware/database_stats_spec.rb
396
389
  - spec/middleware/request_stats_spec.rb
397
- - spec/sortable_api_spec.rb
398
390
  - spec/spec_helper.rb
399
391
  - spec/stats_d_timer_spec.rb
400
392
  - spec/stats_spec.rb
@@ -426,15 +418,9 @@ signing_key:
426
418
  specification_version: 4
427
419
  summary: An easy-ish way of quickly generating an API using Grape
428
420
  test_files:
429
- - spec/active_record_extensions/filter_by_hash_spec.rb
430
421
  - spec/active_record_extensions/seeder_spec.rb
431
422
  - spec/authentication_spec.rb
432
- - spec/deprecations/application_api_spec.rb
433
- - spec/deprecations/entity_spec.rb
434
- - spec/deprecations/filter_by_hash_spec.rb
435
- - spec/deprecations/napa_setup_spec.rb
436
423
  - spec/generators/api_generator_spec.rb
437
- - spec/generators/migration_generator_spec.rb
438
424
  - spec/generators/readme_generator_spec.rb
439
425
  - spec/generators/scaffold_generator_spec.rb
440
426
  - spec/grape_extenders_spec.rb
@@ -448,9 +434,7 @@ test_files:
448
434
  - spec/middleware/authentication_spec.rb
449
435
  - spec/middleware/database_stats_spec.rb
450
436
  - spec/middleware/request_stats_spec.rb
451
- - spec/sortable_api_spec.rb
452
437
  - spec/spec_helper.rb
453
438
  - spec/stats_d_timer_spec.rb
454
439
  - spec/stats_spec.rb
455
440
  - spec/version_spec.rb
456
- has_rdoc:
@@ -1,17 +0,0 @@
1
- if defined?(ActiveRecord)
2
- module ServiceTemplate
3
- module SortableApi
4
- def sort_from_params(objects, sort_params)
5
- return objects if sort_params.nil?
6
-
7
- sort_fields = sort_params.split(",")
8
- sort_fields.each do |sort_field|
9
- sort_field = (sort_field[1..-1] + " DESC") if sort_field.start_with?("-")
10
- objects = objects.order(sort_field)
11
- end
12
-
13
- return objects
14
- end
15
- end
16
- end
17
- end
@@ -1,23 +0,0 @@
1
- require 'active_record'
2
- require 'spec_helper'
3
- require 'service_template/active_record_extensions/filter_by_hash'
4
-
5
-
6
- describe ServiceTemplate::FilterByHash do
7
- before do
8
- expect(ActiveSupport::Deprecation).to receive(:warn)
9
- class Foo < ActiveRecord::Base; include ServiceTemplate::FilterByHash; end
10
- end
11
-
12
- context 'when a hash is provided' do
13
- it 'returns an AR relation' do
14
- expect(Foo.filter).to be_a(ActiveRecord::Relation)
15
- end
16
- end
17
-
18
- context 'when nothing is provided' do
19
- it 'returns an AR relation' do
20
- expect(Foo.filter).to be_a(ActiveRecord::Relation)
21
- end
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_support'
3
- require 'service_template/deprecations/application_api'
4
-
5
- describe ServiceTemplate::Deprecations do
6
- describe '.application_api_check' do
7
- it 'does not raise a deprecation warning if the file exists' do
8
- allow(File).to receive(:exists?).and_return(true)
9
- expect(ActiveSupport::Deprecation).to_not receive(:warn)
10
- ServiceTemplate::Deprecations.application_api_check
11
- end
12
-
13
- it 'raises a deprecation warning if the file is missing' do
14
- allow(File).to receive(:exists?).and_return(false)
15
- expect(ActiveSupport::Deprecation).to receive(:warn)
16
- ServiceTemplate::Deprecations.application_api_check
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_support'
3
-
4
- describe "ServiceTemplate::Entity Deprecation" do
5
- it 'raises a deprecation warning when a class inherits' do
6
- expect(ActiveSupport::Deprecation).to receive(:warn)
7
- class FooEntity < ServiceTemplate::Entity; end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "ServiceTemplate::FilterByHash Deprecation" do
4
- it 'raises a deprecation warning when mixed in to a class' do
5
- expect(ActiveSupport::Deprecation).to receive(:warn)
6
- class FooModel; include ServiceTemplate::FilterByHash; end
7
- ActiveSupport::Deprecation.silenced = false
8
- end
9
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_support'
3
- require 'service_template/deprecations/service_template_setup'
4
-
5
- describe ServiceTemplate::Deprecations do
6
- before do
7
- allow(File).to receive(:exists?).and_return(true)
8
-
9
- @apprb_stub = [
10
- "require 'bundler/setup'",
11
- "Bundler.setup(:default)",
12
- "require 'service_template/setup'",
13
- "Bundler.require(:default, ServiceTemplate.env.to_sym)",
14
- "require 'service_template'",
15
- "ServiceTemplate.load_environment",
16
- "Dir['./config/initializers/**/*.rb'].map { |file| require file }",
17
- "Dir['./config/middleware/**/*.rb'].map { |file| require file }",
18
- "relative_load_paths = %w(app/apis app/entities app/models app/workers app/representers lib)",
19
- "ActiveSupport::Dependencies.autoload_paths += relative_load_paths"
20
- ]
21
- end
22
-
23
- describe '.service_template_setup_check' do
24
- it 'does not raise a deprecation warning if all the required_patterns are matched' do
25
- allow(File).to receive(:readlines).with('./app.rb').and_return(@apprb_stub)
26
- expect(ActiveSupport::Deprecation).to_not receive(:warn)
27
- ServiceTemplate::Deprecations.service_template_setup_check
28
- end
29
-
30
- it 'raises a deprecation warning if any of the required_patterns are missing' do
31
- (0..@apprb_stub.count - 1).each do |line_num|
32
- apprb_missing_line = @apprb_stub
33
- apprb_missing_line.delete_at(line_num)
34
- allow(File).to receive(:readlines).with('./app.rb').and_return(apprb_missing_line)
35
- expect(ActiveSupport::Deprecation).to receive(:warn)
36
-
37
- ServiceTemplate::Deprecations.service_template_setup_check
38
- end
39
- end
40
-
41
- it 'raises a deprecation warning if any of the expired_patterns are matched' do
42
- ServiceTemplate::Deprecations::EXPIRED_PATTERNS.each do |pattern|
43
- app_rb_stub = [pattern]
44
-
45
- allow(File).to receive(:readlines).with('./app.rb').and_return(app_rb_stub)
46
- expect(ActiveSupport::Deprecation).to receive(:warn)
47
-
48
- ServiceTemplate::Deprecations.service_template_setup_check
49
- end
50
- end
51
- end
52
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
- require 'service_template/generators/migration_generator'
3
- require 'service_template/cli'
4
-
5
- describe ServiceTemplate::Generators::MigrationGenerator do
6
-
7
- let(:migration_filename) { 'foo' }
8
- let(:test_migrations_directory) { 'spec/tmp' }
9
-
10
- before do
11
- allow_any_instance_of(described_class).to receive(:output_directory).and_return(test_migrations_directory)
12
- allow_any_instance_of(described_class).to receive(:migration_filename).and_return(migration_filename)
13
- end
14
-
15
- after do
16
- FileUtils.rm_rf(test_migrations_directory)
17
- end
18
-
19
- describe 'AddFooToBar flew:string:index brew:integer' do
20
- before do
21
- ServiceTemplate::CLI::Base.new.generate("migration", 'AddFooToBar', 'flew:string:index', 'brew:integer')
22
- expected_migration_file = File.join(test_migrations_directory, 'foo.rb')
23
- @migration_code = File.read(expected_migration_file)
24
- end
25
-
26
- it 'creates a camelized migration class' do
27
- expect(@migration_code).to match(/class AddFooToBar/)
28
- end
29
-
30
- it 'adds the columns' do
31
- expect(@migration_code).to match(/add_column :bars, :flew, :string/)
32
- expect(@migration_code).to match(/add_column :bars, :brew, :integer/)
33
- end
34
-
35
- it 'adds the index on the correct column' do
36
- expect(@migration_code).to match(/add_index :bars, :flew/)
37
- end
38
- end
39
-
40
- describe 'RemoveFooFromBar flew:string brew:integer' do
41
- before do
42
- ServiceTemplate::CLI::Base.new.generate("migration", 'RemoveFooFromBar', 'flew:string', 'brew:integer')
43
- expected_migration_file = File.join(test_migrations_directory, 'foo.rb')
44
- @migration_code = File.read(expected_migration_file)
45
- end
46
-
47
- it 'creates a camelized migration class' do
48
- expect(@migration_code).to match(/class RemoveFooFromBar/)
49
- end
50
-
51
- it 'removes the columns' do
52
- expect(@migration_code).to match(/remove_column :bars, :flew, :string/)
53
- expect(@migration_code).to match(/remove_column :bars, :brew, :integer/)
54
- end
55
- end
56
-
57
- describe 'CreateJoinTableFooBar foo bar' do
58
- before do
59
- ServiceTemplate::CLI::Base.new.generate("migration", 'CreateJoinTableFooBar', 'foo', 'bar')
60
- expected_migration_file = File.join(test_migrations_directory, 'foo.rb')
61
- @migration_code = File.read(expected_migration_file)
62
- end
63
-
64
- it 'creates a camelized migration class' do
65
- expect(@migration_code).to match(/class CreateJoinTableFooBar/)
66
- end
67
-
68
- it 'creates the join table' do
69
- expect(@migration_code).to match(/create_join_table :foos, :bars/)
70
- end
71
-
72
- it 'adds placeholders for the indexing' do
73
- expect(@migration_code).to match(/# t.index \[:foo_id, :bar_id\]/)
74
- expect(@migration_code).to match(/# t.index \[:bar_id, :foo_id\]/)
75
- end
76
- end
77
-
78
- describe 'CreateSkrillex drops:integer hair:string:index' do
79
- before do
80
- ServiceTemplate::CLI::Base.new.generate("migration", 'CreateSkrillex', 'drops:integer', 'hair:string:index')
81
- expected_migration_file = File.join(test_migrations_directory, 'foo.rb')
82
- @migration_code = File.read(expected_migration_file)
83
- end
84
-
85
- it 'creates a camelized migration class' do
86
- expect(@migration_code).to match(/class CreateSkrillex/)
87
- end
88
-
89
- it 'creates the table' do
90
- expect(@migration_code).to match(/create_table :skrillexes/)
91
- end
92
-
93
- it 'adds the columns' do
94
- expect(@migration_code).to match(/t.integer :drops/)
95
- expect(@migration_code).to match(/t.string :hair/)
96
- end
97
-
98
- it 'adds the index on the correct column' do
99
- expect(@migration_code).to match(/add_index :skrillexes, :hair/)
100
- end
101
- end
102
-
103
- describe
104
-
105
- end
@@ -1,56 +0,0 @@
1
- require 'active_record'
2
- require 'spec_helper'
3
- require 'service_template/sortable_api'
4
-
5
- describe "SortableApi" do
6
- describe "#sort_from_params" do
7
- before do
8
- build_model :foos do
9
- integer :param1
10
- integer :param2
11
- end
12
-
13
- @object1 = Foo.create(param1: 2, param2: 1)
14
- @object2 = Foo.create(param1: 2, param2: 3)
15
- @object3 = Foo.create(param1: 3, param2: 5)
16
- @object4 = Foo.create(param1: 1, param2: 3)
17
- @object5 = Foo.create(param1: 1, param2: 1)
18
-
19
- @api = Object.new
20
- @api.extend(ServiceTemplate::SortableApi)
21
- @foos = Foo.scoped
22
- end
23
-
24
- it "returns the sortable objects if sort_param is nil" do
25
- expect(@api.sort_from_params(@foos, nil)).to eq(@foos)
26
- end
27
-
28
- it "sorts by a given parameter" do
29
- sorted = @api.sort_from_params(@foos, "param1")
30
- expect(sorted.last).to eq(@object3)
31
- expect(sorted.to_sql).to end_with("ORDER BY param1")
32
- end
33
-
34
- it "sorts by a given parameter descending if preceded by -" do
35
- sorted = @api.sort_from_params(@foos, "-param1")
36
- expect(sorted.first).to eq(@object3)
37
- expect(sorted.to_sql).to end_with("ORDER BY param1 DESC")
38
- end
39
-
40
- it "sorts by multiple parameters in order" do
41
- sorted = @api.sort_from_params(@foos, "param2,param1")
42
- expect(sorted.to_a).to eq([@object5, @object1, @object4, @object2, @object3])
43
- expect(sorted.to_sql).to end_with("ORDER BY param2, param1")
44
-
45
- alt_sorted = @api.sort_from_params(@foos, "param1,param2")
46
- expect(alt_sorted.to_a).to eq([@object5, @object4, @object1, @object2, @object3])
47
- expect(alt_sorted.to_sql).to end_with("ORDER BY param1, param2")
48
- end
49
-
50
- it "sorts by multiple parameters, even if descending" do
51
- sorted = @api.sort_from_params(@foos, "-param2,param1")
52
- expect(sorted.to_a).to eq([@object3, @object4, @object2, @object5, @object1])
53
- expect(sorted.to_sql).to end_with("ORDER BY param2 DESC, param1")
54
- end
55
- end
56
- end