dolly 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b95a3057eeb5b34b96057f4275d05092a50691e1
4
- data.tar.gz: 50b3dbc939e4d994c9ff882cb89299552236a1ce
3
+ metadata.gz: b28574b576a8c603f05cec20f24811a4f5698f9a
4
+ data.tar.gz: 43fecabe76cf497cef7c8faef9450af7307c5e3b
5
5
  SHA512:
6
- metadata.gz: a76f4783159796be1d936fde1612a45ba2a8855224a08adf72af6450fa325d23b510472b51f67bc772ed03617139e78845d306bf524ac4ce8bd7a6891ec3c70d
7
- data.tar.gz: 1d050ebc067d3df4f72e89b8d1eaa17519ce20130c061980451e0bf8e2a6749c52901c97117a008b40d8f1245852ae402705f92809bfba0dfb7614d3c45133ce
6
+ metadata.gz: 194d6c0a4ac0e500aa7d6dd252ac4ef560ce70c206748c66c2858e780c2eec9434cff0a2b7180b4ca7ec11054a1d687d795e9ba572b0094352d73a2caf7ea9a8
7
+ data.tar.gz: caebc0959d1a043ec49e9e30623d7d8f3f177cef51ffce8ec3259902facf5214fdf4d68f6f84ae83554bb65409fdcbb628a98c7c10a56c3a5073ae238163c8de
@@ -1,19 +1,14 @@
1
1
  module Dolly
2
- class Collection
3
- extend Forwardable
2
+ class Collection < DelegateClass(Set)
4
3
  attr_accessor :rows
5
4
  attr_writer :json, :docs_class
6
5
 
7
- def_delegators :@set, :clear, :empty?, :length, :+, :-
8
-
9
6
  def initialize str, docs_class
10
- @set = Set.new
11
7
  @docs_class = docs_class
12
8
  @json = str
13
- end
14
-
15
- def first
16
- to_a.first
9
+ initial = []
10
+ super(initial)
11
+ load
17
12
  end
18
13
 
19
14
  def last
@@ -37,37 +32,18 @@ module Dolly
37
32
  end
38
33
 
39
34
  BulkDocument.new(Dolly::Document.database, to_a).save
35
+ clear
36
+ load
40
37
  self
41
38
  end
42
39
 
43
- def map &block
44
- load if empty?
45
- @set.collect &block
46
- end
47
-
48
- alias_method :collect, :map
49
-
50
- def flat_map &block
51
- map( &block ).flatten
52
- end
53
-
54
40
  def each &block
55
41
  load if empty?
56
- @set.each &block
42
+ super &block
57
43
  #TODO: returning nil to avoid extra time serializing set.
58
44
  nil
59
45
  end
60
46
 
61
- def to_a
62
- load if empty?
63
- @set.to_a
64
- end
65
-
66
- def count
67
- load if empty?
68
- length
69
- end
70
-
71
47
  def rows= ary
72
48
  ary.each do |r|
73
49
  next unless r['doc']
@@ -76,9 +52,8 @@ module Dolly
76
52
  rev = properties.delete '_rev' if properties['_rev']
77
53
  document = (docs_class || doc_class(id)).new properties
78
54
  document.doc = properties.merge({'_id' => id, '_rev' => rev})
79
- @set << document
55
+ self << document
80
56
  end
81
- @rows = ary
82
57
  end
83
58
 
84
59
  def load
@@ -36,6 +36,10 @@ module Dolly
36
36
  save
37
37
  end
38
38
 
39
+ def reload
40
+ self.doc = self.class.find(id).doc
41
+ end
42
+
39
43
  def id
40
44
  doc['_id'] ||= self.class.next_id
41
45
  end
data/lib/dolly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -51,7 +51,7 @@ class CollectionTest < ActiveSupport::TestCase
51
51
  assert_equal ['stuff', 'stuff'], collection.map(&:bar)
52
52
  end
53
53
 
54
- test 'ypdate attributes will raise exception if property is missing' do
54
+ test 'update attributes will raise exception if property is missing' do
55
55
  assert_raise Dolly::MissingPropertyError do
56
56
  @collection.update_properties! missing: 'Ha! Ha!'
57
57
  end
@@ -179,6 +179,28 @@ class DocumentTest < ActiveSupport::TestCase
179
179
  end
180
180
  end
181
181
 
182
+ test 'reload reloads the doc attribute from database' do
183
+ assert foo = FooBar.find('1')
184
+ expected_doc = foo.doc.dup
185
+ FakeWeb.register_uri :get, "#{query_base_path}?keys=%5B%22foo_bar%2F0%22%5D&include_docs=true", body: build_view_response([expected_doc]).to_json
186
+ assert foo.foo = 1
187
+ assert_not_equal expected_doc, foo.doc
188
+ assert foo.reload
189
+ assert_equal expected_doc, foo.doc
190
+ end
191
+
192
+ test 'accessors work as expected after reload' do
193
+ resp = {ok: true, id: "foo_bar/1", rev: "FF0000"}
194
+ FakeWeb.register_uri :put, "http://localhost:5984/test/foo_bar%2F0", body: resp.to_json
195
+ assert foo = FooBar.find('1')
196
+ assert foo.foo = 1
197
+ assert foo.save
198
+ assert expected_doc = foo.doc
199
+ FakeWeb.register_uri :get, "#{query_base_path}?keys=%5B%22foo_bar%2F0%22%5D&include_docs=true", body: build_view_response([expected_doc]).to_json
200
+ assert foo.reload
201
+ assert_equal 1, foo.foo
202
+ end
203
+
182
204
  test 'find with multiple ids will return Collection' do
183
205
  many = FooBar.find "1", "2"
184
206
  assert_equal true, many.kind_of?(Dolly::Collection)
@@ -0,0 +1,213 @@
1
+ --------------------------------------------------
2
+ BulkDocumentTest: test_adding_document_to_bulk_doc
3
+ --------------------------------------------------
4
+ -----------------------------------------------------------------
5
+ BulkDocumentTest: test_bulk_document_intialize_with_empty_payload
6
+ -----------------------------------------------------------------
7
+ ------------------------------------------------------------------
8
+ BulkDocumentTest: test_save_document_will_remove_docs_from_payload
9
+ ------------------------------------------------------------------
10
+ ----------------------------------------------------------------------
11
+ CollectionTest: test_count_returns_the_number_of_objects_in_collection
12
+ ----------------------------------------------------------------------
13
+ -------------------------------------
14
+ CollectionTest: test_each_returns_nil
15
+ -------------------------------------
16
+ -----------------------------------------------------------------------
17
+ CollectionTest: test_map_accepts_a_block_and_returns_the_correct_values
18
+ -----------------------------------------------------------------------
19
+ ----------------------------------------------
20
+ CollectionTest: test_map_returns_an_enumerator
21
+ ----------------------------------------------
22
+ ------------------------------------------
23
+ CollectionTest: test_to_a_returns_an_array
24
+ ------------------------------------------
25
+ -----------------------------------------------------
26
+ CollectionTest: test_to_json_returns_a_string_of_json
27
+ -----------------------------------------------------
28
+ ----------------------------------------------------------------------
29
+ CollectionTest: test_update_attributes_will_change_expected_attributes
30
+ ----------------------------------------------------------------------
31
+ ----------------------------------------------------------------------------------
32
+ CollectionTest: test_update_attributes_will_raise_exception_if_property_is_missing
33
+ ----------------------------------------------------------------------------------
34
+ --------------------------------------------
35
+ CollectionTest: test_update_empty_attributes
36
+ --------------------------------------------
37
+ --------------------------------------------------------------
38
+ DocumentTest: test_Dolly::Document_have_bulk_document_instance
39
+ --------------------------------------------------------------
40
+ ----------------------------------------------------------
41
+ DocumentTest: test_accessors_work_as_expected_after_reload
42
+ ----------------------------------------------------------
43
+ -------------------------------------------
44
+ DocumentTest: test_all_first_returns_FooBar
45
+ -------------------------------------------
46
+ ------------------------------------------
47
+ DocumentTest: test_all_last_returns_FooBar
48
+ ------------------------------------------
49
+ --------------------------------------
50
+ DocumentTest: test_all_will_get_2_docs
51
+ --------------------------------------
52
+ ------------------------------------------------
53
+ DocumentTest: test_all_will_get_FooBar_documents
54
+ ------------------------------------------------
55
+ --------------------------------------------------------------------------------
56
+ DocumentTest: test_attach_file!_will_add_a_standalone_attachment_to_the_document
57
+ --------------------------------------------------------------------------------
58
+ --------------------------------------------------------------------------
59
+ DocumentTest: test_attach_file!_will_add_an_inline_attachment_if_specified
60
+ --------------------------------------------------------------------------
61
+ ------------------------------------------
62
+ DocumentTest: test_can_find_with_fixnum_id
63
+ ------------------------------------------
64
+ ----------------------------------------------
65
+ DocumentTest: test_can_save_without_timestamps
66
+ ----------------------------------------------
67
+ ---------------------------------------------
68
+ DocumentTest: test_created_at_is_current_time
69
+ ---------------------------------------------
70
+ ------------------------------------
71
+ DocumentTest: test_created_at_is_set
72
+ ------------------------------------
73
+ -------------------------------------------------------------
74
+ DocumentTest: test_default_objects_are_not_the_same_in_memory
75
+ -------------------------------------------------------------
76
+ --------------------------------------------------------------------------------
77
+ DocumentTest: test_default_properties_do_not_update_the_class_default_properties
78
+ --------------------------------------------------------------------------------
79
+ ---------------------------------------------------------
80
+ DocumentTest: test_default_should_be_overridden_by_params
81
+ ---------------------------------------------------------
82
+ ------------------------------------------------------
83
+ DocumentTest: test_default_should_populate_before_save
84
+ ------------------------------------------------------
85
+ ----------------------------------------------
86
+ DocumentTest: test_default_will_be_avoerwriten
87
+ ----------------------------------------------
88
+ --------------------------------------------
89
+ DocumentTest: test_delete_method_on_document
90
+ --------------------------------------------
91
+ ---------------------------------------------------------------
92
+ DocumentTest: test_doc_and_method_and_instance_var_are_the_same
93
+ ---------------------------------------------------------------
94
+ ------------------------------------------------
95
+ DocumentTest: test_empty_find_should_raise_error
96
+ ------------------------------------------------
97
+ ------------------------------------------------------------
98
+ DocumentTest: test_error_on_server_raises_Dolly::ServerError
99
+ ------------------------------------------------------------
100
+ --------------------------------------------------
101
+ DocumentTest: test_find_will_get_a_FooBar_document
102
+ --------------------------------------------------
103
+ ----------------------------------------------------------------
104
+ DocumentTest: test_find_with_multiple_ids_will_return_Collection
105
+ ----------------------------------------------------------------
106
+ --------------------------------------------------------
107
+ DocumentTest: test_first_class_method_returns_collection
108
+ --------------------------------------------------------
109
+ ---------------------------------------------------------
110
+ DocumentTest: test_first_class_method_returns_single_item
111
+ ---------------------------------------------------------
112
+ ---------------------------------------------
113
+ DocumentTest: test_getting_not_found_document
114
+ ---------------------------------------------
115
+ -------------------------------------------------------
116
+ DocumentTest: test_last_class_method_returns_collection
117
+ -------------------------------------------------------
118
+ --------------------------------------------------------
119
+ DocumentTest: test_last_class_method_returns_single_item
120
+ --------------------------------------------------------
121
+ -------------------------------------------------
122
+ DocumentTest: test_multi_response_with_right_data
123
+ -------------------------------------------------
124
+ ---------------------------------------
125
+ DocumentTest: test_new_document_have_id
126
+ ---------------------------------------
127
+ -------------------------------------------------------------------
128
+ DocumentTest: test_new_document_will_have_id_from__id_or_id_strings
129
+ -------------------------------------------------------------------
130
+ -------------------------------------------------------------------
131
+ DocumentTest: test_new_document_will_have_id_from__id_or_id_symbols
132
+ -------------------------------------------------------------------
133
+ ------------------------------------------
134
+ DocumentTest: test_new_document_with_no_id
135
+ ------------------------------------------
136
+ -----------------------------------------
137
+ DocumentTest: test_new_in_memory_document
138
+ -----------------------------------------
139
+ -----------------------------------------------------
140
+ DocumentTest: test_new_object_from_inhereted_document
141
+ -----------------------------------------------------
142
+ ------------------------------
143
+ DocumentTest: test_nil_default
144
+ ------------------------------
145
+ ------------------------------------------------------------------
146
+ DocumentTest: test_persisted?_returns_false_if__rev_is_not_present
147
+ ------------------------------------------------------------------
148
+ -------------------------------------------------------------
149
+ DocumentTest: test_persisted?_returns_true_if__rev_is_present
150
+ -------------------------------------------------------------
151
+ ------------------------------------------------------------------
152
+ DocumentTest: test_property_writes_work_correctly_with_pipe_equals
153
+ ------------------------------------------------------------------
154
+ ------------------------------------
155
+ DocumentTest: test_query_custom_view
156
+ ------------------------------------
157
+ ----------------------------------------------
158
+ DocumentTest: test_query_custom_view_collation
159
+ ----------------------------------------------
160
+ --------------------------------------------------------------
161
+ DocumentTest: test_reader_:bar_is_not_calling_the_writer_:bar=
162
+ --------------------------------------------------------------
163
+ -----------------------------------------------------------------
164
+ DocumentTest: test_reload_reloads_the_doc_attribute_from_database
165
+ -----------------------------------------------------------------
166
+ ------------------------------------------------------------------
167
+ DocumentTest: test_save_returns_false_for_invalid_document_on_save
168
+ ------------------------------------------------------------------
169
+ -----------------------------------------------------------------------------
170
+ DocumentTest: test_save_succeeds_for_invalid_document_if_skipping_validations
171
+ -----------------------------------------------------------------------------
172
+ ---------------------------------
173
+ DocumentTest: test_set_updated_at
174
+ ---------------------------------
175
+ ----------------------------------------------------------------------------
176
+ DocumentTest: test_setting_on_instance_value_does_set_it_for_other_instances
177
+ ----------------------------------------------------------------------------
178
+ ------------------------------------------
179
+ DocumentTest: test_soft_delete_on_document
180
+ ------------------------------------------
181
+ -----------------------------------------------------------------------
182
+ DocumentTest: test_subclass_raises_DocumentInvalidError_if_valid?_fails
183
+ -----------------------------------------------------------------------
184
+ ----------------------------------------------------
185
+ DocumentTest: test_trying_to_update_invalid_property
186
+ ----------------------------------------------------
187
+ ---------------------------------------------
188
+ DocumentTest: test_update_document_properties
189
+ ---------------------------------------------
190
+ ------------------------------------------------------
191
+ DocumentTest: test_update_document_propertys_with_bang
192
+ ------------------------------------------------------
193
+ -------------------------------------------
194
+ DocumentTest: test_will_have_key_properties
195
+ -------------------------------------------
196
+ --------------------------------------------------------
197
+ DocumentTest: test_will_have_object_with_DateTime_method
198
+ --------------------------------------------------------
199
+ ----------------------------------------------------
200
+ DocumentTest: test_will_have_object_with_Date_method
201
+ ----------------------------------------------------
202
+ ----------------------------------------------------
203
+ DocumentTest: test_will_have_object_with_Time_method
204
+ ----------------------------------------------------
205
+ --------------------------------------------------------
206
+ DocumentTest: test_will_have_object_with_boolean?_method
207
+ --------------------------------------------------------
208
+ ------------------------------------------------
209
+ DocumentTest: test_will_have_only_set_properties
210
+ ------------------------------------------------
211
+ ----------------------------------------------------------------
212
+ DocumentTest: test_with_default_will_return_default_value_on_nil
213
+ ----------------------------------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -191,6 +191,7 @@ files:
191
191
  - test/dummy/config/locales/en.yml
192
192
  - test/dummy/config/routes.rb
193
193
  - test/dummy/lib/couch_rest_adapter/railtie.rb
194
+ - test/dummy/log/test.log
194
195
  - test/dummy/public/404.html
195
196
  - test/dummy/public/422.html
196
197
  - test/dummy/public/500.html
@@ -251,6 +252,7 @@ test_files:
251
252
  - test/dummy/config/routes.rb
252
253
  - test/dummy/config.ru
253
254
  - test/dummy/lib/couch_rest_adapter/railtie.rb
255
+ - test/dummy/log/test.log
254
256
  - test/dummy/public/404.html
255
257
  - test/dummy/public/422.html
256
258
  - test/dummy/public/500.html