Class: RSpec::Resources::DSL::Actions::IncludeIfNeeded

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/resources/dsl/actions/include_if_needed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, action) ⇒ IncludeIfNeeded

Returns a new instance of IncludeIfNeeded.



8
9
10
11
# File 'lib/rspec/resources/dsl/actions/include_if_needed.rb', line 8

def initialize(context, action)
  @ctx = context
  @action = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



13
14
15
# File 'lib/rspec/resources/dsl/actions/include_if_needed.rb', line 13

def action
  @action
end

Instance Method Details

#auth_examplesObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/resources/dsl/actions/include_if_needed.rb', line 15

def auth_examples
  with_meta_for :it_needs_authentication do |incl_meta|
    context 'when authentication is missing' do
      let(incl_meta[:headers]) { {} }

      it "denies access with status code #{incl_meta[:error_status]}" do
        expect(response).to have_http_status(incl_meta[:error_status])
      end
    end
  end
end

#restricted_examplesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec/resources/dsl/actions/include_if_needed.rb', line 27

def restricted_examples
  with_meta_for :it_has_restricted_access do |incl_meta|
    case action
    when :index then restricted_index_examples incl_meta
    when :create then restricted_create_examples incl_meta
    else
      context 'when trying to access a restricted resource' do
        subject { send incl_meta[:for_resource] }

        it "denies access with status code #{incl_meta[:error_status]}" do
          expect(response).to have_http_status(incl_meta[:error_status])
        end
      end
    end
  end
end