rails-api 0.2.1 → 0.3.0
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 +4 -4
- data/README.md +2 -2
- data/lib/rails-api.rb +1 -0
- data/lib/rails-api/action_controller/api.rb +4 -0
- data/lib/rails-api/application.rb +4 -3
- data/lib/rails-api/templates/rails/app/Gemfile +3 -1
- data/lib/rails-api/templates/rails/scaffold_controller/controller.rb +12 -2
- data/lib/rails-api/version.rb +1 -1
- data/test/generators/scaffold_generator_test.rb +7 -3
- metadata +12 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b28c4566c34870ed999653a0e313daf06bd1b0da
         | 
| 4 | 
            +
              data.tar.gz: f7c2d51b73e60f0f557e93c7f672b0087a4751c3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9dc88bdd19ab2495b8e53e52b4431474e9e9f112177ec6d6a5cbf6248e6a764b921e27b3d19a231431a69b622fa83bde76a22c94806d31db8fbfc38fab2bd84e
         | 
| 7 | 
            +
              data.tar.gz: 988cec2b4327f322fbcb1c365e06c23708d0e92bf4272b099b3fc73a7dfae234acf8fdca925c2cfaf4f76a39dc8a7b840c4326c856c0cc3f9c46739267ea9886
         | 
    
        data/README.md
    CHANGED
    
    | @@ -131,7 +131,7 @@ class ApplicationController < ActionController::API | |
| 131 131 | 
             
            end
         | 
| 132 132 | 
             
            ```
         | 
| 133 133 |  | 
| 134 | 
            -
            And comment out the `protect_from_forgery` call if you are using it.
         | 
| 134 | 
            +
            And comment out the `protect_from_forgery` call if you are using it. (You aren't using cookie-based authentication for your API, are you?)
         | 
| 135 135 |  | 
| 136 136 | 
             
            If you want to use the Rails default middleware stack (avoid the reduction that rails-api does), you can just add config.api_only = false to config/application.rb file.
         | 
| 137 137 |  | 
| @@ -220,7 +220,7 @@ Some common modules you might want to add: | |
| 220 220 |  | 
| 221 221 | 
             
            * *AbstractController::Translation*: Support for the *l* and *t* localization and translation methods. These delegate to *I18n.translate* and *I18n.localize*.
         | 
| 222 222 | 
             
            * *ActionController::HttpAuthentication::Basic::ControllerMethods* (or *Digest* or *Token*): Support for basic, digest or token HTTP authentication.
         | 
| 223 | 
            -
            * * | 
| 223 | 
            +
            * *ActionView::Layouts*: Support for layouts when rendering.
         | 
| 224 224 | 
             
            * *ActionController::MimeResponds* (and *ActionController::ImplicitRender* for Rails 4): Support for content negotiation (*respond_to*, *respond_with*).
         | 
| 225 225 | 
             
            * *ActionController::Cookies*: Support for *cookies*, which includes support for signed and encrypted cookies. This requires the cookie middleware.
         | 
| 226 226 |  | 
    
        data/lib/rails-api.rb
    CHANGED
    
    
| @@ -1,15 +1,16 @@ | |
| 1 | 
            -
            require 'rails/version'
         | 
| 2 1 | 
             
            require 'rails/application'
         | 
| 3 2 | 
             
            require 'rails-api/public_exceptions'
         | 
| 4 3 | 
             
            require 'rails-api/application/default_rails_four_middleware_stack'
         | 
| 5 4 |  | 
| 6 5 | 
             
            module Rails
         | 
| 7 6 | 
             
              class Application < Engine
         | 
| 7 | 
            +
                alias_method :rails_default_middleware_stack, :default_middleware_stack
         | 
| 8 | 
            +
             | 
| 8 9 | 
             
                def default_middleware_stack
         | 
| 9 10 | 
             
                  if Rails::API.rails4?
         | 
| 10 11 | 
             
                    DefaultRailsFourMiddlewareStack.new(self, config, paths).build_stack
         | 
| 11 12 | 
             
                  else
         | 
| 12 | 
            -
                     | 
| 13 | 
            +
                    rails_3_stack
         | 
| 13 14 | 
             
                  end
         | 
| 14 15 | 
             
                end
         | 
| 15 16 |  | 
| @@ -37,7 +38,7 @@ module Rails | |
| 37 38 | 
             
                  setup_generators!
         | 
| 38 39 | 
             
                end
         | 
| 39 40 |  | 
| 40 | 
            -
                def  | 
| 41 | 
            +
                def rails_3_stack
         | 
| 41 42 | 
             
                  ActionDispatch::MiddlewareStack.new.tap do |middleware|
         | 
| 42 43 | 
             
                    if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
         | 
| 43 44 | 
             
                      require "action_dispatch/http/rack_cache"
         | 
| @@ -4,9 +4,11 @@ source 'https://rubygems.org' | |
| 4 4 | 
             
            <%= rails_gemfile_entry %>
         | 
| 5 5 | 
             
            <%- else -%>
         | 
| 6 6 | 
             
            <%- rails_gemfile_entry.each do |entry| -%>
         | 
| 7 | 
            +
            <%- if entry.respond_to?(:name) %>
         | 
| 7 8 | 
             
            gem '<%= entry.name -%>', '<%= entry.version -%>'
         | 
| 8 9 | 
             
            <%- end -%>
         | 
| 9 10 | 
             
            <%- end -%>
         | 
| 11 | 
            +
            <%- end -%>
         | 
| 10 12 |  | 
| 11 13 | 
             
            gem 'rails-api'
         | 
| 12 14 |  | 
| @@ -15,7 +17,7 @@ gem 'rails-api' | |
| 15 17 | 
             
            <%- else -%>
         | 
| 16 18 | 
             
            gem 'spring', :group => :development
         | 
| 17 19 |  | 
| 18 | 
            -
            <%- if database_gemfile_entry  | 
| 20 | 
            +
            <%- if database_gemfile_entry && database_gemfile_entry.respond_to?(:name) %>
         | 
| 19 21 | 
             
            gem '<%= database_gemfile_entry.name -%>'
         | 
| 20 22 | 
             
            <%- end -%>
         | 
| 21 23 | 
             
            <%- end -%>
         | 
| @@ -19,7 +19,7 @@ class <%= controller_class_name %>Controller < ApplicationController | |
| 19 19 | 
             
              # POST <%= route_url %>
         | 
| 20 20 | 
             
              # POST <%= route_url %>.json
         | 
| 21 21 | 
             
              def create
         | 
| 22 | 
            -
                @<%= singular_table_name %> = <%= orm_class.build(class_name, " | 
| 22 | 
            +
                @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
         | 
| 23 23 |  | 
| 24 24 | 
             
                if @<%= orm_instance.save %>
         | 
| 25 25 | 
             
                  render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %>
         | 
| @@ -33,7 +33,7 @@ class <%= controller_class_name %>Controller < ApplicationController | |
| 33 33 | 
             
              def update
         | 
| 34 34 | 
             
                @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
         | 
| 35 35 |  | 
| 36 | 
            -
                if @<%= Rails::API.rails4? ? orm_instance.update(" | 
| 36 | 
            +
                if @<%= Rails::API.rails4? ? orm_instance.update("#{singular_table_name}_params") : orm_instance.update_attributes("params[:#{singular_table_name}]") %>
         | 
| 37 37 | 
             
                  head :no_content
         | 
| 38 38 | 
             
                else
         | 
| 39 39 | 
             
                  render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
         | 
| @@ -48,5 +48,15 @@ class <%= controller_class_name %>Controller < ApplicationController | |
| 48 48 |  | 
| 49 49 | 
             
                head :no_content
         | 
| 50 50 | 
             
              end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              private
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                def <%= "#{singular_table_name}_params" %>
         | 
| 55 | 
            +
                  <%- if attributes_names.empty? -%>
         | 
| 56 | 
            +
                  params[:<%= singular_table_name %>]
         | 
| 57 | 
            +
                  <%- else -%>
         | 
| 58 | 
            +
                  params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
         | 
| 59 | 
            +
                  <%- end -%>
         | 
| 60 | 
            +
                end
         | 
| 51 61 | 
             
            end
         | 
| 52 62 | 
             
            <% end -%>
         | 
    
        data/lib/rails-api/version.rb
    CHANGED
    
    
| @@ -47,7 +47,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase | |
| 47 47 | 
             
                  end
         | 
| 48 48 |  | 
| 49 49 | 
             
                  assert_instance_method :create, content do |m|
         | 
| 50 | 
            -
                    assert_match(/@product_line = ProductLine\.new\( | 
| 50 | 
            +
                    assert_match(/@product_line = ProductLine\.new\(product_line_params\)/, m)
         | 
| 51 51 | 
             
                    assert_match(/@product_line\.save/, m)
         | 
| 52 52 | 
             
                    assert_match(/@product_line\.errors/, m)
         | 
| 53 53 | 
             
                  end
         | 
| @@ -55,9 +55,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase | |
| 55 55 | 
             
                  assert_instance_method :update, content do |m|
         | 
| 56 56 | 
             
                    assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m)
         | 
| 57 57 | 
             
                    if rails4?
         | 
| 58 | 
            -
                      assert_match(/@product_line\.update\( | 
| 58 | 
            +
                      assert_match(/@product_line\.update\(product_line_params\)/, m)
         | 
| 59 59 | 
             
                    else
         | 
| 60 | 
            -
                      assert_match(/@product_line\.update_attributes\( | 
| 60 | 
            +
                      assert_match(/@product_line\.update_attributes\(product_line_params\)/, m)
         | 
| 61 61 | 
             
                    end
         | 
| 62 62 | 
             
                    assert_match(/@product_line\.errors/, m)
         | 
| 63 63 | 
             
                  end
         | 
| @@ -66,6 +66,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase | |
| 66 66 | 
             
                    assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m)
         | 
| 67 67 | 
             
                    assert_match(/@product_line\.destroy/, m)
         | 
| 68 68 | 
             
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  assert_instance_method :product_line_params, content do |m|
         | 
| 71 | 
            +
                    assert_match(/params\.require\(:product_line\)\.permit\(:title, :product_id, :user_id\)/, m)
         | 
| 72 | 
            +
                  end
         | 
| 69 73 | 
             
                end
         | 
| 70 74 |  | 
| 71 75 | 
             
                assert_file "test/#{generated_test_functional_dir}/product_lines_controller_test.rb" do |test|
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rails-api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Santiago Pastorino and Carlos Antonio da Silva
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-10-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: actionpack
         | 
| @@ -120,17 +120,17 @@ signing_key: | |
| 120 120 | 
             
            specification_version: 4
         | 
| 121 121 | 
             
            summary: Rails for API only Applications
         | 
| 122 122 | 
             
            test_files:
         | 
| 123 | 
            +
            - test/test_helper.rb
         | 
| 123 124 | 
             
            - test/api_application/api_application_test.rb
         | 
| 124 | 
            -
            - test/api_controller/action_methods_test.rb
         | 
| 125 | 
            -
            - test/api_controller/conditional_get_test.rb
         | 
| 126 | 
            -
            - test/api_controller/data_streaming_test.rb
         | 
| 127 | 
            -
            - test/api_controller/force_ssl_test.rb
         | 
| 128 | 
            -
            - test/api_controller/redirect_to_test.rb
         | 
| 129 | 
            -
            - test/api_controller/renderers_test.rb
         | 
| 130 | 
            -
            - test/api_controller/url_for_test.rb
         | 
| 131 | 
            -
            - test/generators/app_generator_test.rb
         | 
| 132 125 | 
             
            - test/generators/fixtures/routes.rb
         | 
| 133 | 
            -
            - test/generators/generators_test_helper.rb
         | 
| 134 126 | 
             
            - test/generators/resource_generator_test.rb
         | 
| 127 | 
            +
            - test/generators/generators_test_helper.rb
         | 
| 128 | 
            +
            - test/generators/app_generator_test.rb
         | 
| 135 129 | 
             
            - test/generators/scaffold_generator_test.rb
         | 
| 136 | 
            -
            - test/ | 
| 130 | 
            +
            - test/api_controller/conditional_get_test.rb
         | 
| 131 | 
            +
            - test/api_controller/url_for_test.rb
         | 
| 132 | 
            +
            - test/api_controller/renderers_test.rb
         | 
| 133 | 
            +
            - test/api_controller/force_ssl_test.rb
         | 
| 134 | 
            +
            - test/api_controller/redirect_to_test.rb
         | 
| 135 | 
            +
            - test/api_controller/data_streaming_test.rb
         | 
| 136 | 
            +
            - test/api_controller/action_methods_test.rb
         |