Class: TicketEvolution::TestResponse
- Inherits:
-
Object
- Object
- TicketEvolution::TestResponse
- Defined in:
- lib/ticket_evolution/core/test_response.rb
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #headers ⇒ Object
-
#initialize(path, request, base) ⇒ TestResponse
constructor
A new instance of TestResponse.
- #status ⇒ Object
- #test_response_path ⇒ Object
- #test_responses ⇒ Object
Constructor Details
#initialize(path, request, base) ⇒ TestResponse
Returns a new instance of TestResponse.
14 15 16 17 |
# File 'lib/ticket_evolution/core/test_response.rb', line 14 def initialize(path, request, base) @path = request.sub base, '' @path = "#{@path}.json" end |
Class Method Details
.connection_in_test_mode(object) ⇒ Object
3 4 5 6 |
# File 'lib/ticket_evolution/core/test_response.rb', line 3 def self.connection_in_test_mode(object) connection = self.get_connection(object) connection ? connection.config["test_responses"] : false end |
.get_connection(object) ⇒ Object
8 9 10 11 12 |
# File 'lib/ticket_evolution/core/test_response.rb', line 8 def self.get_connection(object) return object if object.is_a? TicketEvolution::Connection return false if !object.respond_to?(:parent) return self.get_connection(object.parent) end |
Instance Method Details
#body ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ticket_evolution/core/test_response.rb', line 33 def body if test_responses.include?(@path) File.open("#{test_response_path}/#{@path}").read else {} end end |
#headers ⇒ Object
41 42 43 |
# File 'lib/ticket_evolution/core/test_response.rb', line 41 def headers {'location' => '127.0.0.1'} end |
#status ⇒ Object
29 30 31 |
# File 'lib/ticket_evolution/core/test_response.rb', line 29 def status 200 end |
#test_response_path ⇒ Object
19 20 21 |
# File 'lib/ticket_evolution/core/test_response.rb', line 19 def test_response_path "#{TicketEvolution.root}/test_responses" end |
#test_responses ⇒ Object
23 24 25 26 27 |
# File 'lib/ticket_evolution/core/test_response.rb', line 23 def test_responses Dir.glob("#{test_response_path}/**/*").map { |path| path.sub test_response_path, '' } end |