sandboxy 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/.github/pull_request_template.md +2 -2
  3. data/CHANGELOG.md +6 -0
  4. data/CODE_OF_CONDUCT.md +1 -1
  5. data/DEPRECATIONS.md +3 -1
  6. data/Gemfile +1 -1
  7. data/INSTALL.md +1 -1
  8. data/LICENSE +1 -1
  9. data/README.md +68 -38
  10. data/Rakefile +0 -1
  11. data/examples/rails_example/Gemfile +1 -0
  12. data/examples/rails_example/app/api/books/api.rb +33 -0
  13. data/examples/rails_example/app/assets/javascripts/{bars.coffee → applications.coffee} +0 -0
  14. data/examples/rails_example/app/assets/javascripts/{foos.coffee → authors.coffee} +0 -0
  15. data/examples/rails_example/app/assets/javascripts/books.coffee +3 -0
  16. data/examples/rails_example/app/assets/javascripts/libraries.coffee +3 -0
  17. data/examples/rails_example/app/assets/javascripts/sandbox.coffee +3 -0
  18. data/examples/rails_example/app/assets/stylesheets/applications.scss +3 -0
  19. data/examples/rails_example/app/assets/stylesheets/{foos.scss → authors.scss} +1 -1
  20. data/examples/rails_example/app/assets/stylesheets/{bars.scss → books.scss} +1 -1
  21. data/examples/rails_example/app/assets/stylesheets/libraries.scss +3 -0
  22. data/examples/rails_example/app/assets/stylesheets/sandbox.scss +3 -0
  23. data/examples/rails_example/app/controllers/application_controller.rb +5 -1
  24. data/examples/rails_example/app/controllers/applications_controller.rb +74 -0
  25. data/examples/rails_example/app/controllers/authors_controller.rb +77 -0
  26. data/examples/rails_example/app/controllers/books_controller.rb +77 -0
  27. data/examples/rails_example/app/controllers/libraries_controller.rb +77 -0
  28. data/examples/rails_example/app/controllers/sandbox_controller.rb +6 -0
  29. data/examples/rails_example/app/helpers/applications_helper.rb +2 -0
  30. data/examples/rails_example/app/helpers/authors_helper.rb +2 -0
  31. data/examples/rails_example/app/helpers/books_helper.rb +2 -0
  32. data/examples/rails_example/app/helpers/libraries_helper.rb +2 -0
  33. data/examples/rails_example/app/helpers/sandbox_helper.rb +2 -0
  34. data/examples/rails_example/app/models/application.rb +14 -0
  35. data/examples/rails_example/app/models/author.rb +2 -0
  36. data/examples/rails_example/app/models/book.rb +2 -0
  37. data/examples/rails_example/app/models/library.rb +2 -0
  38. data/examples/rails_example/app/views/applications/_application.json.jbuilder +2 -0
  39. data/examples/rails_example/app/views/applications/_form.html.erb +19 -0
  40. data/examples/rails_example/app/views/applications/edit.html.erb +6 -0
  41. data/examples/rails_example/app/views/applications/index.html.erb +25 -0
  42. data/examples/rails_example/app/views/applications/index.json.jbuilder +1 -0
  43. data/examples/rails_example/app/views/applications/new.html.erb +5 -0
  44. data/examples/rails_example/app/views/applications/show.html.erb +7 -0
  45. data/examples/rails_example/app/views/applications/show.json.jbuilder +1 -0
  46. data/examples/rails_example/app/views/authors/_author.json.jbuilder +2 -0
  47. data/examples/rails_example/app/views/authors/_form.html.erb +19 -0
  48. data/examples/rails_example/app/views/authors/edit.html.erb +6 -0
  49. data/examples/rails_example/app/views/authors/index.html.erb +25 -0
  50. data/examples/rails_example/app/views/authors/index.json.jbuilder +1 -0
  51. data/examples/rails_example/app/views/authors/new.html.erb +5 -0
  52. data/examples/rails_example/app/views/authors/show.html.erb +4 -0
  53. data/examples/rails_example/app/views/authors/show.json.jbuilder +1 -0
  54. data/examples/rails_example/app/views/books/_book.json.jbuilder +2 -0
  55. data/examples/rails_example/app/views/books/_form.html.erb +19 -0
  56. data/examples/rails_example/app/views/books/edit.html.erb +6 -0
  57. data/examples/rails_example/app/views/books/index.html.erb +25 -0
  58. data/examples/rails_example/app/views/books/index.json.jbuilder +1 -0
  59. data/examples/rails_example/app/views/books/new.html.erb +5 -0
  60. data/examples/rails_example/app/views/books/show.html.erb +4 -0
  61. data/examples/rails_example/app/views/books/show.json.jbuilder +1 -0
  62. data/examples/rails_example/app/views/libraries/_form.html.erb +19 -0
  63. data/examples/rails_example/app/views/libraries/_library.json.jbuilder +2 -0
  64. data/examples/rails_example/app/views/libraries/edit.html.erb +6 -0
  65. data/examples/rails_example/app/views/libraries/index.html.erb +25 -0
  66. data/examples/rails_example/app/views/libraries/index.json.jbuilder +1 -0
  67. data/examples/rails_example/app/views/libraries/new.html.erb +5 -0
  68. data/examples/rails_example/app/views/libraries/show.html.erb +4 -0
  69. data/examples/rails_example/app/views/libraries/show.json.jbuilder +1 -0
  70. data/examples/rails_example/config/initializers/grape.rb +2 -0
  71. data/examples/rails_example/config/initializers/sandboxy.rb +13 -0
  72. data/examples/rails_example/config/routes.rb +9 -3
  73. data/examples/rails_example/config/secrets.yml +2 -2
  74. data/examples/rails_example/db/migrate/20170827184048_create_books.rb +9 -0
  75. data/examples/rails_example/db/migrate/20170827184054_create_authors.rb +9 -0
  76. data/examples/rails_example/db/migrate/20170827184106_create_libraries.rb +9 -0
  77. data/examples/rails_example/db/migrate/20170827184304_create_applications.rb +11 -0
  78. data/examples/rails_example/db/migrate/{20170827105828_sandboxy_migration.rb → 20170827190815_sandboxy_migration.rb} +0 -0
  79. data/examples/rails_example/db/schema.rb +19 -3
  80. data/examples/rails_example/test/controllers/applications_controller_test.rb +48 -0
  81. data/examples/rails_example/test/controllers/authors_controller_test.rb +48 -0
  82. data/examples/rails_example/test/controllers/books_controller_test.rb +48 -0
  83. data/examples/rails_example/test/controllers/libraries_controller_test.rb +48 -0
  84. data/examples/rails_example/test/controllers/sandbox_controller_test.rb +7 -0
  85. data/examples/rails_example/test/fixtures/{bars.yml → applications.yml} +0 -0
  86. data/examples/rails_example/test/fixtures/{foos.yml → authors.yml} +0 -0
  87. data/examples/rails_example/test/fixtures/books.yml +11 -0
  88. data/examples/rails_example/test/fixtures/libraries.yml +11 -0
  89. data/examples/rails_example/test/models/application_test.rb +7 -0
  90. data/examples/rails_example/test/models/{bar_test.rb → author_test.rb} +1 -1
  91. data/examples/rails_example/test/models/{foo_test.rb → book_test.rb} +1 -1
  92. data/examples/rails_example/test/models/library_test.rb +7 -0
  93. data/examples/rails_example/test/system/applications_test.rb +9 -0
  94. data/examples/rails_example/test/system/authors_test.rb +9 -0
  95. data/examples/rails_example/test/system/books_test.rb +9 -0
  96. data/examples/rails_example/test/system/libraries_test.rb +9 -0
  97. data/lib/generators/sandboxy_generator.rb +4 -6
  98. data/lib/generators/templates/initializer.rb +13 -0
  99. data/lib/sandboxy/configuration.rb +11 -34
  100. data/lib/sandboxy/middleware.rb +3 -3
  101. data/lib/sandboxy/railtie.rb +3 -3
  102. data/lib/sandboxy/version.rb +1 -1
  103. data/lib/sandboxy.rb +12 -3
  104. data/sandboxy.gemspec +4 -6
  105. data/test/dummy30/config/initializers/sandboxy.rb +13 -0
  106. data/test/test_helper.rb +0 -2
  107. metadata +93 -78
  108. data/examples/rails_example/app/controllers/bars_controller.rb +0 -74
  109. data/examples/rails_example/app/controllers/foos_controller.rb +0 -74
  110. data/examples/rails_example/app/helpers/bars_helper.rb +0 -2
  111. data/examples/rails_example/app/helpers/foos_helper.rb +0 -2
  112. data/examples/rails_example/app/models/bar.rb +0 -2
  113. data/examples/rails_example/app/models/foo.rb +0 -2
  114. data/examples/rails_example/app/models/shared_sandbox.rb +0 -3
  115. data/examples/rails_example/app/views/bars/_bar.json.jbuilder +0 -2
  116. data/examples/rails_example/app/views/bars/_form.html.erb +0 -17
  117. data/examples/rails_example/app/views/bars/edit.html.erb +0 -6
  118. data/examples/rails_example/app/views/bars/index.html.erb +0 -25
  119. data/examples/rails_example/app/views/bars/index.json.jbuilder +0 -1
  120. data/examples/rails_example/app/views/bars/new.html.erb +0 -5
  121. data/examples/rails_example/app/views/bars/show.html.erb +0 -4
  122. data/examples/rails_example/app/views/bars/show.json.jbuilder +0 -1
  123. data/examples/rails_example/app/views/foos/_foo.json.jbuilder +0 -2
  124. data/examples/rails_example/app/views/foos/_form.html.erb +0 -17
  125. data/examples/rails_example/app/views/foos/edit.html.erb +0 -6
  126. data/examples/rails_example/app/views/foos/index.html.erb +0 -25
  127. data/examples/rails_example/app/views/foos/index.json.jbuilder +0 -1
  128. data/examples/rails_example/app/views/foos/new.html.erb +0 -5
  129. data/examples/rails_example/app/views/foos/show.html.erb +0 -4
  130. data/examples/rails_example/app/views/foos/show.json.jbuilder +0 -1
  131. data/examples/rails_example/config/sandboxy.yml +0 -13
  132. data/examples/rails_example/db/migrate/20170826223227_create_foos.rb +0 -8
  133. data/examples/rails_example/db/migrate/20170826223243_create_bars.rb +0 -8
  134. data/examples/rails_example/test/controllers/bars_controller_test.rb +0 -48
  135. data/examples/rails_example/test/controllers/foos_controller_test.rb +0 -48
  136. data/examples/rails_example/test/system/bars_test.rb +0 -9
  137. data/examples/rails_example/test/system/foos_test.rb +0 -9
  138. data/lib/generators/templates/configuration.yml.erb +0 -13
@@ -0,0 +1,77 @@
1
+ class LibrariesController < ApplicationController
2
+ before_action :set_library, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /libraries
5
+ # GET /libraries.json
6
+ def index
7
+ $sandbox = session[:sandbox]
8
+ @libraries = Library.all
9
+ end
10
+
11
+ # GET /libraries/1
12
+ # GET /libraries/1.json
13
+ def show
14
+ end
15
+
16
+ # GET /libraries/new
17
+ def new
18
+ $sandbox = session[:sandbox]
19
+ @library = Library.new
20
+ end
21
+
22
+ # GET /libraries/1/edit
23
+ def edit
24
+ end
25
+
26
+ # POST /libraries
27
+ # POST /libraries.json
28
+ def create
29
+ $sandbox = session[:sandbox]
30
+ @library = Library.new(library_params)
31
+
32
+ respond_to do |format|
33
+ if @library.save
34
+ format.html { redirect_to @library, notice: 'Library was successfully created.' }
35
+ format.json { render :show, status: :created, location: @library }
36
+ else
37
+ format.html { render :new }
38
+ format.json { render json: @library.errors, status: :unprocessable_entity }
39
+ end
40
+ end
41
+ end
42
+
43
+ # PATCH/PUT /libraries/1
44
+ # PATCH/PUT /libraries/1.json
45
+ def update
46
+ respond_to do |format|
47
+ if @library.update(library_params)
48
+ format.html { redirect_to @library, notice: 'Library was successfully updated.' }
49
+ format.json { render :show, status: :ok, location: @library }
50
+ else
51
+ format.html { render :edit }
52
+ format.json { render json: @library.errors, status: :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # DELETE /libraries/1
58
+ # DELETE /libraries/1.json
59
+ def destroy
60
+ @library.destroy
61
+ respond_to do |format|
62
+ format.html { redirect_to libraries_url, notice: 'Library was successfully destroyed.' }
63
+ format.json { head :no_content }
64
+ end
65
+ end
66
+
67
+ private
68
+ # Use callbacks to share common setup or constraints between actions.
69
+ def set_library
70
+ @library = Library.find(params[:id])
71
+ end
72
+
73
+ # Never trust parameters from the scary internet, only allow the white list through.
74
+ def library_params
75
+ params.fetch(:library, {})
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ class SandboxController < ApplicationController
2
+ def edit
3
+ session[:sandbox] == !session[:sandbox]
4
+ redirect_to root_url
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module AuthorsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module BooksHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module LibrariesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module SandboxHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ class Application < ApplicationRecord
2
+ before_create :create_access_tokens
3
+
4
+ private
5
+
6
+ def create_access_tokens
7
+ begin
8
+ self.access_token = SecureRandom.hex(32)
9
+ end while self.class.where(access_token: self.access_token, sandbox_access_token: self.access_token).exists?
10
+ begin
11
+ self.sandbox_access_token = SecureRandom.hex(32)
12
+ end while self.class.where(sandbox_access_token: self.sandbox_access_token, access_token: self.sandbox_access_token).exists?
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ class Author < ApplicationRecord
2
+ end
@@ -0,0 +1,2 @@
1
+ class Book < ApplicationRecord
2
+ end
@@ -0,0 +1,2 @@
1
+ class Library < ApplicationRecord
2
+ end
@@ -0,0 +1,2 @@
1
+ json.extract! application, :id, :created_at, :updated_at
2
+ json.url application_url(application, format: :json)
@@ -0,0 +1,19 @@
1
+ <%= form_with(model: application, local: true) do |form| %>
2
+ <% if application.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(application.errors.count, "error") %> prohibited this application from being saved:</h2>
5
+
6
+ <ul>
7
+ <% application.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= form.input :name %>
15
+
16
+ <div class="actions">
17
+ <%= form.submit %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Application</h1>
2
+
3
+ <%= render 'form', application: @application %>
4
+
5
+ <%= link_to 'Show', @application %> |
6
+ <%= link_to 'Back', applications_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Applications</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @applications.each do |application| %>
14
+ <tr>
15
+ <td><%= link_to 'Show', application %></td>
16
+ <td><%= link_to 'Edit', edit_application_path(application) %></td>
17
+ <td><%= link_to 'Destroy', application, method: :delete, data: { confirm: 'Are you sure?' } %></td>
18
+ </tr>
19
+ <% end %>
20
+ </tbody>
21
+ </table>
22
+
23
+ <br>
24
+
25
+ <%= link_to 'New Application', new_application_path %>
@@ -0,0 +1 @@
1
+ json.array! @applications, partial: 'applications/application', as: :application
@@ -0,0 +1,5 @@
1
+ <h1>New Application</h1>
2
+
3
+ <%= render 'form', application: @application %>
4
+
5
+ <%= link_to 'Back', applications_path %>
@@ -0,0 +1,7 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_application_path(@application) %> |
4
+ <%= link_to 'Back', applications_path %>
5
+
6
+ Live Access Token: <%= @application.access_token %>
7
+ Sandbox Access Token: <%= @application.sandbox_access_token %>
@@ -0,0 +1 @@
1
+ json.partial! "applications/application", application: @application
@@ -0,0 +1,2 @@
1
+ json.extract! author, :id, :created_at, :updated_at
2
+ json.url author_url(author, format: :json)
@@ -0,0 +1,19 @@
1
+ <%= form_with(model: author, local: true) do |form| %>
2
+ <% if author.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(author.errors.count, "error") %> prohibited this author from being saved:</h2>
5
+
6
+ <ul>
7
+ <% author.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= form.input :name %>
15
+
16
+ <div class="actions">
17
+ <%= form.submit %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Author</h1>
2
+
3
+ <%= render 'form', author: @author %>
4
+
5
+ <%= link_to 'Show', @author %> |
6
+ <%= link_to 'Back', authors_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Authors</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @authors.each do |author| %>
14
+ <tr>
15
+ <td><%= link_to 'Show', author %></td>
16
+ <td><%= link_to 'Edit', edit_author_path(author) %></td>
17
+ <td><%= link_to 'Destroy', author, method: :delete, data: { confirm: 'Are you sure?' } %></td>
18
+ </tr>
19
+ <% end %>
20
+ </tbody>
21
+ </table>
22
+
23
+ <br>
24
+
25
+ <%= link_to 'New Author', new_author_path %>
@@ -0,0 +1 @@
1
+ json.array! @authors, partial: 'authors/author', as: :author
@@ -0,0 +1,5 @@
1
+ <h1>New Author</h1>
2
+
3
+ <%= render 'form', author: @author %>
4
+
5
+ <%= link_to 'Back', authors_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_author_path(@author) %> |
4
+ <%= link_to 'Back', authors_path %>
@@ -0,0 +1 @@
1
+ json.partial! "authors/author", author: @author
@@ -0,0 +1,2 @@
1
+ json.extract! book, :id, :created_at, :updated_at
2
+ json.url book_url(book, format: :json)
@@ -0,0 +1,19 @@
1
+ <%= form_with(model: book, local: true) do |form| %>
2
+ <% if book.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(book.errors.count, "error") %> prohibited this book from being saved:</h2>
5
+
6
+ <ul>
7
+ <% book.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= form.input :name %>
15
+
16
+ <div class="actions">
17
+ <%= form.submit %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Book</h1>
2
+
3
+ <%= render 'form', book: @book %>
4
+
5
+ <%= link_to 'Show', @book %> |
6
+ <%= link_to 'Back', books_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Books</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @books.each do |book| %>
14
+ <tr>
15
+ <td><%= link_to 'Show', book %></td>
16
+ <td><%= link_to 'Edit', edit_book_path(book) %></td>
17
+ <td><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %></td>
18
+ </tr>
19
+ <% end %>
20
+ </tbody>
21
+ </table>
22
+
23
+ <br>
24
+
25
+ <%= link_to 'New Book', new_book_path %>
@@ -0,0 +1 @@
1
+ json.array! @books, partial: 'books/book', as: :book
@@ -0,0 +1,5 @@
1
+ <h1>New Book</h1>
2
+
3
+ <%= render 'form', book: @book %>
4
+
5
+ <%= link_to 'Back', books_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_book_path(@book) %> |
4
+ <%= link_to 'Back', books_path %>
@@ -0,0 +1 @@
1
+ json.partial! "books/book", book: @book
@@ -0,0 +1,19 @@
1
+ <%= form_with(model: library, local: true) do |form| %>
2
+ <% if library.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(library.errors.count, "error") %> prohibited this library from being saved:</h2>
5
+
6
+ <ul>
7
+ <% library.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= form.input :name %>
15
+
16
+ <div class="actions">
17
+ <%= form.submit %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,2 @@
1
+ json.extract! library, :id, :created_at, :updated_at
2
+ json.url library_url(library, format: :json)
@@ -0,0 +1,6 @@
1
+ <h1>Editing Library</h1>
2
+
3
+ <%= render 'form', library: @library %>
4
+
5
+ <%= link_to 'Show', @library %> |
6
+ <%= link_to 'Back', libraries_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Libraries</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @libraries.each do |library| %>
14
+ <tr>
15
+ <td><%= link_to 'Show', library %></td>
16
+ <td><%= link_to 'Edit', edit_library_path(library) %></td>
17
+ <td><%= link_to 'Destroy', library, method: :delete, data: { confirm: 'Are you sure?' } %></td>
18
+ </tr>
19
+ <% end %>
20
+ </tbody>
21
+ </table>
22
+
23
+ <br>
24
+
25
+ <%= link_to 'New Library', new_library_path %>
@@ -0,0 +1 @@
1
+ json.array! @libraries, partial: 'libraries/library', as: :library
@@ -0,0 +1,5 @@
1
+ <h1>New Library</h1>
2
+
3
+ <%= render 'form', library: @library %>
4
+
5
+ <%= link_to 'Back', libraries_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_library_path(@library) %> |
4
+ <%= link_to 'Back', libraries_path %>
@@ -0,0 +1 @@
1
+ json.partial! "libraries/library", library: @library
@@ -0,0 +1,2 @@
1
+ Rails.application.config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
2
+ Rails.application.config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
@@ -0,0 +1,13 @@
1
+ Sandboxy.configure do |config|
2
+
3
+ # Set your environment default: Must be either `live` or `sandbox`.
4
+ # This is the environment that your app boots with.
5
+ # By default it gets refreshed with every new request to your server.
6
+ # config.environment = 'live'
7
+
8
+ # Specify whether to retain your current app environment on new requests.
9
+ # If set to true, your app will only load your environment default when starting.
10
+ # Every additional switch of your environment at runtime will then not be automatically resolved to your environment default on a new request.
11
+ # config.retain_environment = false
12
+
13
+ end
@@ -1,7 +1,13 @@
1
1
  Rails.application.routes.draw do
2
- resources :bars
3
- resources :foos
2
+ mount Books::API => '/api'
4
3
 
5
- root 'foos#index'
4
+ resources :applications
5
+ resources :libraries
6
+ resources :authors
7
+ resources :books
8
+
9
+ root 'libraries#index'
10
+
11
+ get 'switch-environments', to: 'sandbox#edit'
6
12
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
7
13
  end
@@ -18,10 +18,10 @@
18
18
  # Environmental secrets are only available for that specific environment.
19
19
 
20
20
  development:
21
- secret_key_base: 4e0b28be813a86fc3a1d1e0477c4923676fe18e7facadbea587f21aef1fbaa94084282265fac12c2e3a06edb6ba775beec38ba5bd4aa82fd1cdf6c30eff086d3
21
+ secret_key_base: def380439341bd8d1fe444db27e4faa1626b39097220af40dd6fb6e99fff10cec00d782dda094b4ebda0f45fa9578d42110534d2e35b2240f418586e44aa12bf
22
22
 
23
23
  test:
24
- secret_key_base: f54b8ff9aad462876cea1072ca41197d9fd17f79a77a76499dac2c472ccbb4be303991866328461a104d0a257e85c010e4403c34d8fddf8b146cf8dc65984d31
24
+ secret_key_base: 269bf1f079ced783a42ff334f462b938b9d704748377e180023443a761c513437c06b6c7958cb6d19bc1826ee9ced849f295cb47a6c586a85be13a67a3d9101a
25
25
 
26
26
  # Do not keep production secrets in the unencrypted secrets file.
27
27
  # Instead, either read values from the environment.
@@ -0,0 +1,9 @@
1
+ class CreateBooks < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :books do |t|
4
+ t.string :name, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAuthors < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :authors do |t|
4
+ t.string :name, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateLibraries < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :libraries do |t|
4
+ t.string :name, null: false
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateApplications < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :applications do |t|
4
+ t.string :name, null: false
5
+ t.string :access_token, null: false
6
+ t.string :sandbox_access_token, null: false
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -10,14 +10,30 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20170827105828) do
13
+ ActiveRecord::Schema.define(version: 20170827190815) do
14
14
 
15
- create_table "bars", force: :cascade do |t|
15
+ create_table "applications", force: :cascade do |t|
16
+ t.string "name", null: false
17
+ t.string "access_token", null: false
18
+ t.string "sandbox_access_token", null: false
16
19
  t.datetime "created_at", null: false
17
20
  t.datetime "updated_at", null: false
18
21
  end
19
22
 
20
- create_table "foos", force: :cascade do |t|
23
+ create_table "authors", force: :cascade do |t|
24
+ t.string "name", null: false
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ end
28
+
29
+ create_table "books", force: :cascade do |t|
30
+ t.string "name", null: false
31
+ t.datetime "created_at", null: false
32
+ t.datetime "updated_at", null: false
33
+ end
34
+
35
+ create_table "libraries", force: :cascade do |t|
36
+ t.string "name", null: false
21
37
  t.datetime "created_at", null: false
22
38
  t.datetime "updated_at", null: false
23
39
  end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class ApplicationsControllerTest < ActionDispatch::IntegrationTest
4
+ setup do
5
+ @application = applications(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get applications_url
10
+ assert_response :success
11
+ end
12
+
13
+ test "should get new" do
14
+ get new_application_url
15
+ assert_response :success
16
+ end
17
+
18
+ test "should create application" do
19
+ assert_difference('Application.count') do
20
+ post applications_url, params: { application: { } }
21
+ end
22
+
23
+ assert_redirected_to application_url(Application.last)
24
+ end
25
+
26
+ test "should show application" do
27
+ get application_url(@application)
28
+ assert_response :success
29
+ end
30
+
31
+ test "should get edit" do
32
+ get edit_application_url(@application)
33
+ assert_response :success
34
+ end
35
+
36
+ test "should update application" do
37
+ patch application_url(@application), params: { application: { } }
38
+ assert_redirected_to application_url(@application)
39
+ end
40
+
41
+ test "should destroy application" do
42
+ assert_difference('Application.count', -1) do
43
+ delete application_url(@application)
44
+ end
45
+
46
+ assert_redirected_to applications_url
47
+ end
48
+ end