ocean-rails 5.7.2 → 5.7.3

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.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/ocean_scaffold/templates/controller_specs/create_spec.rb +1 -0
  3. data/lib/generators/ocean_scaffold/templates/controller_specs/delete_spec.rb +1 -0
  4. data/lib/generators/ocean_scaffold/templates/controller_specs/index_spec.rb +1 -0
  5. data/lib/generators/ocean_scaffold/templates/controller_specs/show_spec.rb +1 -0
  6. data/lib/generators/ocean_scaffold/templates/controller_specs/update_spec.rb +1 -0
  7. data/lib/generators/ocean_scaffold/templates/view_specs/_resource_spec.rb +1 -0
  8. data/lib/generators/ocean_scaffold_dynamo/USAGE +8 -0
  9. data/lib/generators/ocean_scaffold_dynamo/ocean_scaffold_dynamo_generator.rb +96 -0
  10. data/lib/generators/ocean_scaffold_dynamo/templates/controller.rb +83 -0
  11. data/lib/generators/ocean_scaffold_dynamo/templates/controller_specs/create_spec.rb +72 -0
  12. data/lib/generators/ocean_scaffold_dynamo/templates/controller_specs/delete_spec.rb +48 -0
  13. data/lib/generators/ocean_scaffold_dynamo/templates/controller_specs/index_spec.rb +52 -0
  14. data/lib/generators/ocean_scaffold_dynamo/templates/controller_specs/show_spec.rb +44 -0
  15. data/lib/generators/ocean_scaffold_dynamo/templates/controller_specs/update_spec.rb +86 -0
  16. data/lib/generators/ocean_scaffold_dynamo/templates/model_spec.rb +39 -0
  17. data/lib/generators/ocean_scaffold_dynamo/templates/resource_routing_spec.rb +27 -0
  18. data/lib/generators/ocean_scaffold_dynamo/templates/view_specs/_resource_spec.rb +56 -0
  19. data/lib/generators/ocean_scaffold_dynamo/templates/views/_resource.json.jbuilder +11 -0
  20. data/lib/ocean/version.rb +1 -1
  21. metadata +14 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aad06c44231394d3492ed38bc19f036f30243b0e
4
- data.tar.gz: 1954dfcda369f4b8940de7e8b5d9b1f5aec1a2de
3
+ metadata.gz: b77eee37e70f96b4d1f17874b279db7e1d87a73d
4
+ data.tar.gz: bdbbfac3f27b19de30d717c5c1aae93c3461c061
5
5
  SHA512:
6
- metadata.gz: d14611e0298e23b7a58c2e70ee4eca110d3bd8d4351e7874c3b84497dfa577421e2d7eda3d631efd6ef65fab7d871a3151207fa3016dda68d964816779c1f52d
7
- data.tar.gz: e9c77525b77d657a8b46f074d16e29064fa3359007b5a21904a55a669a37c2f0d7ffb50416a306552d15adf86652ecf671943225ab66bbb2c36ea5ad38719f12
6
+ metadata.gz: 8b074a8b9c4febf03d0a8e24277ce89f6d6f371e05ecd86c40e2d0c87fd89de1969ef2461333e08b40ce161b1271ba61099eb6c405ac089bda82a9f59a2fdd6b
7
+ data.tar.gz: 9dd6e17eb74d8ec7faa99956e841889efaff0b737b04c852f02743db8b3b762a4186a77f725aa24ca2c803c8a9cd80a3d607dfca66de1eac98a36a65ae492318
@@ -7,6 +7,7 @@ describe <%= class_name.pluralize %>Controller do
7
7
  describe "POST" do
8
8
 
9
9
  before :each do
10
+ <%= class_name %>.delete_all
10
11
  permit_with 200
11
12
  request.headers['HTTP_ACCEPT'] = "application/json"
12
13
  request.headers['X-API-Token'] = "incredibly-fake!"
@@ -7,6 +7,7 @@ describe <%= class_name.pluralize %>Controller do
7
7
  describe "DELETE" do
8
8
 
9
9
  before :each do
10
+ <%= class_name %>.delete_all
10
11
  permit_with 200
11
12
  @<%= singular_name %> = create :<%= singular_name %>
12
13
  request.headers['HTTP_ACCEPT'] = "application/json"
@@ -7,6 +7,7 @@ describe <%= class_name.pluralize %>Controller do
7
7
  describe "INDEX" do
8
8
 
9
9
  before :each do
10
+ <%= class_name %>.delete_all
10
11
  permit_with 200
11
12
  create :<%= singular_name %>
12
13
  create :<%= singular_name %>
@@ -7,6 +7,7 @@ describe <%= class_name.pluralize %>Controller do
7
7
  describe "GET" do
8
8
 
9
9
  before :each do
10
+ <%= class_name %>.delete_all
10
11
  permit_with 200
11
12
  @<%= singular_name %> = create :<%= singular_name %>
12
13
  request.headers['HTTP_ACCEPT'] = "application/json"
@@ -7,6 +7,7 @@ describe <%= class_name.pluralize %>Controller do
7
7
  describe "PUT" do
8
8
 
9
9
  before :each do
10
+ <%= class_name %>.delete_all
10
11
  permit_with 200
11
12
  request.headers['HTTP_ACCEPT'] = "application/json"
12
13
  request.headers['X-API-Token'] = "incredibly-fake!"
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe "<%= plural_name %>/_<%= singular_name %>" do
4
4
 
5
5
  before :each do # Must be :each (:all causes all tests to fail)
6
+ <%= class_name %>.delete_all
6
7
  render partial: "<%= plural_name %>/<%= singular_name %>", locals: {<%= singular_name %>: create(:<%= singular_name %>)}
7
8
  @json = JSON.parse(rendered)
8
9
  @u = @json['<%= singular_name %>']
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate ocean_scaffold_dynamo Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,96 @@
1
+ class OceanScaffoldDynamoGenerator < Rails::Generators::NamedBase #:nodoc: all
2
+
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def convert_to_dynamodb
6
+ gsub_file "#{Rails.root}/app/models/#{singular_name}.rb",
7
+ "class #{class_name} < ActiveRecord::Base",
8
+ "class #{class_name} < OceanDynamo::Table"
9
+ end
10
+
11
+ def extend_model
12
+ inject_into_class "#{Rails.root}/app/models/#{singular_name}.rb",
13
+ class_name.constantize,
14
+ "
15
+
16
+ ocean_resource_model index: false,
17
+ search: false
18
+
19
+ dynamo_schema(:id, table_name_suffix: Api.basename_suffix,
20
+ create: Rails.env != 'production') do
21
+ # Input attributes
22
+ attribute :name
23
+ attribute :description
24
+ attribute :created_by
25
+ attribute :updated_by
26
+ end
27
+
28
+ # Relations
29
+
30
+
31
+ # Attributes
32
+
33
+
34
+ # Validations
35
+
36
+
37
+ "
38
+ end
39
+
40
+ def add_model_specs
41
+ template "model_spec.rb", "#{Rails.root}/spec/models/#{singular_name}_spec.rb"
42
+ end
43
+
44
+ def replace_controller
45
+ template "controller.rb", "#{Rails.root}/app/controllers/#{plural_name}_controller.rb"
46
+ end
47
+
48
+ def remove_html_controller_specs
49
+ remove_file "spec/controllers/#{plural_name}_controller_spec.rb"
50
+ end
51
+
52
+ def add_json_controller_specs
53
+ template "controller_specs/delete_spec.rb", "#{Rails.root}/spec/controllers/#{plural_name}/delete_spec.rb"
54
+ template "controller_specs/show_spec.rb", "#{Rails.root}/spec/controllers/#{plural_name}/show_spec.rb"
55
+ template "controller_specs/index_spec.rb", "#{Rails.root}/spec/controllers/#{plural_name}/index_spec.rb"
56
+ template "controller_specs/create_spec.rb", "#{Rails.root}/spec/controllers/#{plural_name}/create_spec.rb"
57
+ template "controller_specs/update_spec.rb", "#{Rails.root}/spec/controllers/#{plural_name}/update_spec.rb"
58
+ end
59
+
60
+ def remove_html_views
61
+ remove_file "app/views/#{plural_name}/_form.html.erb"
62
+ remove_file "app/views/#{plural_name}/edit.html.erb"
63
+ remove_file "app/views/#{plural_name}/index.html.erb"
64
+ remove_file "app/views/#{plural_name}/index.json.jbuilder"
65
+ remove_file "app/views/#{plural_name}/new.html.erb"
66
+ remove_file "app/views/#{plural_name}/show.html.erb"
67
+ remove_file "app/views/#{plural_name}/show.json.jbuilder"
68
+ end
69
+
70
+ def add_json_views
71
+ template "views/_resource.json.jbuilder", "#{Rails.root}/app/views/#{plural_name}/_#{singular_name}.json.jbuilder"
72
+ end
73
+
74
+ def remove_html_view_specs
75
+ remove_file "spec/views/#{plural_name}/index.html.erb_spec.rb"
76
+ remove_file "spec/views/#{plural_name}/show.html.erb_spec.rb"
77
+ remove_file "spec/views/#{plural_name}/new.html.erb_spec.rb"
78
+ remove_file "spec/views/#{plural_name}/create.html.erb_spec.rb"
79
+ remove_file "spec/views/#{plural_name}/update.html.erb_spec.rb"
80
+ remove_file "spec/views/#{plural_name}/edit.html.erb_spec.rb"
81
+ end
82
+
83
+ def add_json_view_spec
84
+ template "view_specs/_resource_spec.rb", "#{Rails.root}/spec/views/#{plural_name}/_#{singular_name}_spec.rb"
85
+ end
86
+
87
+ def remove_request_specs
88
+ remove_file "spec/requests/#{plural_name}_spec.rb"
89
+ end
90
+
91
+ def update_routing_specs
92
+ remove_file "spec/routing/#{plural_name}_routing_spec.rb"
93
+ template "resource_routing_spec.rb", "#{Rails.root}/spec/routing/#{plural_name}_routing_spec.rb"
94
+ end
95
+
96
+ end
@@ -0,0 +1,83 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+
8
+ ocean_resource_controller required_attributes: [:lock_version]
9
+
10
+ before_action :find_<%= singular_table_name %>, :only => [:show, :update, :destroy]
11
+
12
+
13
+ # GET <%= route_url %>
14
+ def index
15
+ expires_in 0, 's-maxage' => 30.minutes
16
+ # if stale?(collection_etag(<%= class_name %>)) # collection_etag is still ActiveRecord only!
17
+ # Instead, we get all the instances and compute the ETag manually.
18
+ # You may wish to remove this action entirely. You may also wish to remove the caching,
19
+ # in which case you don't need to compute the Etag at all.
20
+ @<%= plural_table_name %> = <%= class_name %>.all
21
+ latest = @<%= plural_table_name %>.max_by(&:updated_at)
22
+ last_updated = latest && latest.updated_at
23
+ if stale?(etag: "<%= class_name %>:#{@<%= plural_table_name %>.length}:#{last_updated}")
24
+ api_render @<%= plural_table_name %>
25
+ end
26
+ end
27
+
28
+
29
+ # GET <%= route_url %>/a-b-c-d-e
30
+ def show
31
+ expires_in 0, 's-maxage' => 30.minutes
32
+ if stale?(etag: @<%= singular_table_name %>.lock_version, # NB: DynamoDB tables don't have cache_key - FIX!
33
+ last_modified: @<%= singular_table_name %>.updated_at)
34
+ api_render @<%= singular_table_name %>
35
+ end
36
+ end
37
+
38
+
39
+ # POST <%= route_url %>
40
+ def create
41
+ ActionController::Parameters.permit_all_parameters = true
42
+ name = params[:name]
43
+ description = params[:description]
44
+ @<%= singular_table_name %> = <%= class_name %>.new(name: name, description: description)
45
+ set_updater(@<%= singular_table_name %>)
46
+ @<%= singular_table_name %>.save!
47
+ api_render @<%= singular_table_name %>, new: true
48
+ end
49
+
50
+
51
+ # PUT <%= route_url %>/a-b-c-d-e
52
+ def update
53
+ if missing_attributes?
54
+ render_api_error 422, "Missing resource attributes"
55
+ return
56
+ end
57
+ @<%= singular_table_name %>.name = params[:name] if params[:name]
58
+ @<%= singular_table_name %>.description = params[:description] if params[:description]
59
+ set_updater(@<%= singular_table_name %>)
60
+ @<%= singular_table_name %>.save!
61
+ api_render @<%= singular_table_name %>
62
+ end
63
+
64
+
65
+ # DELETE <%= route_url %>/a-b-c-d-e
66
+ def destroy
67
+ @<%= singular_table_name %>.destroy
68
+ render_head_204
69
+ end
70
+
71
+
72
+ private
73
+
74
+ def find_<%= singular_table_name %>
75
+ ActionController::Parameters.permit_all_parameters = true
76
+ @<%= singular_table_name %> = <%= class_name %>.find_by_key(params['id'], consistent: true)
77
+ return true if @<%= singular_table_name %>
78
+ render_api_error 404, "<%= class_name %> not found"
79
+ false
80
+ end
81
+
82
+ end
83
+ <% end -%>
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+
5
+ render_views
6
+
7
+ describe "POST" do
8
+
9
+ before :each do
10
+ <%= class_name %>.delete_all
11
+ permit_with 200
12
+ request.headers['HTTP_ACCEPT'] = "application/json"
13
+ request.headers['X-API-Token'] = "incredibly-fake!"
14
+ @args = build(:<%= singular_name %>).attributes
15
+ end
16
+
17
+
18
+ it "should return JSON" do
19
+ post :create, @args
20
+ expect(response.content_type).to eq "application/json"
21
+ end
22
+
23
+ it "should return a 400 if the X-API-Token header is missing" do
24
+ request.headers['X-API-Token'] = nil
25
+ post :create, @args
26
+ expect(response.status).to eq 400
27
+ end
28
+
29
+ it "should return a 201 when successful" do
30
+ post :create, @args
31
+ expect(response).to render_template(partial: "_<%= singular_name %>", count: 1)
32
+ expect(response.status).to eq 201
33
+ end
34
+
35
+ it "should contain a Location header when successful" do
36
+ post :create, @args
37
+ expect(response.headers['Location']).to be_a String
38
+ end
39
+
40
+ it "should return the new resource in the body when successful" do
41
+ post :create, @args
42
+ expect(response.body).to be_a String
43
+ end
44
+
45
+ #
46
+ # Uncomment this test as soon as there is one or more DB attributes that define
47
+ # the uniqueness of a record.
48
+ #
49
+ # it "should return a 422 if the <%= singular_name %> already exists" do
50
+ # post :create, @args
51
+ # expect(response.status).to eq 201
52
+ # expect(response.content_type).to eq "application/json"
53
+ # post :create, @args
54
+ # expect(response.status).to eq 422
55
+ # expect(response.content_type).to eq "application/json"
56
+ # expect(JSON.parse(response.body).to eq({"_api_error" => ["<%= class_name %> already exists"]})
57
+ # end
58
+
59
+ #
60
+ # Uncomment this test as soon as there is one or more DB attributes that need
61
+ # validating.
62
+ #
63
+ # it "should return a 422 when there are validation errors" do
64
+ # post :create, @args.merge('name' => "qz")
65
+ # expect(response.status).to eq 422
66
+ # expect(response.content_type).to eq "application/json"
67
+ # expect(JSON.parse(response.body)).to eq({"name"=>["is too short (minimum is 3 characters)"]})
68
+ # end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+
5
+ render_views
6
+
7
+ describe "DELETE" do
8
+
9
+ before :each do
10
+ <%= class_name %>.delete_all
11
+ permit_with 200
12
+ @<%= singular_name %> = create :<%= singular_name %>
13
+ request.headers['HTTP_ACCEPT'] = "application/json"
14
+ request.headers['X-API-Token'] = "so-totally-fake"
15
+ end
16
+
17
+
18
+ it "should return JSON" do
19
+ delete :destroy, id: @<%= singular_name %>
20
+ expect(response.content_type).to eq "application/json"
21
+ end
22
+
23
+ it "should return a 400 if the X-API-Token header is missing" do
24
+ request.headers['X-API-Token'] = nil
25
+ delete :destroy, id: @<%= singular_name %>
26
+ expect(response.status).to eq 400
27
+ end
28
+
29
+ it "should return a 204 when successful" do
30
+ delete :destroy, id: @<%= singular_name %>
31
+ expect(response.status).to eq 204
32
+ expect(response.content_type).to eq "application/json"
33
+ end
34
+
35
+ it "should return a 404 when the <%= class_name %> can't be found" do
36
+ delete :destroy, id: "0-0-0-0-0"
37
+ expect(response.status).to eq 404
38
+ end
39
+
40
+ it "should destroy the <%= class_name %> when successful" do
41
+ delete :destroy, id: @<%= singular_name %>
42
+ expect(response.status).to eq 204
43
+ expect(<%= class_name %>.find_by_id(@<%= singular_name %>.id)).to be_nil
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+
5
+ render_views
6
+
7
+ describe "INDEX" do
8
+
9
+ before :each do
10
+ <%= class_name %>.delete_all
11
+ permit_with 200
12
+ create :<%= singular_name %>
13
+ create :<%= singular_name %>
14
+ create :<%= singular_name %>
15
+ request.headers['HTTP_ACCEPT'] = "application/json"
16
+ request.headers['X-API-Token'] = "boy-is-this-fake"
17
+ end
18
+
19
+
20
+ it "should return JSON" do
21
+ get :index
22
+ expect(response.content_type).to eq "application/json"
23
+ end
24
+
25
+ it "should return a 400 if the X-API-Token header is missing" do
26
+ request.headers['X-API-Token'] = nil
27
+ get :index
28
+ expect(response.status).to eq 400
29
+ expect(response.content_type).to eq "application/json"
30
+ end
31
+
32
+ it "should return a 200 when successful" do
33
+ get :index
34
+ expect(response.status).to eq 200
35
+ expect(response).to render_template(partial: "_<%= singular_name %>", count: 3)
36
+ end
37
+
38
+ it "should return a collection" do
39
+ get :index
40
+ expect(response.status).to eq 200
41
+ wrapper = JSON.parse(response.body)
42
+ expect(wrapper).to be_a Hash
43
+ resource = wrapper['_collection']
44
+ expect(resource).to be_a Hash
45
+ coll = resource['resources']
46
+ expect(coll).to be_an Array
47
+ expect(coll.count).to eq 3
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+
5
+ render_views
6
+
7
+ describe "GET" do
8
+
9
+ before :each do
10
+ <%= class_name %>.delete_all
11
+ permit_with 200
12
+ @<%= singular_name %> = create :<%= singular_name %>
13
+ request.headers['HTTP_ACCEPT'] = "application/json"
14
+ request.headers['X-API-Token'] = "totally-fake"
15
+ end
16
+
17
+
18
+ it "should return JSON" do
19
+ get :show, id: @<%= singular_name %>
20
+ expect(response.content_type).to eq "application/json"
21
+ end
22
+
23
+ it "should return a 400 if the X-API-Token header is missing" do
24
+ request.headers['X-API-Token'] = nil
25
+ get :show, id: @<%= singular_name %>
26
+ expect(response.status).to eq 400
27
+ expect(response.content_type).to eq "application/json"
28
+ end
29
+
30
+ it "should return a 404 when the user can't be found" do
31
+ get :show, id: "0-0-0-0-0"
32
+ expect(response.status).to eq 404
33
+ expect(response.content_type).to eq "application/json"
34
+ end
35
+
36
+ it "should return a 200 when successful" do
37
+ get :show, id: @<%= singular_name %>
38
+ expect(response.status).to eq 200
39
+ expect(response).to render_template(partial: "_<%= singular_name %>", count: 1)
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+
5
+ render_views
6
+
7
+ describe "PUT" do
8
+
9
+ before :each do
10
+ <%= class_name %>.delete_all
11
+ permit_with 200
12
+ request.headers['HTTP_ACCEPT'] = "application/json"
13
+ request.headers['X-API-Token'] = "incredibly-fake!"
14
+ @u = create :<%= singular_name %>
15
+ @args = @u.attributes
16
+ end
17
+
18
+
19
+ it "should return JSON" do
20
+ put :update, @args
21
+ expect(response.content_type).to eq "application/json"
22
+ end
23
+
24
+ it "should return a 400 if the X-API-Token header is missing" do
25
+ request.headers['X-API-Token'] = nil
26
+ put :update, @args
27
+ expect(response.status).to eq 400
28
+ end
29
+
30
+ it "should return a 404 if the resource can't be found" do
31
+ put :update, id: "0-0-0-0-0"
32
+ expect(response.status).to eq 404
33
+ expect(response.content_type).to eq "application/json"
34
+ end
35
+
36
+ it "should return a 422 when resource properties are missing (all must be set simultaneously)" do
37
+ put :update, id: @u.id
38
+ expect(response.status).to eq 422
39
+ expect(response.content_type).to eq "application/json"
40
+ end
41
+
42
+ it "should return a 409 when there is an update conflict" do
43
+ @args['lock_version'] = -2
44
+ put :update, @args
45
+ expect(response.status).to eq(409)
46
+ end
47
+
48
+ it "should return a 200 when successful" do
49
+ put :update, @args
50
+ expect(response.status).to eq 200
51
+ expect(response).to render_template(partial: "_<%= singular_name %>", count: 1)
52
+ end
53
+
54
+ it "should return the updated resource in the body when successful" do
55
+ put :update, @args
56
+ expect(response.status).to eq 200
57
+ expect(JSON.parse(response.body)).to be_a Hash
58
+ end
59
+
60
+ #
61
+ # Uncomment this test as soon as there is one or more DB attributes that need
62
+ # validating.
63
+ #
64
+ # it "should return a 422 when there are validation errors" do
65
+ # put :update, @args.merge('name' => "qz")
66
+ # expect(response.status).to eq 422
67
+ # expect(response.content_type).to eq "application/json"
68
+ # expect(JSON.parse(response.body)).to eq({"name"=>["is too short (minimum is 3 characters)"]})
69
+ # end
70
+
71
+
72
+ # it "should alter the <%= singular_name %> when successful" do
73
+ # expect(@u.name).to eq @args['name']
74
+ # expect(@u.description).to eq @args['description']
75
+ # @args['name'] = "zalagadoola"
76
+ # @args['description'] = "menchikaboola"
77
+ # put :update, @args
78
+ # expect(response.status).to eq 200
79
+ # @u.reload
80
+ # expect(@u.name).to eq "zalagadoola"
81
+ # expect(@u.description).to eq "menchikaboola"
82
+ # end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+
5
+
6
+ describe "attributes" do
7
+
8
+ it "should have a name" do
9
+ expect(create(:<%= singular_name %>).name).to be_a String
10
+ end
11
+
12
+ it "should have a description" do
13
+ expect(create(:<%= singular_name %>).description).to be_a String
14
+ end
15
+
16
+ it "should have a creation time" do
17
+ expect(create(:<%= singular_name %>).created_at).to be_a Time
18
+ end
19
+
20
+ it "should have an update time" do
21
+ expect(create(:<%= singular_name %>).updated_at).to be_a Time
22
+ end
23
+
24
+ it "should have a creator" do
25
+ expect(create(:<%= singular_name %>).created_by).to be_a String
26
+ end
27
+
28
+ it "should have an updater" do
29
+ expect(create(:<%= singular_name %>).updated_by).to be_a String
30
+ end
31
+
32
+ end
33
+
34
+
35
+ describe "relations" do
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe <%= class_name.pluralize %>Controller do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ expect(get("/v1/<%= plural_name %>")).to route_to("<%= plural_name %>#index")
8
+ end
9
+
10
+ it "routes to #show" do
11
+ expect(get("/v1/<%= plural_name %>/1-2-3-4-5")).to route_to("<%= plural_name %>#show", id: "1-2-3-4-5")
12
+ end
13
+
14
+ it "routes to #create" do
15
+ expect(post("/v1/<%= plural_name %>")).to route_to("<%= plural_name %>#create")
16
+ end
17
+
18
+ it "routes to #update" do
19
+ expect(put("/v1/<%= plural_name %>/1-2-3-4-5")).to route_to("<%= plural_name %>#update", id: "1-2-3-4-5")
20
+ end
21
+
22
+ it "routes to #destroy" do
23
+ expect(delete("/v1/<%= plural_name %>/1-2-3-4-5")).to route_to("<%= plural_name %>#destroy", id: "1-2-3-4-5")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe "<%= plural_name %>/_<%= singular_name %>" do
4
+
5
+ before :each do # Must be :each (:all causes all tests to fail)
6
+ <%= class_name %>.delete_all
7
+ render partial: "<%= plural_name %>/<%= singular_name %>", locals: {<%= singular_name %>: create(:<%= singular_name %>)}
8
+ @json = JSON.parse(rendered)
9
+ @u = @json['<%= singular_name %>']
10
+ @links = @u['_links'] rescue {}
11
+ end
12
+
13
+
14
+ it "has a named root" do
15
+ expect(@u).not_to eq nil
16
+ end
17
+
18
+
19
+ it "should have three hyperlinks" do
20
+ expect(@links.size).to eq 3
21
+ end
22
+
23
+ it "should have a self hyperlink" do
24
+ expect(@links).to be_hyperlinked('self', /<%= plural_name %>/)
25
+ end
26
+
27
+ it "should have a creator hyperlink" do
28
+ expect(@links).to be_hyperlinked('creator', /api_users/)
29
+ end
30
+
31
+ it "should have an updater hyperlink" do
32
+ expect(@links).to be_hyperlinked('updater', /api_users/)
33
+ end
34
+
35
+
36
+ it "should have a name" do
37
+ expect(@u['name']).to be_a String
38
+ end
39
+
40
+ it "should have a description" do
41
+ expect(@u['description']).to be_a String
42
+ end
43
+
44
+ it "should have a created_at time" do
45
+ expect(@u['created_at']).to be_a String
46
+ end
47
+
48
+ it "should have an updated_at time" do
49
+ expect(@u['updated_at']).to be_a String
50
+ end
51
+
52
+ it "should have a lock_version field" do
53
+ expect(@u['lock_version']).to be_an Integer
54
+ end
55
+
56
+ end
@@ -0,0 +1,11 @@
1
+ json.<%= singular_name %> do |json|
2
+ json._links hyperlinks(self: <%= singular_name %>_url(<%= singular_name %>),
3
+ creator: smart_api_user_url(<%= singular_name %>.created_by),
4
+ updater: smart_api_user_url(<%= singular_name %>.updated_by))
5
+ json.(<%= singular_name %>, :lock_version,
6
+ :name,
7
+ :description
8
+ )
9
+ json.created_at <%= singular_name %>.created_at.utc.iso8601
10
+ json.updated_at <%= singular_name %>.updated_at.utc.iso8601
11
+ end
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "5.7.2"
2
+ VERSION = "5.7.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.2
4
+ version: 5.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -236,6 +236,18 @@ files:
236
236
  - lib/generators/ocean_scaffold/templates/resource_routing_spec.rb
237
237
  - lib/generators/ocean_scaffold/templates/view_specs/_resource_spec.rb
238
238
  - lib/generators/ocean_scaffold/templates/views/_resource.json.jbuilder
239
+ - lib/generators/ocean_scaffold_dynamo/USAGE
240
+ - lib/generators/ocean_scaffold_dynamo/ocean_scaffold_dynamo_generator.rb
241
+ - lib/generators/ocean_scaffold_dynamo/templates/controller.rb
242
+ - lib/generators/ocean_scaffold_dynamo/templates/controller_specs/create_spec.rb
243
+ - lib/generators/ocean_scaffold_dynamo/templates/controller_specs/delete_spec.rb
244
+ - lib/generators/ocean_scaffold_dynamo/templates/controller_specs/index_spec.rb
245
+ - lib/generators/ocean_scaffold_dynamo/templates/controller_specs/show_spec.rb
246
+ - lib/generators/ocean_scaffold_dynamo/templates/controller_specs/update_spec.rb
247
+ - lib/generators/ocean_scaffold_dynamo/templates/model_spec.rb
248
+ - lib/generators/ocean_scaffold_dynamo/templates/resource_routing_spec.rb
249
+ - lib/generators/ocean_scaffold_dynamo/templates/view_specs/_resource_spec.rb
250
+ - lib/generators/ocean_scaffold_dynamo/templates/views/_resource.json.jbuilder
239
251
  - lib/generators/ocean_setup/USAGE
240
252
  - lib/generators/ocean_setup/ocean_setup_generator.rb
241
253
  - lib/generators/ocean_setup/templates/Gemfile