Top Level Namespace

Defined Under Namespace

Modules: ArtirixDataModels

Instance Method Summary collapse

Instance Method Details

#fake_mode_for(model_name) ⇒ Object

:nocov:



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/artirix_data_models/spec_support/fake_mode.rb', line 2

def fake_mode_for(model_name)
  before(:all) do
    SimpleConfig.for(:site) do

      set :debug_model_mode_enabled, true

      group :data_fake_mode do
        set model_name, true
      end
    end
  end

  after(:all) do
    SimpleConfig.for(:site) do

      set :debug_model_mode_enabled, false

      group :data_fake_mode do
        set model_name, false
      end
    end
  end
end

#given_gateway_config(connection_url = nil) ⇒ Object

:nocov:



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 2

def given_gateway_config(connection_url = nil)
  connection_url ||= 'http://example.com/other'
  before(:all) do
    c = connection_url
    SimpleConfig.for(:site) do
      group :data_gateway do
        set :url, c
      end
    end
  end
end

#mock_gateway_delete_not_found_response(**params) ⇒ Object



105
106
107
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 105

def mock_gateway_delete_not_found_response(**params)
  mock_gateway_not_found_response method: :delete, **params
end

#mock_gateway_delete_response(**params) ⇒ Object

DELETE



101
102
103
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 101

def mock_gateway_delete_response(**params)
  mock_gateway_response method: :delete, **params
end

#mock_gateway_get_not_found_response(**params) ⇒ Object



78
79
80
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 78

def mock_gateway_get_not_found_response(**params)
  mock_gateway_not_found_response method: :get, **params
end

#mock_gateway_get_response(**params) ⇒ Object

GET



74
75
76
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 74

def mock_gateway_get_response(**params)
  mock_gateway_response method: :get, **params
end

#mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 44

def mock_gateway_not_found_response(method:,
                                    path:,
                                    body: nil,
                                    json_body: true,
                                    timeout: nil,
                                    authorization_bearer: nil,
                                    authorization_token_hash: nil,
                                    gateway: nil)

  gateway ||= ArtirixDataModels::DAORegistry.gateway

  params_hash = {
    path:                     path,
    body:                     body,
    json_body:                json_body,
    timeout:                  timeout,
    authorization_bearer:     authorization_bearer,
    authorization_token_hash: authorization_token_hash
  }

  allow(gateway).to receive(:perform).with(method, params_hash).and_raise ArtirixDataModels::DataGateway::NotFound

  # check with body already parsed
  unless body.nil?
    body = body.kind_of?(String) ? body : body.to_json
    allow(gateway).to receive(:perform).with(method, params_hash.merge(body: body)).and_raise ArtirixDataModels::DataGateway::NotFound
  end
end

#mock_gateway_post_not_found_response(**params) ⇒ Object



87
88
89
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 87

def mock_gateway_post_not_found_response(**params)
  mock_gateway_not_found_response method: :post, **params
end

#mock_gateway_post_response(**params) ⇒ Object

POST



83
84
85
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 83

def mock_gateway_post_response(**params)
  mock_gateway_response method: :post, **params
end

#mock_gateway_put_not_found_response(**params) ⇒ Object



96
97
98
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 96

def mock_gateway_put_not_found_response(**params)
  mock_gateway_not_found_response method: :put, **params
end

#mock_gateway_put_response(**params) ⇒ Object

PUT



92
93
94
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 92

def mock_gateway_put_response(**params)
  mock_gateway_response method: :put, **params
end

#mock_gateway_response(response:, method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/artirix_data_models/spec_support/gateway_mock.rb', line 15

def mock_gateway_response(response:,
                          method:,
                          path:,
                          body: nil,
                          json_body: true,
                          timeout: nil,
                          authorization_bearer: nil,
                          authorization_token_hash: nil,
                          gateway: nil)
  gateway ||= ArtirixDataModels::DAORegistry.gateway

  params_hash = {
    path:                     path,
    body:                     body,
    json_body:                json_body,
    timeout:                  timeout,
    authorization_bearer:     authorization_bearer,
    authorization_token_hash: authorization_token_hash
  }

  allow(gateway).to receive(:perform).with(method, params_hash).and_return response

  # check with body already parsed
  unless body.nil?
    body = body.kind_of?(String) ? body : body.to_json
    allow(gateway).to receive(:perform).with(method, params_hash.merge(body: body)).and_return response
  end
end