Class: Alf::Rest::Test::Client

Inherits:
Object
  • Object
show all
Includes:
Payload::Client, Rack::Test::Methods
Defined in:
lib/alf/rest/test/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Payload::Client

#payload, #to_payload

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
# File 'lib/alf/rest/test/client.rb', line 8

def initialize(config)
  @config   = config
  @database = config.database
  @db_conn  = config.database.connection
  @global_headers = { "Content-Type" => "application/json" }
  @global_parameters = { }
  reset
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



19
20
21
# File 'lib/alf/rest/test/client.rb', line 19

def body
  @body
end

#databaseObject (readonly)

Returns the value of attribute database.



16
17
18
# File 'lib/alf/rest/test/client.rb', line 16

def database
  @database
end

#db_connObject (readonly)

Returns the value of attribute db_conn.



16
17
18
# File 'lib/alf/rest/test/client.rb', line 16

def db_conn
  @db_conn
end

#global_headersObject

Returns the value of attribute global_headers.



18
19
20
# File 'lib/alf/rest/test/client.rb', line 18

def global_headers
  @global_headers
end

#global_parametersObject

Returns the value of attribute global_parameters.



17
18
19
# File 'lib/alf/rest/test/client.rb', line 17

def global_parameters
  @global_parameters
end

#parametersObject

Returns the value of attribute parameters.



20
21
22
# File 'lib/alf/rest/test/client.rb', line 20

def parameters
  @parameters
end

Instance Method Details

#disconnectObject



28
29
30
# File 'lib/alf/rest/test/client.rb', line 28

def disconnect
  db_conn.close if db_conn
end

#global_header(k, v) ⇒ Object



50
51
52
# File 'lib/alf/rest/test/client.rb', line 50

def global_header(k, v)
  global_headers[k] = v
end

#headersObject



46
47
48
# File 'lib/alf/rest/test/client.rb', line 46

def headers
  current_session.headers
end

#parameter(k, v) ⇒ Object



54
55
56
# File 'lib/alf/rest/test/client.rb', line 54

def parameter(k, v)
  parameters[k] = v
end

#resetObject



22
23
24
25
26
# File 'lib/alf/rest/test/client.rb', line 22

def reset
  self.body       = nil
  self.parameters = {}
  global_headers.each{|k,v| header(k,v) }
end

#with_database {|database| ... } ⇒ Object

Yields:



32
33
34
# File 'lib/alf/rest/test/client.rb', line 32

def with_database
  yield(database)
end

#with_db_conn {|db_conn| ... } ⇒ Object

Yields:



36
37
38
# File 'lib/alf/rest/test/client.rb', line 36

def with_db_conn(&bl)
  yield(db_conn)
end

#with_relvar(*args, &bl) ⇒ Object



40
41
42
43
44
# File 'lib/alf/rest/test/client.rb', line 40

def with_relvar(*args, &bl)
  with_db_conn do |db_conn|
    yield(db_conn.relvar(*args))
  end
end