nano-store 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ # [0.5.1](https://github.com/siuying/NanoStoreInMotion/compare/v0.5.0%E2%80%A6v0.5.1)
2
+
3
+ - Update to NanoStore 2.1.6
4
+
5
+ # [0.5.0](https://github.com/siuying/NanoStoreInMotion/compare/v0.4.3%E2%80%A6v0.5.0)
6
+
7
+ - Add bag support in Model
8
+
1
9
  # [0.4.3](https://github.com/siuying/NanoStoreInMotion/compare/v0.4.2%E2%80%A6v0.4.3)
2
10
 
3
11
  - Fix bug saving bag to store
data/README.md CHANGED
@@ -27,9 +27,9 @@ require 'nano-store'
27
27
  Motion::Project::App.setup do |app|
28
28
  app.name = 'myapp'
29
29
 
30
- # Only needed if you have not already specifying a pods dependency
30
+ # Add the pod NanoStore to your project
31
31
  app.pods do
32
- pod 'NanoStore', '~> 2.1.4'
32
+ pod 'NanoStore', '~> 2.1.8'
33
33
  end
34
34
  end
35
35
  ```
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ Motion::Project::App.setup do |app|
9
9
  app.redgreen_style = :full
10
10
  app.files += Dir.glob(File.join(app.project_dir, 'lib/nano_store/*.rb'))
11
11
  app.pods do
12
- pod 'NanoStore', '~> 2.1.5'
12
+ pod 'NanoStore', '~> 2.1.8'
13
13
  end
14
14
  end
15
15
 
@@ -15,5 +15,5 @@ Motion::Project::App.setup do |app|
15
15
  app.files.unshift(File.join(File.dirname(__FILE__), 'nano_store/finder.rb'))
16
16
 
17
17
  app.pods ||= Motion::Project::CocoaPods.new(app)
18
- app.pods.pod 'NanoStore', '~> 2.1.5'
18
+ app.pods.pod 'NanoStore', '~> 2.1.8'
19
19
  end
@@ -142,7 +142,7 @@ module NanoStore
142
142
  expression = NSFNanoExpression.expressionWithPredicate(attribute)
143
143
  if val.is_a?(Hash)
144
144
  val.each do |operator, sub_val|
145
- value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:operator, value:sub_val)
145
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:operator, value:sub_val.to_s)
146
146
  expression.addPredicate(value, withOperator:NSFAnd)
147
147
  end
148
148
  elsif val.is_a?(Array)
@@ -150,11 +150,11 @@ module NanoStore
150
150
  expression.addPredicate(value, withOperator:NSFAnd)
151
151
 
152
152
  val.each do |sub_val|
153
- value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:sub_val)
153
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:sub_val.to_s)
154
154
  expression.addPredicate(value, withOperator:NSFOr)
155
155
  end
156
156
  else
157
- value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:val)
157
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:val.to_s)
158
158
  expression.addPredicate(value, withOperator:NSFAnd)
159
159
  end
160
160
  expressions << expression
@@ -6,11 +6,11 @@ module NanoStore
6
6
 
7
7
  case type
8
8
  when :memory
9
- store = NSFNanoStore.createAndOpenStoreWithType(NSFMemoryStoreType, path:nil, error: error_ptr)
9
+ store = NSFNanoStore.createAndOpenStoreWithType(::NSFMemoryStoreType, path:nil, error: error_ptr)
10
10
  when :temporary, :temp
11
- store = NSFNanoStore.createAndOpenStoreWithType(NSFTemporaryStoreType, path:nil, error: error_ptr)
11
+ store = NSFNanoStore.createAndOpenStoreWithType(::NSFTemporaryStoreType, path:nil, error: error_ptr)
12
12
  when :persistent, :file
13
- store = NSFNanoStore.createAndOpenStoreWithType(NSFPersistentStoreType, path:path, error: error_ptr)
13
+ store = NSFNanoStore.createAndOpenStoreWithType(::NSFPersistentStoreType, path:path, error: error_ptr)
14
14
  else
15
15
  raise NanoStoreError.new("unexpected store type (#{type}), must be one of: :memory, :temporary or :persistent")
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module NanoStore
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -14,6 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = NanoStore::VERSION
16
16
 
17
- gem.add_dependency 'motion-cocoapods', '>= 1.2.0'
17
+ gem.add_dependency 'motion-cocoapods', '>= 1.2.1'
18
18
  gem.add_development_dependency 'motion-redgreen'
19
19
  end
@@ -14,66 +14,68 @@ describe NanoStore::Bag do
14
14
  NanoStore.shared_store = nil
15
15
  end
16
16
 
17
- it "should add objects to bag" do
18
- bag = Bag.bag
17
+ describe "#<<" do
18
+ it "should add objects to bag" do
19
+ bag = Bag.bag
19
20
 
20
- # use << method to add object to bag
21
- page = Page.new
22
- page.text = "Hello"
23
- page.index = 1
24
- bag << page
25
-
26
- # use + method to add object to bag
27
- page = Page.new
28
- page.text = "World"
29
- page.index = 2
30
- bag += page
21
+ # use << method to add object to bag
22
+ bag << Page.new(:text => "Hello", :index => 1)
31
23
 
32
- bag.unsaved.count.should.be == 2
33
- bag.changed?.should.be.true
34
- bag.save
35
-
36
- bag.unsaved.count.should.be == 0
37
- bag.saved.count.should.be == 2
38
- bag.changed?.should.be.false
24
+ bag.unsaved.count.should.be == 1
25
+ bag.changed?.should.be.true
26
+ bag.save
27
+
28
+ bag.unsaved.count.should.be == 0
29
+ bag.saved.count.should.be == 1
30
+ bag.changed?.should.be.false
31
+ end
39
32
  end
33
+
34
+ describe "#+" do
35
+ it "should add objects to bag" do
36
+ bag = Bag.bag
40
37
 
41
- it "should delete object from bag" do
42
- bag = Bag.bag
43
-
44
- # use << method to add object to bag
45
- page = Page.new
46
- page.text = "Hello"
47
- page.index = 1
48
- bag << page
49
-
50
- page = Page.new
51
- page.text = "Foo Bar"
52
- page.index = 2
53
- bag << page
38
+ # use + method to add object to bag
39
+ bag += Page.new(:text => "World", :index => 2)
54
40
 
55
- bag.save
56
- bag.saved.count.should.be == 2
57
- bag.delete(page)
58
- bag.changed?.should.be.true
59
- bag.removed.count.should.be == 1
60
- bag.save
61
- bag.saved.count.should.be == 1
41
+ bag.unsaved.count.should.be == 1
42
+ bag.changed?.should.be.true
43
+ bag.save
44
+
45
+ bag.unsaved.count.should.be == 0
46
+ bag.saved.count.should.be == 1
47
+ bag.changed?.should.be.false
48
+ end
62
49
  end
63
50
 
64
- it "should add bag to store" do
65
- before_count = NanoStore.shared_store.bags.count
51
+ describe "#delete" do
52
+ it "should delete object from bag" do
53
+ bag = Bag.bag
66
54
 
67
- bag = Bag.bag
55
+ page = Page.new(:text => "Hello", :index => 1)
56
+ bag << page
57
+ bag << Page.new(:text => "World", :index => 2)
58
+ bag.save
59
+ bag.saved.count.should.be == 2
68
60
 
69
- # use << method to add object to bag
70
- page = Page.new
71
- page.text = "Hello"
72
- page.index = 1
73
- bag << page
61
+ bag.delete(page)
62
+ bag.changed?.should.be.true
63
+ bag.removed.count.should.be == 1
64
+ bag.save
65
+ bag.saved.count.should.be == 1
66
+ end
67
+ end
74
68
 
75
- bag.save
76
- NanoStore.shared_store.bags.count.should.be == before_count + 1
69
+ describe "#store=" do
70
+ it "should store bag in a NanoStore" do
71
+ store = NanoStore.store
72
+ bag = Bag.bag
73
+ bag.store = store
74
+ bag << Page.new(:text => "1")
75
+ bag.save
76
+ store.bags.size.should == 1
77
+ store.bags.first.to_a.first.text.should == "1"
78
+ end
77
79
  end
78
80
 
79
81
  describe "#to_a" do
@@ -84,8 +86,10 @@ describe NanoStore::Bag do
84
86
 
85
87
  bag.to_a.is_a?(Array).should.be.true
86
88
  bag.to_a.size.should == 2
87
- bag.to_a[0].text.should == "1"
88
- bag.to_a[1].text.should == "2"
89
+
90
+ # #to_a is not ordered!
91
+ ["1", "2"].include?(bag.to_a[0].text).should.be.true
92
+ ["1", "2"].include?(bag.to_a[1].text).should.be.true
89
93
  bag.save
90
94
  bag.to_a.size.should == 2
91
95
  end
@@ -31,156 +31,162 @@ describe "Finder" do
31
31
  user3.save
32
32
  end
33
33
 
34
- it "create object in their class" do
35
- NanoStore.shared_store.allObjectClasses.should == ["User"]
36
- Car.create(:name => "Bob")
37
- NanoStore.shared_store.allObjectClasses.sort.should == ["User", "Car"].sort
34
+ describe "::create" do
35
+ it "create object in their class" do
36
+ NanoStore.shared_store.allObjectClasses.should == ["User"]
37
+ Car.create(:name => "Bob")
38
+ NanoStore.shared_store.allObjectClasses.sort.should == ["User", "Car"].sort
39
+ end
40
+ end
41
+
42
+ describe "::find" do
43
+ it "search object traditional way: supply key, operator and value" do
44
+ users = User.find(:name, NSFEqualTo, "Bob")
45
+ users.should.not.be.nil
46
+ user = users.first
47
+ user.should.not.be.nil
48
+ user.name.should.be == "Bob"
49
+ user.age.should.be == 10
50
+ end
51
+
52
+ it "search object with simple hash" do
53
+ user = User.find(:name => "Carl").first
54
+ user.name.should.be == "Carl"
55
+ user.age.should.be == 4
56
+ end
57
+
58
+ it "search object with simple hash with two class" do
59
+ Car.create(:name => "Carl")
60
+ users = User.find(:name => "Carl")
61
+ users.size.should.be == 1
62
+ user = users.first
63
+ user.name.should.be == "Carl"
64
+ user.age.should.be == 4
65
+ end
66
+
67
+ it "search object with array (OR)" do
68
+ users = User.find(:name => ["Carl", "Amy"])
69
+ users.size.should == 2
70
+
71
+ users.collect(&:name).include?("Carl").should == true
72
+ users.collect(&:name).include?("Amy").should == true
73
+ users.collect(&:name).include?("Bob").should == false
74
+ end
75
+
76
+ it "search object with multiple parameters" do
77
+ stub_user("Ronald", 18, Time.now).save
78
+ stub_user("Ronald", 29, Time.now).save
79
+ stub_user("Ronald", 36, Time.now).save
80
+ stub_user("Ronald", 39, Time.now).save
81
+ stub_user("Ronald", 49, Time.now).save
82
+ stub_user("Ronald", 59, Time.now).save
83
+
84
+ users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })
85
+ users.size.should == 1
86
+ user = users.first
87
+ user.name.should.be == "Ronald"
88
+ user.age.should.be == 59
89
+
90
+ users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFLessThan => 30 })
91
+ users.size.should == 2
92
+ user = users.first
93
+ user.name.should.be == "Ronald"
94
+ end
95
+
96
+ it "sort search results" do
97
+ stub_user("Alan", 39, Time.now).save
98
+ stub_user("Cat", 29, Time.now).save
99
+ stub_user("Dan", 36, Time.now).save
100
+ stub_user("Ted", 18, Time.now).save
101
+ stub_user("Zidd", 59, Time.now).save
102
+ stub_user("Sarah", 49, Time.now).save
103
+
104
+ users = User.find({:age => { NSFGreaterThan => 1 }}, {:sort => {:age => :asc}})
105
+ users.size.should == 9
106
+ user = users.first
107
+ user.name.should.be == "Carl"
108
+ user.age.should.be == 4
109
+ user = users.last
110
+ user.name.should.be == "Zidd"
111
+ user.age.should.be == 59
112
+
113
+ users = User.find({:age => { NSFGreaterThan => 1 }}, {:sort => {:age => 'DESC'}})
114
+ users.size.should == 9
115
+ user = users.last
116
+ user.name.should.be == "Carl"
117
+ user.age.should.be == 4
118
+ user = users.first
119
+ user.name.should.be == "Zidd"
120
+ user.age.should.be == 59
121
+ end
122
+
123
+ it "find object" do
124
+ users = User.find(:name, NSFEqualTo, "Bob")
125
+ users.size.should == 1
126
+
127
+ user = users.first
128
+ user.name.should == "Bob"
129
+ user.class.should == User
130
+ end
131
+
132
+ it "only return objects of the class" do
133
+ car = Car.create(:name => "Honda")
134
+ Car.find.size.should == 1
135
+ Car.find.first.key.should == car.key
136
+ end
137
+ end
138
+
139
+ describe "::find_by_key" do
140
+ it "should return object by key" do
141
+ name = "Julien"
142
+ age = 32
143
+ created_at = Time.now
144
+ user = stub_user("Julien", 32, Time.now)
145
+ user.save
146
+ user2 = User.find_by_key(user.key)
147
+ user2.should.not.be.nil
148
+ user2.key.should == user.key
149
+ user2.name.should == user.name
150
+ user2.age.should == user.age
151
+ end
152
+
153
+ it "should not find object by inexists key" do
154
+ User.find_by_key("invalid-key").should.be.nil
155
+ end
156
+ end
157
+
158
+ describe "::all" do
159
+ it "find all objects" do
160
+ User.count.should == 3
161
+ users = User.all
162
+ users.size.should == 3
163
+ end
164
+
165
+ it "find all objects, sorted" do
166
+ stub_user("Alan", 39, Time.now).save
167
+ stub_user("Cat", 29, Time.now).save
168
+ stub_user("Dan", 36, Time.now).save
169
+ stub_user("Ted", 18, Time.now).save
170
+ stub_user("Zidd", 59, Time.now).save
171
+ stub_user("Sarah", 49, Time.now).save
172
+
173
+ User.count.should == 9
174
+ users = User.all({:sort => {:age => :asc}})
175
+ users.size.should == 9
176
+ users.first.name.should == "Carl"
177
+ end
178
+
179
+ it "only return objects of the class" do
180
+ car = Car.create(:name => "Honda")
181
+ Car.count.should == 1
182
+ Car.all.size.should == 1
183
+ Car.all.first.key.should == car.key
184
+ end
185
+
186
+ it "only return objects of the class" do
187
+ car = Car.create(:name => "Honda")
188
+ Car.find_keys.size.should == 1
189
+ Car.find_keys.first.should == car.key
190
+ end
38
191
  end
39
-
40
- it "search object traditional way: supply key, operator and value" do
41
- users = User.find(:name, NSFEqualTo, "Bob")
42
- users.should.not.be.nil
43
- user = users.first
44
- user.should.not.be.nil
45
- user.name.should.be == "Bob"
46
- user.age.should.be == 10
47
- end
48
-
49
- it "search object with simple hash" do
50
- user = User.find(:name => "Carl").first
51
- user.name.should.be == "Carl"
52
- user.age.should.be == 4
53
- end
54
-
55
- it "search object with simple hash with two class" do
56
- Car.create(:name => "Carl")
57
- users = User.find(:name => "Carl")
58
- users.size.should.be == 1
59
- user = users.first
60
- user.name.should.be == "Carl"
61
- user.age.should.be == 4
62
- end
63
-
64
- it "search object with array (OR)" do
65
- users = User.find(:name => ["Carl", "Amy"])
66
- users.size.should == 2
67
-
68
- users.collect(&:name).include?("Carl").should == true
69
- users.collect(&:name).include?("Amy").should == true
70
- users.collect(&:name).include?("Bob").should == false
71
- end
72
-
73
-
74
- it "search object with multiple parameters" do
75
- stub_user("Ronald", 18, Time.now).save
76
- stub_user("Ronald", 29, Time.now).save
77
- stub_user("Ronald", 36, Time.now).save
78
- stub_user("Ronald", 39, Time.now).save
79
- stub_user("Ronald", 49, Time.now).save
80
- stub_user("Ronald", 59, Time.now).save
81
-
82
- users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })
83
- users.size.should == 1
84
- user = users.first
85
- user.name.should.be == "Ronald"
86
- user.age.should.be == 59
87
-
88
- users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFLessThan => 30 })
89
- users.size.should == 2
90
- user = users.first
91
- user.name.should.be == "Ronald"
92
- end
93
-
94
- it "sort search results" do
95
- stub_user("Alan", 39, Time.now).save
96
- stub_user("Cat", 29, Time.now).save
97
- stub_user("Dan", 36, Time.now).save
98
- stub_user("Ted", 18, Time.now).save
99
- stub_user("Zidd", 59, Time.now).save
100
- stub_user("Sarah", 49, Time.now).save
101
-
102
- users = User.find({:age => { NSFGreaterThan => 1 }}, {:sort => {:age => :asc}})
103
- users.size.should == 9
104
- user = users.first
105
- user.name.should.be == "Carl"
106
- user.age.should.be == 4
107
- user = users.last
108
- user.name.should.be == "Zidd"
109
- user.age.should.be == 59
110
-
111
- users = User.find({:age => { NSFGreaterThan => 1 }}, {:sort => {:age => 'DESC'}})
112
- users.size.should == 9
113
- user = users.last
114
- user.name.should.be == "Carl"
115
- user.age.should.be == 4
116
- user = users.first
117
- user.name.should.be == "Zidd"
118
- user.age.should.be == 59
119
- end
120
-
121
- it "find object" do
122
- users = User.find(:name, NSFEqualTo, "Bob")
123
- users.size.should == 1
124
-
125
- user = users.first
126
- user.name.should == "Bob"
127
- user.class.should == User
128
- end
129
-
130
- it "find object by key" do
131
- name = "Julien"
132
- age = 32
133
- created_at = Time.now
134
- user = stub_user("Julien", 32, Time.now)
135
- user.save
136
- user2 = User.find_by_key(user.key)
137
- user2.should.not.be.nil
138
- user2.key.should == user.key
139
- user2.name.should == user.name
140
- user2.age.should == user.age
141
- end
142
-
143
- it "should not find object by key" do
144
- User.find_by_key("invalid-key").should.be.nil
145
- end
146
-
147
- it "find all objects" do
148
- User.count.should == 3
149
- users = User.all
150
- users.size.should == 3
151
- end
152
-
153
- it "find all objects, sorted" do
154
- stub_user("Alan", 39, Time.now).save
155
- stub_user("Cat", 29, Time.now).save
156
- stub_user("Dan", 36, Time.now).save
157
- stub_user("Ted", 18, Time.now).save
158
- stub_user("Zidd", 59, Time.now).save
159
- stub_user("Sarah", 49, Time.now).save
160
-
161
- User.count.should == 9
162
- users = User.all({:sort => {:age => :asc}})
163
- users.size.should == 9
164
- users.first.name.should == "Carl"
165
- end
166
-
167
- it "#all only return objects of the class" do
168
- car = Car.create(:name => "Honda")
169
- Car.count.should == 1
170
- Car.all.size.should == 1
171
- Car.all.first.key.should == car.key
172
- end
173
-
174
- it "#find only return objects of the class" do
175
- car = Car.create(:name => "Honda")
176
- Car.find.size.should == 1
177
- Car.find.first.key.should == car.key
178
- end
179
-
180
- it "#find_keys only return objects of the class" do
181
- car = Car.create(:name => "Honda")
182
- Car.find_keys.size.should == 1
183
- Car.find_keys.first.should == car.key
184
- end
185
-
186
192
  end