Class: Test::Spec::Rails::Macros::Authorization::TestGenerator

Inherits:
Proxy
  • Object
show all
Defined in:
lib/test/spec/rails/macros/authorization.rb

Instance Attribute Summary collapse

Attributes inherited from Proxy

#test_case

Instance Method Summary collapse

Constructor Details

#initialize(test_case, validation_method, expected, message) ⇒ TestGenerator

Returns a new instance of TestGenerator.



48
49
50
51
52
53
54
# File 'lib/test/spec/rails/macros/authorization.rb', line 48

def initialize(test_case, validation_method, expected, message)
  self.validation_method = validation_method
  self.expected = expected
  self.message = message
  
  super(test_case)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(verb, action, params = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/test/spec/rails/macros/authorization.rb', line 56

def method_missing(verb, action, params={})
  if [:get, :post, :put, :delete, :options].include?(verb.to_sym)
    description = "should disallow #{verb.to_s.upcase} on `#{action}'"
    description << " #{params.inspect}" unless params.blank?
    
    validation_method = self.validation_method
    expected = self.expected
    message = self.message
    
    test_case.it description do
      send(verb, action, immediate_values(params))
      send(validation_method).should.messaging(message) == expected
    end
  else
    super
  end
end

Instance Attribute Details

#expectedObject

Returns the value of attribute expected.



46
47
48
# File 'lib/test/spec/rails/macros/authorization.rb', line 46

def expected
  @expected
end

#messageObject

Returns the value of attribute message.



46
47
48
# File 'lib/test/spec/rails/macros/authorization.rb', line 46

def message
  @message
end

#validation_methodObject

Returns the value of attribute validation_method.



46
47
48
# File 'lib/test/spec/rails/macros/authorization.rb', line 46

def validation_method
  @validation_method
end