trax_controller 0.0.4 → 0.1.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/lib/trax/controller/action_types.rb +2 -12
- data/lib/trax/controller/actions.rb +6 -1
- data/lib/trax_controller/version.rb +1 -1
- data/spec/internal/app/policies/widget_policy.rb +1 -1
- data/spec/trax/controller/authorization/pundit_spec.rb +25 -0
- metadata +2 -4
- data/spec/internal/db/combustion_test.sqlite +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6d61bb93ac569a174d291f54084d306a6726c3bc
         | 
| 4 | 
            +
              data.tar.gz: ca40fc02d4b101efe9d9d27498a926bb26a5dd1f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4495db797d01bcfd38f2e258b82049e4ccf390d328319e945d8aacad9e66310b682d33150c8e050f8727ea4d97d342baccf1ac4edda0fefc10042c957e8c7273
         | 
| 7 | 
            +
              data.tar.gz: 8185f4a78f4ac4577dbfdda77e72d70f2e4151817855ab2c04febe70da0b95f03292819686f8e0f2f0a64020da21872cdb72bfb8812b528c7a8453c568c81d77
         | 
| @@ -2,27 +2,17 @@ module Trax | |
| 2 2 | 
             
              module Controller
         | 
| 3 3 | 
             
                module ActionTypes
         | 
| 4 4 | 
             
                  extend ::ActiveSupport::Concern
         | 
| 5 | 
            -
                  #todo: pretty janky but works for now
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                  included do
         | 
| 8 | 
            -
                    class_attribute :action_types
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                    self.action_types = Hashie::Mash.new({
         | 
| 11 | 
            -
                      :collection => [:index, :search],
         | 
| 12 | 
            -
                      :resource => [ :show, :delete, :update, :create, :login ]
         | 
| 13 | 
            -
                    })
         | 
| 14 | 
            -
                  end
         | 
| 15 5 |  | 
| 16 6 | 
             
                  def current_action
         | 
| 17 7 | 
             
                    :"#{request.params["action"]}"
         | 
| 18 8 | 
             
                  end
         | 
| 19 9 |  | 
| 20 10 | 
             
                  def collection_action?
         | 
| 21 | 
            -
                     | 
| 11 | 
            +
                    !!get_collection_ivar
         | 
| 22 12 | 
             
                  end
         | 
| 23 13 |  | 
| 24 14 | 
             
                  def resource_action?
         | 
| 25 | 
            -
                     | 
| 15 | 
            +
                    !!get_resource_ivar
         | 
| 26 16 | 
             
                  end
         | 
| 27 17 | 
             
                end
         | 
| 28 18 | 
             
              end
         | 
| @@ -99,7 +99,12 @@ module Trax | |
| 99 99 | 
             
                  end
         | 
| 100 100 |  | 
| 101 101 | 
             
                  def render_errors(status = :unprocessable_entity, error_messages_hash:{}, **options)
         | 
| 102 | 
            -
                    errors =  | 
| 102 | 
            +
                    errors = if resource_action?
         | 
| 103 | 
            +
                      error_messages_hash.merge(resource_error_messages(**options) || {})
         | 
| 104 | 
            +
                    else
         | 
| 105 | 
            +
                      error_messages_hash.merge({})
         | 
| 106 | 
            +
                    end
         | 
| 107 | 
            +
             | 
| 103 108 | 
             
                    render json: { meta: { errors: errors } }, status: status, serializer: nil
         | 
| 104 109 | 
             
                  end
         | 
| 105 110 |  | 
| @@ -104,6 +104,31 @@ require 'spec_helper' | |
| 104 104 | 
             
                    end
         | 
| 105 105 | 
             
                  end
         | 
| 106 106 |  | 
| 107 | 
            +
                  describe '#index' do
         | 
| 108 | 
            +
                    context 'user can read widgets' do
         | 
| 109 | 
            +
                      let(:current_user) { user_who_can[:read_widgets] }
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                      it 'is authorized' do
         | 
| 112 | 
            +
                        get :index, common_params
         | 
| 113 | 
            +
                        expect(response).to be_ok
         | 
| 114 | 
            +
                        json = JSON.parse response.body
         | 
| 115 | 
            +
                        expect(json).to have_key('widgets')
         | 
| 116 | 
            +
                      end
         | 
| 117 | 
            +
                    end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                    context 'user cannot read widgets' do
         | 
| 120 | 
            +
                      let(:current_user) { user_who_cannot[:read_widgets] }
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                      it do
         | 
| 123 | 
            +
                        get :index, common_params
         | 
| 124 | 
            +
                        json = JSON.parse response.body
         | 
| 125 | 
            +
                        expect(response).to_not be_ok
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                        unauthorized_result_expectations.call(json)
         | 
| 128 | 
            +
                      end
         | 
| 129 | 
            +
                    end
         | 
| 130 | 
            +
                  end
         | 
| 131 | 
            +
             | 
| 107 132 | 
             
                  describe '#create' do
         | 
| 108 133 | 
             
                    context "user can create widgets" do
         | 
| 109 134 | 
             
                      let(:current_user) { user_who_can[:create_widgets] }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: trax_controller
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jason Ayre
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-04- | 
| 11 | 
            +
            date: 2016-04-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: trax_core
         | 
| @@ -356,7 +356,6 @@ files: | |
| 356 356 | 
             
            - spec/internal/app/serializers/widget_serializer.rb
         | 
| 357 357 | 
             
            - spec/internal/config/database.yml
         | 
| 358 358 | 
             
            - spec/internal/config/routes.rb
         | 
| 359 | 
            -
            - spec/internal/db/combustion_test.sqlite
         | 
| 360 359 | 
             
            - spec/internal/db/schema.rb
         | 
| 361 360 | 
             
            - spec/internal/log/.gitignore
         | 
| 362 361 | 
             
            - spec/internal/public/favicon.ico
         | 
| @@ -408,7 +407,6 @@ test_files: | |
| 408 407 | 
             
            - spec/internal/app/serializers/widget_serializer.rb
         | 
| 409 408 | 
             
            - spec/internal/config/database.yml
         | 
| 410 409 | 
             
            - spec/internal/config/routes.rb
         | 
| 411 | 
            -
            - spec/internal/db/combustion_test.sqlite
         | 
| 412 410 | 
             
            - spec/internal/db/schema.rb
         | 
| 413 411 | 
             
            - spec/internal/log/.gitignore
         | 
| 414 412 | 
             
            - spec/internal/public/favicon.ico
         | 
| Binary file |