ree_lib 1.0.87 → 1.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -22
- data/lib/ree_lib/packages/ree_actions/package/ree_actions/dsl.rb +0 -12
- data/lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb +0 -90
- data/lib/ree_lib/packages/ree_dao/Package.schema.json +0 -28
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/dataset_extensions.rb +29 -21
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/build_pg_connection_spec.rb +10 -3
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/build_sqlite_connection_spec.rb +0 -37
- data/lib/ree_lib/packages/ree_http/package/ree_http/functions/execute_request.rb +27 -20
- data/lib/ree_lib/packages/ree_http/schemas/ree_http/functions/execute_request.schema.json +8 -0
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_delete_spec.rb +10 -8
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_get_spec.rb +79 -18
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_options_spec.rb +6 -5
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_patch_spec.rb +8 -4
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_post_spec.rb +5 -10
- data/lib/ree_lib/packages/ree_http/spec/ree_http/functions/http_put_spec.rb +5 -3
- data/lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/t_spec.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper.rb +22 -6
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/benchmarks/mapper_benchmark_spec.rb +31 -0
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/bool_spec.rb +8 -8
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_spec.rb +10 -10
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/date_time_spec.rb +16 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/float_spec.rb +13 -13
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/hash_spec.rb +2 -2
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/integer_spec.rb +14 -14
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/rational_spec.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/string_spec.rb +12 -12
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/time_spec.rb +16 -16
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/types/type_options_spec.rb +4 -4
- data/lib/ree_lib/packages/ree_mapper/spec/ree_mapper/wrappers/array_spec.rb +6 -6
- data/lib/ree_lib/version.rb +1 -1
- metadata +17 -24
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/beans/dao_cache.rb +0 -81
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/drop_cache.rb +0 -15
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/extract_changes.rb +0 -26
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/init_cache.rb +0 -15
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/beans/dao_cache.schema.json +0 -22
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/drop_cache.schema.json +0 -31
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/extract_changes.schema.json +0 -45
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/init_cache.schema.json +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42bfcdb43c2ebd44badd128321d5b277951829cd63f0ec4d28157ae6526b04f4
|
4
|
+
data.tar.gz: 0c42d2aa910eff7c1fc4da08aab37f21236b1e656b69399deb5f71cf10db127b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b868775ba1f7f0e3b692c646389b591d7615289cdd717220568bef46641972d0e281cf4dc8bcdd535b977420503070a5ae7cd06256c2c3a6bdd2366018e62a
|
7
|
+
data.tar.gz: 1eef6d917be75f9169788f327bb36833378186ba453af0dd99a791f1a4c5e555e6f2d4976f5b1468a8604ea3f3584847c0dd201bed7317940c2171c6546c1b2e
|
data/Gemfile.lock
CHANGED
@@ -1,53 +1,52 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ree_lib (1.0.
|
4
|
+
ree_lib (1.0.89)
|
5
5
|
bigdecimal (~> 3.1.6)
|
6
6
|
binding_of_caller (~> 1.0.0)
|
7
|
-
i18n (~> 1.
|
8
|
-
loofah (~> 2.
|
9
|
-
oj (~> 3.
|
7
|
+
i18n (~> 1.14.1)
|
8
|
+
loofah (~> 2.22.0)
|
9
|
+
oj (~> 3.16.3)
|
10
10
|
rainbow (~> 3.1.1)
|
11
11
|
ree (~> 1.0.0)
|
12
|
-
sequel (~> 5.
|
12
|
+
sequel (~> 5.76.0)
|
13
13
|
tzinfo (~> 2.0.5)
|
14
14
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
abbrev (0.1.2)
|
19
18
|
addressable (2.8.6)
|
20
19
|
public_suffix (>= 2.0.2, < 6.0)
|
21
20
|
bigdecimal (3.1.6)
|
22
21
|
binding_of_caller (1.0.0)
|
23
22
|
debug_inspector (>= 0.0.1)
|
24
|
-
bootsnap (1.17.
|
23
|
+
bootsnap (1.17.1)
|
25
24
|
msgpack (~> 1.2)
|
26
25
|
commander (5.0.0)
|
27
26
|
highline (~> 3.0.0)
|
28
|
-
concurrent-ruby (1.2.
|
27
|
+
concurrent-ruby (1.2.3)
|
29
28
|
crack (0.4.5)
|
30
29
|
rexml
|
31
30
|
crass (1.0.6)
|
32
31
|
debug_inspector (1.2.0)
|
33
32
|
diff-lcs (1.5.0)
|
34
|
-
faker (3.2.
|
33
|
+
faker (3.2.3)
|
35
34
|
i18n (>= 1.8.11, < 2)
|
36
35
|
hashdiff (1.1.0)
|
37
|
-
highline (3.0.
|
38
|
-
|
39
|
-
i18n (1.12.0)
|
36
|
+
highline (3.0.1)
|
37
|
+
i18n (1.14.1)
|
40
38
|
concurrent-ruby (~> 1.0)
|
41
|
-
loofah (2.
|
39
|
+
loofah (2.22.0)
|
42
40
|
crass (~> 1.0.2)
|
43
|
-
nokogiri (>= 1.
|
41
|
+
nokogiri (>= 1.12.0)
|
44
42
|
msgpack (1.7.2)
|
45
43
|
nokogiri (1.16.0-x86_64-darwin)
|
46
44
|
racc (~> 1.4)
|
47
45
|
nokogiri (1.16.0-x86_64-linux)
|
48
46
|
racc (~> 1.4)
|
49
|
-
oj (3.
|
50
|
-
|
47
|
+
oj (3.16.3)
|
48
|
+
bigdecimal (>= 3.0)
|
49
|
+
pg (1.5.4)
|
51
50
|
public_suffix (5.0.4)
|
52
51
|
racc (1.7.3)
|
53
52
|
rack (3.0.8)
|
@@ -58,9 +57,9 @@ GEM
|
|
58
57
|
ree (1.0.34)
|
59
58
|
commander (~> 5.0.0)
|
60
59
|
rexml (3.2.6)
|
61
|
-
roda (3.
|
60
|
+
roda (3.76.0)
|
62
61
|
rack
|
63
|
-
rollbar (3.
|
62
|
+
rollbar (3.5.1)
|
64
63
|
rspec (3.12.0)
|
65
64
|
rspec-core (~> 3.12.0)
|
66
65
|
rspec-expectations (~> 3.12.0)
|
@@ -74,7 +73,8 @@ GEM
|
|
74
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
75
74
|
rspec-support (~> 3.12.0)
|
76
75
|
rspec-support (3.12.1)
|
77
|
-
sequel (5.
|
76
|
+
sequel (5.76.0)
|
77
|
+
bigdecimal
|
78
78
|
sqlite3 (1.4.4)
|
79
79
|
timecop (0.9.8)
|
80
80
|
tzinfo (2.0.6)
|
@@ -95,12 +95,12 @@ PLATFORMS
|
|
95
95
|
DEPENDENCIES
|
96
96
|
bootsnap
|
97
97
|
faker (~> 3.2)
|
98
|
-
pg (~> 1.4
|
98
|
+
pg (~> 1.5.4)
|
99
99
|
rack-test
|
100
100
|
rake (~> 13.0)
|
101
101
|
ree_lib!
|
102
|
-
roda (~> 3.
|
103
|
-
rollbar (~> 3.
|
102
|
+
roda (~> 3.76.0)
|
103
|
+
rollbar (~> 3.5.1)
|
104
104
|
rspec
|
105
105
|
sqlite3 (~> 1.4.4)
|
106
106
|
timecop (~> 0.9.5)
|
@@ -7,19 +7,11 @@ module ReeActions
|
|
7
7
|
def self.included(base)
|
8
8
|
base.extend(ClassMethods)
|
9
9
|
base.include(ReeMapper::DSL)
|
10
|
-
link_dao_cache(base)
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.extended(base)
|
14
13
|
base.extend(ClassMethods)
|
15
14
|
base.include(ReeMapper::DSL)
|
16
|
-
link_dao_cache(base)
|
17
|
-
end
|
18
|
-
|
19
|
-
private_class_method def self.link_dao_cache(base)
|
20
|
-
base.include(Ree::LinkDSL)
|
21
|
-
base.link :drop_cache, as: :__ree_dao_drop_cache, from: :ree_dao
|
22
|
-
base.link :init_cache, as: :__ree_dao_init_cache, from: :ree_dao
|
23
15
|
end
|
24
16
|
|
25
17
|
module ClassMethods
|
@@ -52,8 +44,6 @@ module ReeActions
|
|
52
44
|
alias_method(:__original_call, :call)
|
53
45
|
|
54
46
|
define_method :call do |user_access, attrs|
|
55
|
-
__ree_dao_init_cache
|
56
|
-
|
57
47
|
if self.class.const_defined?(:ActionCaster)
|
58
48
|
caster = self.class.const_get(:ActionCaster)
|
59
49
|
|
@@ -69,8 +59,6 @@ module ReeActions
|
|
69
59
|
end
|
70
60
|
|
71
61
|
__original_call(user_access, attrs)
|
72
|
-
ensure
|
73
|
-
__ree_dao_drop_cache
|
74
62
|
end
|
75
63
|
|
76
64
|
nil
|
@@ -89,94 +89,4 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
89
89
|
result = ReeActionsTest::TestAction2.new.call('user_access', {user_id: 1})
|
90
90
|
expect(result).to eq(1)
|
91
91
|
}
|
92
|
-
|
93
|
-
it {
|
94
|
-
module ReeActionsTest
|
95
|
-
include Ree::PackageDSL
|
96
|
-
|
97
|
-
package do
|
98
|
-
depends_on :ree_mapper
|
99
|
-
depends_on :ree_dao
|
100
|
-
end
|
101
|
-
|
102
|
-
class Db
|
103
|
-
include Ree::BeanDSL
|
104
|
-
|
105
|
-
bean :db do
|
106
|
-
singleton
|
107
|
-
factory :build
|
108
|
-
|
109
|
-
link :build_sqlite_connection, from: :ree_dao
|
110
|
-
end
|
111
|
-
|
112
|
-
def build
|
113
|
-
build_sqlite_connection({database: 'sqlite_db'})
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class User
|
118
|
-
include ReeDto::EntityDSL
|
119
|
-
|
120
|
-
properties(
|
121
|
-
id: Nilor[Integer],
|
122
|
-
name: String,
|
123
|
-
age: Integer,
|
124
|
-
)
|
125
|
-
|
126
|
-
attr_accessor :name
|
127
|
-
end
|
128
|
-
|
129
|
-
class UsersDao
|
130
|
-
include ReeDao::DSL
|
131
|
-
|
132
|
-
dao :users_dao do
|
133
|
-
link :db
|
134
|
-
end
|
135
|
-
|
136
|
-
table :users
|
137
|
-
|
138
|
-
schema ReeActionsTest::User do
|
139
|
-
integer :id, null: true
|
140
|
-
string :name
|
141
|
-
integer :age
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
class TestAction3
|
146
|
-
include ReeActions::DSL
|
147
|
-
|
148
|
-
action :test_action3 do
|
149
|
-
link :users_dao
|
150
|
-
end
|
151
|
-
|
152
|
-
contract Any, Hash => Integer
|
153
|
-
def call(user_access, attrs)
|
154
|
-
$user = ReeActionsTest::User.new(name: 'John', age: 30)
|
155
|
-
users_dao.put($user)
|
156
|
-
|
157
|
-
Thread.new do
|
158
|
-
users_dao.put(ReeActionsTest::User.new(name: 'Alex', age: 33))
|
159
|
-
end.join
|
160
|
-
|
161
|
-
Thread.new do
|
162
|
-
users_dao.put(ReeActionsTest::User.new(name: 'David', age: 21))
|
163
|
-
|
164
|
-
Thread.new do
|
165
|
-
users_dao.put(ReeActionsTest::User.new(name: 'Sam', age: 19))
|
166
|
-
end.join
|
167
|
-
end.join
|
168
|
-
|
169
|
-
$thread_cache = ReeDao::DaoCache.new.get(:users, $user.id)
|
170
|
-
|
171
|
-
attrs[:user_id]
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
Thread.new do
|
177
|
-
ReeActionsTest::TestAction3.new.call('user_access', {user_id: 1})
|
178
|
-
end.join
|
179
|
-
|
180
|
-
expect($thread_cache).to eq($user.to_h)
|
181
|
-
}
|
182
92
|
end
|
@@ -75,34 +75,6 @@
|
|
75
75
|
"object"
|
76
76
|
]
|
77
77
|
},
|
78
|
-
{
|
79
|
-
"name": "dao_cache",
|
80
|
-
"schema": "packages/ree_dao/schemas/ree_dao/beans/dao_cache.schema.json",
|
81
|
-
"tags": [
|
82
|
-
"object"
|
83
|
-
]
|
84
|
-
},
|
85
|
-
{
|
86
|
-
"name": "drop_cache",
|
87
|
-
"schema": "packages/ree_dao/schemas/ree_dao/functions/drop_cache.schema.json",
|
88
|
-
"tags": [
|
89
|
-
"fn"
|
90
|
-
]
|
91
|
-
},
|
92
|
-
{
|
93
|
-
"name": "extract_changes",
|
94
|
-
"schema": "packages/ree_dao/schemas/ree_dao/functions/extract_changes.schema.json",
|
95
|
-
"tags": [
|
96
|
-
"fn"
|
97
|
-
]
|
98
|
-
},
|
99
|
-
{
|
100
|
-
"name": "init_cache",
|
101
|
-
"schema": "packages/ree_dao/schemas/ree_dao/functions/init_cache.schema.json",
|
102
|
-
"tags": [
|
103
|
-
"fn"
|
104
|
-
]
|
105
|
-
},
|
106
78
|
{
|
107
79
|
"name": "one_to_many",
|
108
80
|
"schema": "packages/ree_dao/schemas/ree_dao/functions/one_to_many.schema.json",
|
@@ -19,10 +19,9 @@ module ReeDao
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module InstanceMethods
|
22
|
+
PERSISTENCE_STATE_VARIABLE = :@persistence_state
|
22
23
|
IMPORT_BATCH_SIZE = 1000
|
23
24
|
|
24
|
-
package_require("ree_dao/functions/extract_changes")
|
25
|
-
|
26
25
|
# override methods
|
27
26
|
def find(id, mapper: nil)
|
28
27
|
where(primary_key => id).first(mapper: mapper)
|
@@ -50,7 +49,7 @@ module ReeDao
|
|
50
49
|
key = insert(raw)
|
51
50
|
|
52
51
|
set_entity_primary_key(entity, raw, key)
|
53
|
-
|
52
|
+
set_persistence_state(entity, raw)
|
54
53
|
|
55
54
|
entity
|
56
55
|
end
|
@@ -74,7 +73,7 @@ module ReeDao
|
|
74
73
|
key = insert_conflict(conflict_opts).insert(raw)
|
75
74
|
|
76
75
|
set_entity_primary_key(entity, raw, key)
|
77
|
-
|
76
|
+
set_persistence_state(entity, raw)
|
78
77
|
|
79
78
|
where(primary_key => key).first
|
80
79
|
end
|
@@ -105,7 +104,7 @@ module ReeDao
|
|
105
104
|
raw_data = raw[entity]
|
106
105
|
|
107
106
|
set_entity_primary_key(entity, raw_data, id)
|
108
|
-
|
107
|
+
set_persistence_state(entity, raw_data)
|
109
108
|
end
|
110
109
|
|
111
110
|
nil
|
@@ -120,10 +119,10 @@ module ReeDao
|
|
120
119
|
return __original_update(hash_or_entity) if hash_or_entity.is_a?(Hash)
|
121
120
|
|
122
121
|
raw = opts[:schema_mapper].db_dump(hash_or_entity)
|
123
|
-
raw =
|
122
|
+
raw = extract_changes(hash_or_entity, raw)
|
124
123
|
|
125
124
|
unless raw.empty?
|
126
|
-
|
125
|
+
update_persistence_state(hash_or_entity, raw)
|
127
126
|
key_condition = prepare_key_condition_from_entity(hash_or_entity)
|
128
127
|
where(key_condition).__original_update(raw)
|
129
128
|
end
|
@@ -161,7 +160,7 @@ module ReeDao
|
|
161
160
|
if m
|
162
161
|
entity = m.db_load(hash)
|
163
162
|
|
164
|
-
self.
|
163
|
+
self.set_persistence_state(entity, hash)
|
165
164
|
|
166
165
|
entity
|
167
166
|
else
|
@@ -173,10 +172,6 @@ module ReeDao
|
|
173
172
|
|
174
173
|
private
|
175
174
|
|
176
|
-
def __ree_dao_cache
|
177
|
-
ReeDao::DaoCache.new
|
178
|
-
end
|
179
|
-
|
180
175
|
def primary_key
|
181
176
|
opts[:primary_key] || :id
|
182
177
|
end
|
@@ -209,22 +204,35 @@ module ReeDao
|
|
209
204
|
end
|
210
205
|
end
|
211
206
|
|
212
|
-
def
|
207
|
+
def set_persistence_state(entity, raw)
|
213
208
|
if !entity.is_a?(Integer) && !entity.is_a?(Symbol)
|
214
|
-
|
209
|
+
entity.instance_variable_set(PERSISTENCE_STATE_VARIABLE, raw)
|
210
|
+
end
|
211
|
+
end
|
215
212
|
|
216
|
-
|
217
|
-
|
218
|
-
|
213
|
+
def update_persistence_state(entity, raw)
|
214
|
+
persistence_state = entity.instance_variable_get(PERSISTENCE_STATE_VARIABLE)
|
215
|
+
|
216
|
+
if persistence_state
|
217
|
+
persistence_state.merge!(raw)
|
219
218
|
end
|
220
219
|
end
|
221
220
|
|
222
|
-
def
|
223
|
-
|
221
|
+
def extract_changes(entity, hash)
|
222
|
+
return hash unless entity.instance_variable_defined?(PERSISTENCE_STATE_VARIABLE)
|
223
|
+
changes = {}
|
224
|
+
|
225
|
+
persistence_state = entity.instance_variable_get(PERSISTENCE_STATE_VARIABLE)
|
226
|
+
|
227
|
+
hash.each do |column, value|
|
228
|
+
previous_column_value = persistence_state[column]
|
224
229
|
|
225
|
-
|
226
|
-
|
230
|
+
if persistence_state.has_key?(column) && previous_column_value != value
|
231
|
+
changes[column] = value
|
232
|
+
end
|
227
233
|
end
|
234
|
+
|
235
|
+
changes
|
228
236
|
end
|
229
237
|
|
230
238
|
def set_entity_primary_key(entity, raw, key)
|
@@ -134,10 +134,17 @@ RSpec.describe :build_pg_connection do
|
|
134
134
|
it {
|
135
135
|
products_dao.delete_all
|
136
136
|
|
137
|
-
product = ReeDaoTestPg::Product.new(
|
137
|
+
product = ReeDaoTestPg::Product.new(
|
138
|
+
title: "Product",
|
139
|
+
info: {
|
140
|
+
price: 1337, count: 200
|
141
|
+
},
|
142
|
+
labels: ["Sale"]
|
143
|
+
)
|
144
|
+
|
138
145
|
products_dao.put(product)
|
139
146
|
|
140
|
-
product.info
|
147
|
+
product.info = {price: 1440, count: 200}
|
141
148
|
product.labels << "New"
|
142
149
|
|
143
150
|
products_dao.update(product)
|
@@ -152,7 +159,7 @@ RSpec.describe :build_pg_connection do
|
|
152
159
|
products_dao.delete_all
|
153
160
|
|
154
161
|
products = Array.new(3) { |i| ReeDaoTestPg::Product.new(title: "Product#{i}", info: { price: 1337, count: 200 }, labels: ["Sale"]) }
|
155
|
-
|
162
|
+
|
156
163
|
products_dao.import_all(products)
|
157
164
|
|
158
165
|
expect(products_dao.count).to eq 3
|
@@ -5,7 +5,6 @@ package_require('ree_dto/entity_dsl')
|
|
5
5
|
|
6
6
|
RSpec.describe :build_sqlite_connection do
|
7
7
|
link :build_sqlite_connection, from: :ree_dao
|
8
|
-
link :dao_cache, from: :ree_dao
|
9
8
|
|
10
9
|
after do
|
11
10
|
Ree.disable_irb_mode
|
@@ -131,42 +130,6 @@ RSpec.describe :build_sqlite_connection do
|
|
131
130
|
expect(user.age).to eq(u.age)
|
132
131
|
}
|
133
132
|
|
134
|
-
it {
|
135
|
-
dao.delete_all
|
136
|
-
|
137
|
-
user = ReeDaoTest::User.new(name: 'John', age: 30)
|
138
|
-
dao.put(user)
|
139
|
-
|
140
|
-
u = dao.find(user.id)
|
141
|
-
|
142
|
-
expect(u).to be_a(ReeDaoTest::User)
|
143
|
-
|
144
|
-
state = dao_cache.get(:users, u.id)
|
145
|
-
|
146
|
-
expect(state).to be_a(Hash)
|
147
|
-
expect(state[:id]).to eq(user.id)
|
148
|
-
expect(state[:age]).to eq(user.age)
|
149
|
-
expect(state[:name]).to eq(user.name)
|
150
|
-
}
|
151
|
-
|
152
|
-
it {
|
153
|
-
dao.delete_all
|
154
|
-
|
155
|
-
user = ReeDaoTest::User.new(name: 'John', age: 30)
|
156
|
-
dao.put(user)
|
157
|
-
|
158
|
-
u = dao.find(user.id)
|
159
|
-
expect(u).to be_a(ReeDaoTest::User)
|
160
|
-
expect(dao_cache.get(:users, u.id)).to_not eq(nil)
|
161
|
-
|
162
|
-
all = dao.all
|
163
|
-
expect(all.size).to eq(1)
|
164
|
-
u = all.first
|
165
|
-
|
166
|
-
expect(u).to be_a(ReeDaoTest::User)
|
167
|
-
expect(dao_cache.get(:users, u.id)).to be_a(Hash)
|
168
|
-
}
|
169
|
-
|
170
133
|
it {
|
171
134
|
dao.delete_all
|
172
135
|
|
@@ -4,13 +4,13 @@ class ReeHttp::ExecuteRequest
|
|
4
4
|
include Ree::FnDSL
|
5
5
|
|
6
6
|
fn :execute_request do
|
7
|
+
link :build_request
|
7
8
|
link :build_request_executor
|
8
9
|
link :slice, from: :ree_hash
|
9
|
-
link 'ree_http/http_exceptions', -> { HttpExceptions }
|
10
|
-
|
11
10
|
link 'ree_http/constants', -> {
|
12
11
|
DEFAULT_TIMEOUT & DEFAULT_WRITE_TIMEOUT & DEFAULT_FORCE_SSL
|
13
12
|
}
|
13
|
+
link 'ree_http/http_exceptions', -> { HttpExceptions }
|
14
14
|
end
|
15
15
|
|
16
16
|
include HttpExceptions
|
@@ -89,7 +89,9 @@ class ReeHttp::ExecuteRequest
|
|
89
89
|
"Got #{response.code} response on request URI #{request.uri}\n With BODY: #{response.body}\n"
|
90
90
|
)
|
91
91
|
|
92
|
-
|
92
|
+
if response.is_a?(Net::HTTPRedirection)
|
93
|
+
return process_redirect_response(response, request, opts, &block)
|
94
|
+
end
|
93
95
|
|
94
96
|
response
|
95
97
|
end
|
@@ -97,27 +99,32 @@ class ReeHttp::ExecuteRequest
|
|
97
99
|
private
|
98
100
|
|
99
101
|
def process_redirect_response(response, request, opts, &block)
|
100
|
-
if
|
101
|
-
if
|
102
|
-
|
103
|
-
end
|
102
|
+
if opts[:redirects_count] == 0
|
103
|
+
raise TooManyRedirectsError, "Got too match redirects, if you want more redirects, use redirects_count"
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
if opts[:strict_redirect_mode] && STRICT_SENSITIVE_CODES.include?(response.code.to_i) && UNSAFE_VERBS.include?(request.method.to_sym)
|
107
|
+
raise RedirectMethodError, "Got #{response.code.to_i} with strict_mode"
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
if (ALWAYS_GET_CODES.include?(response.code.to_i) || STRICT_SENSITIVE_CODES.include?(response.code.to_i)) && UNSAFE_VERBS.include?(request.method.downcase.to_sym)
|
111
|
+
new_request_method = :get
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
request.instance_variable_set(:@path, request.uri.path)
|
114
|
+
new_request_method ||= request.method.downcase.to_sym
|
115
115
|
|
116
|
-
|
116
|
+
new_uri = URI(response['Location'] || response['location'])
|
117
|
+
new_request = build_request(
|
118
|
+
new_request_method,
|
119
|
+
new_uri.to_s,
|
120
|
+
**slice(opts, [
|
121
|
+
:headers, :body, :form_data, :query_params,
|
122
|
+
:force_ssl, :ca_certs, :basic_auth, :bearer_token
|
123
|
+
])
|
124
|
+
)
|
117
125
|
|
118
|
-
|
119
|
-
end
|
126
|
+
opts[:redirects_count] -= 1
|
120
127
|
|
121
|
-
|
128
|
+
call(new_request, **opts, &block)
|
122
129
|
end
|
123
|
-
end
|
130
|
+
end
|
@@ -129,11 +129,11 @@ RSpec.describe :http_delete do
|
|
129
129
|
headers: {
|
130
130
|
'Accept'=>'*/*',
|
131
131
|
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
132
|
-
'
|
133
|
-
'
|
132
|
+
'Host' => 'www.example.com',
|
133
|
+
'User-Agent'=>'Ruby'
|
134
134
|
}
|
135
135
|
)
|
136
|
-
.to_return(status: 200
|
136
|
+
.to_return(status: 200)
|
137
137
|
end
|
138
138
|
after :all do
|
139
139
|
WebMock.reset!
|
@@ -142,7 +142,7 @@ RSpec.describe :http_delete do
|
|
142
142
|
let(:err_result) {
|
143
143
|
http_delete(
|
144
144
|
host_with_ssl + '/redirect_303_infinity',
|
145
|
-
force_ssl: true
|
145
|
+
force_ssl: true
|
146
146
|
)
|
147
147
|
}
|
148
148
|
|
@@ -151,15 +151,17 @@ RSpec.describe :http_delete do
|
|
151
151
|
|
152
152
|
http_delete(
|
153
153
|
host_with_ssl + '/redirect_307',
|
154
|
-
force_ssl: true, headers: {
|
154
|
+
force_ssl: true, headers: { "Token" => 123 }
|
155
155
|
)
|
156
|
-
expect(WebMock).to have_requested(:delete, host_with_ssl).with(headers: {
|
156
|
+
expect(WebMock).to have_requested(:delete, host_with_ssl + "/redirect_307").with(headers: { "Token" => 123}).once
|
157
|
+
expect(WebMock).to have_requested(:delete, host_with_ssl).once
|
157
158
|
|
158
159
|
http_delete(
|
159
160
|
host_with_ssl + '/redirect_303',
|
160
|
-
force_ssl: true, headers: {
|
161
|
+
force_ssl: true, headers: { "Token" => 123 }
|
161
162
|
)
|
162
|
-
expect(WebMock).to have_requested(:
|
163
|
+
expect(WebMock).to have_requested(:delete, host_with_ssl + "/redirect_303").with(headers: { "Token" => 123}).once
|
164
|
+
expect(WebMock).to have_requested(:get, host_with_ssl).once
|
163
165
|
end
|
164
166
|
end
|
165
167
|
end
|