arrest 0.0.21 → 0.0.23

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.
@@ -7,9 +7,9 @@ module Arrest
7
7
  "#{self.resource_name}"
8
8
  end
9
9
 
10
- def by_url(url)
10
+ def by_url(context, url)
11
11
  begin
12
- body = body_root(source().get_many(url))
12
+ body = body_root(source().get_many(context, url))
13
13
  rescue Arrest::Errors::DocumentNotFoundError
14
14
  Arrest::logger.info "DocumentNotFoundError for #{url} gracefully returning []"
15
15
  return []
@@ -20,9 +20,9 @@ module Arrest
20
20
  end
21
21
  end
22
22
 
23
- def all(filter={})
23
+ def all(context, filter={})
24
24
  begin
25
- body = body_root(source().get_many(self.resource_path, filter))
25
+ body = body_root(source().get_many(context, self.resource_path, filter))
26
26
  rescue Arrest::Errors::DocumentNotFoundError
27
27
  Arrest::logger.info "DocumentNotFoundError for #{self.resource_path} gracefully returning []"
28
28
  return []
@@ -43,12 +43,12 @@ module Arrest
43
43
  self.build(body)
44
44
  end
45
45
 
46
- def find(id)
46
+ def find(context, id)
47
47
  if id == nil || "" == id
48
48
  Arrest::logger.info "DocumentNotFoundError: no id given"
49
49
  raise Errors::DocumentNotFoundError.new
50
50
  end
51
- r = source().get_one "#{self.resource_path}/#{id}"
51
+ r = source().get_one(context, "#{self.resource_path}/#{id}")
52
52
  body = body_root(r)
53
53
  if body == nil || body.empty?
54
54
  Arrest::logger.info "DocumentNotFoundError for #{self.resource_path}/#{id}"
@@ -57,7 +57,7 @@ module Arrest
57
57
  resource = self.build body.merge({:id => id})
58
58
  # traverse fields for subresources and fill them in
59
59
  self.all_fields.find_all{|f| f.is_a?(HasManySubResourceAttribute)}.each do |attr|
60
- ids = AbstractResource::source.get_many_other_ids("#{resource.resource_location}/#{attr.sub_resource_field_name}")
60
+ ids = AbstractResource::source.get_many_other_ids(context, "#{resource.resource_location}/#{attr.sub_resource_field_name}")
61
61
  resource.send("#{attr.name}=", body_root(ids))
62
62
  end
63
63
  resource
@@ -76,8 +76,8 @@ module Arrest
76
76
  instance.instance_exec(call_args, &aproc)
77
77
  end
78
78
  end
79
- send :define_singleton_method, name do |args = nil|
80
- self.all.select do |instance|
79
+ send :define_singleton_method, name do |context, args = nil|
80
+ self.all(context).select do |instance|
81
81
  instance.instance_exec(args, &aproc)
82
82
  end
83
83
  end
@@ -102,12 +102,12 @@ module Arrest
102
102
  def scope name, &block
103
103
  super(name)
104
104
  if block_given?
105
- send :define_singleton_method, name do
106
- self.all.select &block
105
+ send :define_singleton_method, name do |context|
106
+ self.all(context).select(&block)
107
107
  end
108
108
  else
109
- send :define_singleton_method, name do
110
- body_root(source().get_many self.scoped_path(name)).map do |h|
109
+ send :define_singleton_method, name do |context|
110
+ body_root(source().get_many(context, self.scoped_path(name))).map do |h|
111
111
  self.build(h)
112
112
  end
113
113
  end
@@ -119,10 +119,10 @@ module Arrest
119
119
  resource_path + '/' + scope_name.to_s
120
120
  end
121
121
 
122
- def stub stub_id
123
- n = self.new
122
+ def stub(context, stub_id)
123
+ n = self.new(context)
124
124
  n.initialize_has_attributes({:id => stub_id}) do
125
- r = n.class.source().get_one "#{self.resource_path}/#{stub_id}"
125
+ r = n.class.source().get_one(@context, "#{self.resource_path}/#{stub_id}")
126
126
  body = n.class.body_root(r)
127
127
  n.init_from_hash(body, true)
128
128
  end
@@ -130,8 +130,8 @@ module Arrest
130
130
  end
131
131
 
132
132
 
133
- def delete_all
134
- source().delete_all(self.resource_path)
133
+ def delete_all(context)
134
+ source().delete_all(context, self.resource_path)
135
135
  end
136
136
  end
137
137
 
@@ -1,3 +1,3 @@
1
1
  module Arrest
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.23"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'arrest'
3
+ class ContextTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Arrest::Source.source = nil
7
+ end
8
+
9
+ class Facility < Arrest::RootResource
10
+ end
11
+
12
+
13
+ class HeaderDeco
14
+ def self.headers
15
+ puts "MAAAAAHH"
16
+ {}
17
+ end
18
+ end
19
+
20
+ def test_context
21
+ context = Arrest::RequestContext.new()
22
+ context.header_decorator = HeaderDeco
23
+ scope = Arrest::ScopedRoot.new(context)
24
+ assert_not_nil scope.Facility
25
+ assert_not_nil scope.Facility.all
26
+
27
+ f0 = scope.Facility.new(:name => 'Foo')
28
+ assert f0.save
29
+
30
+ f1 = scope.Facility.all.first
31
+ f2 = scope.Facility.find(f1.id)
32
+
33
+ end
34
+ end
35
+
@@ -5,11 +5,12 @@ class NestedResourcesTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  Arrest::Source.source = nil
8
+ @scope = Arrest::ScopedRoot.new
8
9
  #Arrest::Source.debug = true
9
10
  end
10
11
 
11
12
  def test_instance_test
12
- n = ANestedClass.new({:name => "foo", :underscore_name => "Bar"})
13
+ n = ANestedClass.new(nil, {:name => "foo", :underscore_name => "Bar"})
13
14
  assert_equal "foo", n.name
14
15
  assert_equal "Bar", n.underscore_name
15
16
  end
@@ -25,7 +26,7 @@ class NestedResourcesTest < Test::Unit::TestCase
25
26
  }
26
27
  }
27
28
 
28
- actual = WithNested.new(input)
29
+ actual = @scope.WithNested.new(input)
29
30
  assert_equal 'parent', actual.parent_name
30
31
  assert_equal false, actual.bool
31
32
  assert actual.respond_to? :nested_object, "The parent object should have an accessor for the nested object"
@@ -44,7 +45,7 @@ class NestedResourcesTest < Test::Unit::TestCase
44
45
  }
45
46
  }
46
47
 
47
- actual = WithNested.new(input)
48
+ actual = @scope.WithNested.new(input)
48
49
 
49
50
  assert_equal_hashes input, actual.to_hash
50
51
 
@@ -65,14 +66,14 @@ class NestedResourcesTest < Test::Unit::TestCase
65
66
  ]
66
67
  }
67
68
 
68
- actual = WithManyNested.new(input)
69
+ actual = @scope.WithManyNested.new(input)
69
70
 
70
71
  assert_equal_hashes input, actual.to_hash
71
72
 
72
73
  end
73
74
 
74
75
  def test_belongs_to_to_hash
75
- new_zoo = Zoo.new({:name => "Foo"})
76
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
76
77
  new_zoo.save
77
78
 
78
79
  input = {
@@ -85,7 +86,7 @@ class NestedResourcesTest < Test::Unit::TestCase
85
86
  }
86
87
  }
87
88
 
88
- actual = WithNestedBelongingTo.new(input)
89
+ actual = @scope.WithNestedBelongingTo.new(input)
89
90
 
90
91
  assert_equal_hashes input, actual.to_hash
91
92
 
@@ -96,10 +97,10 @@ class NestedResourcesTest < Test::Unit::TestCase
96
97
 
97
98
  def test_custom_belongs_to
98
99
 
99
- new_zoo = Zoo.new({:name => "Foo"})
100
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
100
101
  new_zoo.save
101
102
 
102
- c = CustomNamedBelongsTo.new({:name => 'Bar', :schinken => new_zoo.id, :batzen => new_zoo.id})
103
+ c = @scope.CustomNamedBelongsTo.new({:name => 'Bar', :schinken => new_zoo.id, :batzen => new_zoo.id})
103
104
 
104
105
  c.save
105
106
  assert_not_nil c.id, "Persisted object should have id"
@@ -108,7 +109,7 @@ class NestedResourcesTest < Test::Unit::TestCase
108
109
 
109
110
 
110
111
  assert_not_nil c.id, "Persisted zoo should have id"
111
- c_reloaded = CustomNamedBelongsTo.all.first
112
+ c_reloaded = @scope.CustomNamedBelongsTo.all.first
112
113
  assert_equal "Foo", c_reloaded.zoo_thing.name
113
114
  assert_equal "Foo", c_reloaded.zoo.name
114
115
 
@@ -5,6 +5,7 @@ class FirstTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  Arrest::Source.source = nil
8
+ @scope = Arrest::ScopedRoot.new
8
9
  #Arrest::Source.debug = true
9
10
  end
10
11
 
@@ -16,28 +17,29 @@ class FirstTest < Test::Unit::TestCase
16
17
 
17
18
  def test_init
18
19
  zooname = "Hagenbecks"
19
- z = Zoo.new({:name => zooname})
20
+ z = @scope.Zoo.new({:name => zooname})
20
21
  assert_equal zooname, z.name
21
22
  #assert_not_empty Arrest::AbstractResource.all_fields.select {|f| f.name == :id}, "AbstractResource defines the id field itself"
22
23
  #assert_not_empty Arrest::RootResource.all_fields.select {|f| f.name == :id}, "RootResource should inherit id from AbstractResource"
23
- #assert_not_empty Zoo.all_fields.select {|f| f.name == :id}, "Zoo should inherit id field from RootResource"
24
+ #assert_not_empty @scope.Zoo.all_fields.select {|f| f.name == :id}, "Zoo should inherit id field from RootResource"
24
25
  end
25
26
 
26
27
  def test_create
27
- zoo_count_before = Zoo.all.length
28
- new_zoo = Zoo.new({:name => "Foo"})
29
- new_zoo.save
30
- zoo_count_after = Zoo.all.length
28
+ zoo_count_before = @scope.Zoo.all.length
29
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
30
+ assert_equal "Foo", new_zoo.name
31
+ assert new_zoo.save, new_zoo.errors.full_messages.to_s
32
+ zoo_count_after = @scope.Zoo.all.length
31
33
  assert_not_nil new_zoo.id
32
34
 
33
35
  assert_equal (zoo_count_before + 1), zoo_count_after
34
36
  assert new_zoo.id != nil
35
37
 
36
- zoo_the_last = Zoo.all.last
38
+ zoo_the_last = @scope.Zoo.all.last
37
39
  assert_equal new_zoo.name, zoo_the_last.name
38
40
  assert_equal new_zoo.id, zoo_the_last.id
39
41
 
40
- zoo_reloaded = Zoo.find(new_zoo.id)
42
+ zoo_reloaded = @scope.Zoo.find(new_zoo.id)
41
43
  assert_equal new_zoo.name, zoo_reloaded.name
42
44
  assert_equal new_zoo.id, zoo_reloaded.id
43
45
  end
@@ -50,17 +52,17 @@ class FirstTest < Test::Unit::TestCase
50
52
  ]
51
53
 
52
54
  invalid_params.each do |p|
53
- zoo_count_before = Zoo.all.length
54
- new_zoo = Zoo.new(p)
55
+ zoo_count_before = @scope.Zoo.all.length
56
+ new_zoo = @scope.Zoo.new(p)
55
57
  assert_equal false, new_zoo.save, "zoo without name shouldnt be persistable"
56
- assert_equal zoo_count_before, Zoo.all.length
58
+ assert_equal zoo_count_before, @scope.Zoo.all.length
57
59
  assert_equal :name, new_zoo.errors.first[0]
58
60
  assert_nil new_zoo.id
59
61
 
60
62
  new_zoo.name = "Foo"
61
63
 
62
64
  assert new_zoo.save, "Creating should be possible after setting a name"
63
- zoo_count_after = Zoo.all.length
65
+ zoo_count_after = @scope.Zoo.all.length
64
66
  assert_not_nil new_zoo.id
65
67
 
66
68
  assert_equal (zoo_count_before + 1), zoo_count_after
@@ -72,35 +74,35 @@ class FirstTest < Test::Unit::TestCase
72
74
  end
73
75
 
74
76
  def test_delete
75
- zoo_count_before = Zoo.all.length
76
- new_zoo = Zoo.new({:name => "Foo"})
77
+ zoo_count_before = @scope.Zoo.all.length
78
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
77
79
  new_zoo.save
78
- zoo_count_after = Zoo.all.length
80
+ zoo_count_after = @scope.Zoo.all.length
79
81
 
80
82
  assert_equal (zoo_count_before + 1), zoo_count_after
81
83
  assert new_zoo.id != nil
82
84
 
83
- zoo_the_last = Zoo.all.last
85
+ zoo_the_last = @scope.Zoo.all.last
84
86
  assert_equal new_zoo.name, zoo_the_last.name
85
87
 
86
- zoo_reloaded = Zoo.find(new_zoo.id)
88
+ zoo_reloaded = @scope.Zoo.find(new_zoo.id)
87
89
  assert_equal new_zoo.name, zoo_reloaded.name
88
90
 
89
91
  zoo_reloaded.delete
90
- assert_equal zoo_count_before, Zoo.all.length
92
+ assert_equal zoo_count_before, @scope.Zoo.all.length
91
93
  end
92
94
 
93
95
  def test_create_and_load
94
- zoo_count_before = Zoo.all.length
95
- new_zoo = Zoo.new({:name => "Foo"})
96
+ zoo_count_before = @scope.Zoo.all.length
97
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
96
98
  new_zoo.save
97
- zoo_count_after = Zoo.all.length
99
+ zoo_count_after = @scope.Zoo.all.length
98
100
 
99
101
  assert_equal (zoo_count_before + 1), zoo_count_after
100
102
  end
101
103
 
102
104
  def test_update
103
- new_zoo = Zoo.new({:name => "Foo"})
105
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
104
106
  new_zoo.save
105
107
 
106
108
  new_zoo_name = "Hagenbecks"
@@ -109,7 +111,7 @@ class FirstTest < Test::Unit::TestCase
109
111
 
110
112
  assert new_zoo.id != nil
111
113
 
112
- zoo_reloaded = Zoo.find(new_zoo.id)
114
+ zoo_reloaded = @scope.Zoo.find(new_zoo.id)
113
115
  assert_not_nil zoo_reloaded
114
116
  assert_equal new_zoo.id, zoo_reloaded.id
115
117
 
@@ -117,13 +119,13 @@ class FirstTest < Test::Unit::TestCase
117
119
  end
118
120
 
119
121
  def test_child
120
- new_zoo = Zoo.new({:name => "Foo"})
122
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
121
123
  new_zoo.save
122
124
  assert_not_nil new_zoo.id
123
125
  #assert_not_nil new_zoo.class.all_fields.select {|f| f.name = :id}
124
126
 
125
127
  animal_kind = "mouse"
126
- new_animal = Animal.new new_zoo, {:kind => animal_kind, :age => 42}
128
+ new_animal = @scope.Animal.new new_zoo, {:kind => animal_kind, :age => 42}
127
129
  assert new_zoo.id != nil
128
130
  assert_equal new_zoo.id, new_animal.zoo.id
129
131
  assert_equal new_zoo.id, new_animal.parent.id
@@ -132,7 +134,7 @@ class FirstTest < Test::Unit::TestCase
132
134
 
133
135
  assert new_animal.id != nil
134
136
 
135
- zoo_reloaded = Zoo.find(new_zoo.id)
137
+ zoo_reloaded = @scope.Zoo.find(new_zoo.id)
136
138
  assert_equal new_zoo.id, zoo_reloaded.id
137
139
  assert_equal new_animal.parent.id, zoo_reloaded.id
138
140
 
@@ -148,11 +150,11 @@ class FirstTest < Test::Unit::TestCase
148
150
  end
149
151
 
150
152
  def test_child_update
151
- new_zoo = Zoo.new({:name => "Foo"})
153
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
152
154
  new_zoo.save
153
155
 
154
156
  animal_kind = "mouse"
155
- new_animal = Animal.new new_zoo, {:kind => "foo", :age => 42}
157
+ new_animal = @scope.Animal.new new_zoo, {:kind => "foo", :age => 42}
156
158
  new_animal.save
157
159
 
158
160
  animal_reloaded = new_zoo.animals.first
@@ -166,13 +168,13 @@ class FirstTest < Test::Unit::TestCase
166
168
  end
167
169
 
168
170
  def test_inheritance
169
- new_zoo = SpecialZoo.new({:name => "Foo", :is_magic => true})
171
+ new_zoo = @scope.SpecialZoo.new({:name => "Foo", :is_magic => true})
170
172
  assert_equal "Foo", new_zoo.name
171
173
  assert_equal true, new_zoo.is_magic
172
174
  new_zoo.save
173
175
 
174
176
  assert new_zoo.id != nil, "Zoo must have id after save"
175
- zoo_reloaded = SpecialZoo.find(new_zoo.id)
177
+ zoo_reloaded = @scope.SpecialZoo.find(new_zoo.id)
176
178
  assert_equal new_zoo.id, zoo_reloaded.id
177
179
  assert_equal true, zoo_reloaded.is_magic
178
180
  assert_equal "Foo", zoo_reloaded.name
@@ -181,11 +183,11 @@ class FirstTest < Test::Unit::TestCase
181
183
  def test_inheritance_update
182
184
  assert_equal :zoo3000, SpecialZoo.resource_name
183
185
 
184
- new_zoo = SpecialZoo.new({:name => "Foo", :is_magic => true})
186
+ new_zoo = @scope.SpecialZoo.new({:name => "Foo", :is_magic => true})
185
187
  new_zoo.save
186
188
 
187
189
  assert new_zoo.id != nil, "Zoo must have id after save"
188
- zoo_reloaded = SpecialZoo.find(new_zoo.id)
190
+ zoo_reloaded = @scope.SpecialZoo.find(new_zoo.id)
189
191
  assert_equal true, zoo_reloaded.is_magic
190
192
  assert_equal "Foo", zoo_reloaded.name
191
193
 
@@ -195,14 +197,14 @@ class FirstTest < Test::Unit::TestCase
195
197
  zoo_reloaded.is_magic = !zoo_reloaded.is_magic
196
198
  zoo_reloaded.save
197
199
 
198
- updated_zoo = SpecialZoo.find(zoo_reloaded.id)
200
+ updated_zoo = @scope.SpecialZoo.find(zoo_reloaded.id)
199
201
  assert_equal new_name, updated_zoo.name
200
202
  assert_equal !old_is_magic, updated_zoo.is_magic
201
203
  end
202
204
 
203
205
  def test_read_only_attributes
204
206
  now = Time.now
205
- zoo = SpecialZoo.new({
207
+ zoo = @scope.SpecialZoo.new({
206
208
  :name => "Zoo",
207
209
  :ro1 => "one",
208
210
  :ro2 => "two",
@@ -225,12 +227,12 @@ class FirstTest < Test::Unit::TestCase
225
227
  end
226
228
 
227
229
  def test_stub_delayed_load
228
- new_zoo = Zoo.new({:name => "Foo"})
230
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
229
231
  new_zoo.save
230
232
 
231
233
  assert_not_nil new_zoo.id
232
234
 
233
- stubbed = Zoo.stub(new_zoo.id)
235
+ stubbed = @scope.Zoo.stub(new_zoo.id)
234
236
  assert stubbed.stubbed?, "Zoo should be a stub, so not loaded yet"
235
237
  new_name = stubbed.name
236
238
  assert !stubbed.stubbed?, "Zoo should not be a stub, so loaded now"
@@ -239,14 +241,14 @@ class FirstTest < Test::Unit::TestCase
239
241
  end
240
242
 
241
243
  def test_stub_not_load_for_child_access
242
- new_zoo = Zoo.new({:name => "Foo"})
244
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
243
245
  new_zoo.save
244
246
 
245
247
  assert_not_nil new_zoo.id
246
248
  # this is where the magic hapens
247
- stubbed = Zoo.stub(new_zoo.id)
249
+ stubbed = @scope.Zoo.stub(new_zoo.id)
248
250
 
249
- new_animal = Animal.new new_zoo, {:kind => "foo", :age => 42}
251
+ new_animal = @scope.Animal.new new_zoo, {:kind => "foo", :age => 42}
250
252
  new_animal.save
251
253
 
252
254
  assert stubbed.stubbed?, "Zoo should be a stub, so not loaded yet"
@@ -263,11 +265,11 @@ class FirstTest < Test::Unit::TestCase
263
265
  end
264
266
 
265
267
  def test_root_scope
266
- assert_not_nil Zoo.server_scope
268
+ assert_not_nil @scope.Zoo.server_scope
267
269
  end
268
270
 
269
271
  def test_child_scope
270
- new_zoo = Zoo.new({:name => "Foo"})
272
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
271
273
  new_zoo.save
272
274
 
273
275
  assert_not_nil new_zoo.id
@@ -277,54 +279,54 @@ class FirstTest < Test::Unit::TestCase
277
279
 
278
280
  def test_local_scope
279
281
 
280
- zoo_false = Zoo.new({:name => "Foo", :open => false})
282
+ zoo_false = @scope.Zoo.new({:name => "Foo", :open => false})
281
283
  zoo_false.save
282
- zoo_true = Zoo.new({:name => "Foo", :open => true})
284
+ zoo_true = @scope.Zoo.new({:name => "Foo", :open => true})
283
285
  zoo_true.save
284
286
 
285
- assert_equal 1, Zoo.open.length
286
- assert_equal true, Zoo.open.first.open
287
+ assert_equal 1, @scope.Zoo.open.length
288
+ assert_equal true, @scope.Zoo.open.first.open
287
289
  end
288
290
 
289
291
  def test_local_child_scope
290
- new_zoo = Zoo.new({:name => "Foo"})
292
+ new_zoo = @scope.Zoo.new({:name => "Foo"})
291
293
  new_zoo.save
292
294
 
293
- new_zoo2 = Zoo.new({:name => "Boo"})
295
+ new_zoo2 = @scope.Zoo.new({:name => "Boo"})
294
296
  new_zoo2.save
295
297
 
296
298
  animal_kind = "mouse"
297
- Animal.new(new_zoo, {:kind => animal_kind, :age => 42, :male => true}).save
298
- Animal.new(new_zoo, {:kind => animal_kind, :age => 42, :male => false}).save
299
- Animal.new(new_zoo2, {:kind => animal_kind, :age => 42, :male => false}).save
299
+ @scope.Animal.new(new_zoo, {:kind => animal_kind, :age => 42, :male => true}).save
300
+ @scope.Animal.new(new_zoo, {:kind => animal_kind, :age => 42, :male => false}).save
301
+ @scope.Animal.new(new_zoo2, {:kind => animal_kind, :age => 42, :male => false}).save
300
302
 
301
- assert_equal 2, Zoo.all.first.animals.length
302
- assert_equal 1, Zoo.all.last.animals.length
303
- assert_equal 1, Zoo.all.first.animals.males_only.length
304
- assert_equal true, Zoo.all.first.animals.males_only.first.male
303
+ assert_equal 2, @scope.Zoo.all.first.animals.length
304
+ assert_equal 1, @scope.Zoo.all.last.animals.length
305
+ assert_equal 1, @scope.Zoo.all.first.animals.males_only.length
306
+ assert_equal true, @scope.Zoo.all.first.animals.males_only.first.male
305
307
 
306
308
  end
307
309
 
308
310
  def test_para_filter
309
- p1 = ParentFilter.new({:afield => "Foo"})
310
- p2 = ParentFilter.new({:afield => "Bar"})
311
+ p1 = @scope.ParentFilter.new({:afield => "Foo"})
312
+ p2 = @scope.ParentFilter.new({:afield => "Bar"})
311
313
  p1.save
312
314
  p2.save
313
315
 
314
- nnn = ParentFilter.nnn("Foo")
316
+ nnn = @scope.ParentFilter.nnn("Foo")
315
317
  assert_equal ["Foo"], nnn.map(&:afield)
316
318
  end
317
319
 
318
320
  def test_para_filter_child
319
- p1 = ParentFilter.new({:afield => "ParentFoo"})
321
+ p1 = @scope.ParentFilter.new({:afield => "ParentFoo"})
320
322
  p1.save
321
323
 
322
- c1 = ChildFilter.new(p1, :bfield => "Foo")
324
+ c1 = @scope.ChildFilter.new(p1, :bfield => "Foo")
323
325
  c1.save
324
- c2 = ChildFilter.new(p1, :bfield => "Bar")
326
+ c2 = @scope.ChildFilter.new(p1, :bfield => "Bar")
325
327
  c2.save
326
328
 
327
- reloaded_parent = ParentFilter.find(p1.id)
329
+ reloaded_parent = @scope.ParentFilter.find(p1.id)
328
330
  assert_not_nil reloaded_parent
329
331
  assert_equal "ParentFoo", reloaded_parent.afield
330
332
  assert_equal 2, reloaded_parent.child_filters.length
@@ -333,24 +335,24 @@ class FirstTest < Test::Unit::TestCase
333
335
  end
334
336
 
335
337
  def test_no_param_filter
336
- p1 = ParentFilter.new({:afield => "Foo"})
337
- p2 = ParentFilter.new({:afield => "Bar"})
338
+ p1 = @scope.ParentFilter.new({:afield => "Foo"})
339
+ p2 = @scope.ParentFilter.new({:afield => "Bar"})
338
340
  p1.save
339
341
  p2.save
340
342
 
341
- no_param = ParentFilter.no_param
343
+ no_param = @scope.ParentFilter.no_param
342
344
  assert_equal ["Foo"], no_param.map(&:afield)
343
345
  end
344
346
 
345
347
  def test_has_many
346
- Zoo.new(:name => "Foo1").save
347
- Zoo.new(:name => "Foo2").save
348
- assert_equal 2, Zoo.all.length
349
- all_zoo_ids = Zoo.all.map(&:id)
350
- v1 = ZooOwner.new({:name => "Foo", :zoo_ids => all_zoo_ids})
348
+ @scope.Zoo.new(:name => "Foo1").save
349
+ @scope.Zoo.new(:name => "Foo2").save
350
+ assert_equal 2, @scope.Zoo.all.length
351
+ all_zoo_ids = @scope.Zoo.all.map(&:id)
352
+ v1 = @scope.ZooOwner.new({:name => "Foo", :zoo_ids => all_zoo_ids})
351
353
  v1.save
352
354
 
353
- v1_reloaded = ZooOwner.all.first
355
+ v1_reloaded = @scope.ZooOwner.all.first
354
356
  assert_equal all_zoo_ids, v1_reloaded.zoo_ids
355
357
 
356
358
  url = v1.resource_location + '/' + Zoo.resource_name
@@ -360,7 +362,7 @@ class FirstTest < Test::Unit::TestCase
360
362
  end
361
363
 
362
364
  def test_build
363
- v1 = ZooOwner.new({:name => "Foo"})
365
+ v1 = @scope.ZooOwner.new({:name => "Foo"})
364
366
  v1.save
365
367
 
366
368
  zoo = v1.zoos.build
@@ -368,18 +370,18 @@ class FirstTest < Test::Unit::TestCase
368
370
  end
369
371
 
370
372
  def test_scope_has_many
371
- z1 = Zoo.new(:name => "Foo1", :open => true)
373
+ z1 = @scope.Zoo.new(:name => "Foo1", :open => true)
372
374
  z1.save
373
- z2 = Zoo.new(:name => "Foo2", :open => false)
375
+ z2 = @scope.Zoo.new(:name => "Foo2", :open => false)
374
376
  z2.save
375
- z3 = Zoo.new(:name => "Foo3", :open => true)
377
+ z3 = @scope.Zoo.new(:name => "Foo3", :open => true)
376
378
  z3.save
377
- assert_equal 3, Zoo.all.length
379
+ assert_equal 3, @scope.Zoo.all.length
378
380
  all_zoo_ids = [z1.id, z2.id]
379
- v1 = ZooOwner.new({:name => "Foo", :zoo_ids => all_zoo_ids})
381
+ v1 = @scope.ZooOwner.new({:name => "Foo", :zoo_ids => all_zoo_ids})
380
382
  v1.save
381
383
 
382
- v1_reloaded = ZooOwner.all.first
384
+ v1_reloaded = @scope.ZooOwner.all.first
383
385
  assert_equal all_zoo_ids, v1_reloaded.zoo_ids
384
386
 
385
387
  url = v1.resource_location + '/' + Zoo.resource_name
@@ -389,79 +391,79 @@ class FirstTest < Test::Unit::TestCase
389
391
 
390
392
  assert_equal 1, v1_reloaded.zoos.open_filter.length
391
393
  assert_equal "Foo1", v1_reloaded.zoos.open_filter.first.name
392
- assert_equal 3, Zoo.all.length
394
+ assert_equal 3, @scope.Zoo.all.length
393
395
  end
394
396
 
395
397
  def test_time
396
398
  now = Time.now
397
399
  expected = now.strftime "%FT%T%z"
398
- t = TimeClass.new(:time => now)
400
+ t = @scope.TimeClass.new(:time => now)
399
401
  assert_equal expected, t.to_jhash[:time], "This is the expected default format"
400
402
  end
401
403
 
402
404
  def test_polymorphic_belongs_to
403
- coma = CommentableA.new()
405
+ coma = @scope.CommentableA.new()
404
406
  coma.save
405
- comb = CommentableB.new()
407
+ comb = @scope.CommentableB.new()
406
408
  comb.save
407
409
 
408
- c = Comment.new(:commentable_ref => { :id => coma.id, :type => "coma"})
410
+ c = @scope.Comment.new(:commentable_ref => { :id => coma.id, :type => "coma"})
409
411
  result = c.commentable
410
412
  assert_equal coma.id, c.commentable_ref.id
411
413
  assert_equal result.class, CommentableA
412
414
 
413
- c2 = Comment.new(:commentable_ref => { :id => comb.id, :type => "comb"})
415
+ c2 = @scope.Comment.new(:commentable_ref => { :id => comb.id, :type => "comb"})
414
416
  result2 = c2.commentable
415
417
  assert_equal comb.id, c2.commentable_ref.id
416
418
  assert_equal result2.class, CommentableB
417
419
  end
418
420
 
419
421
  def test_polymorphic_belongs_to_extended
420
- coma = CommentableA.new()
422
+ coma = @scope.CommentableA.new()
421
423
  coma.save
422
- comc = CommentableC.new()
424
+ comc = @scope.CommentableC.new()
423
425
  comc.save
424
426
 
425
- c = ExtendedComment.new({ :special_commentable_ref => { :id => comc.id, :type => "comc"},
427
+ c = @scope.ExtendedComment.new({ :special_commentable_ref => { :id => comc.id, :type => "comc"},
426
428
  :commentable_ref => { :id => coma.id, :type => "coma" }})
427
429
  assert_equal c.commentable.class, CommentableA
428
430
  assert_equal c.other_commentable.class, CommentableC
429
431
 
430
432
  c.save
431
- c_reloaded = ExtendedComment.find(c.id)
433
+ c_reloaded = @scope.ExtendedComment.find(c.id)
432
434
  assert_equal comc.id, c_reloaded.special_commentable_ref.id
433
435
  assert_equal CommentableC, c_reloaded.other_commentable.class
434
436
  assert_equal CommentableA, c_reloaded.commentable.class
435
437
  end
436
438
 
437
439
  def test_delete_all_root_resources
438
- d1 = DeleteMeAll.new()
440
+ d1 = @scope.DeleteMeAll.new()
439
441
  d1.save
440
- d2 = DeleteMeAll.new()
442
+ d2 = @scope.DeleteMeAll.new()
441
443
  d2.save
442
444
 
443
- d1_rel = DeleteMeAll.find(d1.id)
445
+ d1_rel = @scope.DeleteMeAll.find(d1.id)
444
446
  assert_not_nil d1_rel
445
- d2_rel = DeleteMeAll.find(d2.id)
447
+ d2_rel = @scope.DeleteMeAll.find(d2.id)
446
448
  assert_not_nil d2_rel
447
- all = DeleteMeAll.all
449
+ all = @scope.DeleteMeAll.all
448
450
  assert_equal 2, all.length
449
451
 
450
- DeleteMeAll.delete_all
451
- all = DeleteMeAll.all
452
+ @scope.DeleteMeAll.delete_all
453
+ all = @scope.DeleteMeAll.all
452
454
  assert_equal [], all
453
455
  end
454
456
 
455
457
  def test_update_belongs_to
456
- f1 = Foo.new()
458
+ f1 = @scope.Foo.new()
457
459
  f1.save
458
460
  assert_equal 0, Arrest::Source.source.edge_count
459
- b1 = Bar.new({:foo_id => f1.id})
461
+ b1 = @scope.Bar.new({:foo_id => f1.id})
460
462
  b1.save
461
463
  assert_equal 2, Arrest::Source.source.edge_count
462
464
  assert_equal 2, Arrest::Source.source.node_count
463
465
 
464
- f2 = Foo.new()
466
+ f2 = @scope.Foo.new()
465
467
  f2.save
466
468
  assert_equal 2, Arrest::Source.source.edge_count
467
469
  b1.foo_id = f2.id
@@ -472,24 +474,24 @@ class FirstTest < Test::Unit::TestCase
472
474
  end
473
475
 
474
476
  def test_has_many_matrix_in_mem_source
475
- f1 = Foo.new()
477
+ f1 = @scope.Foo.new()
476
478
  f1.save
477
- f2 = Foo.new()
479
+ f2 = @scope.Foo.new()
478
480
  f2.save
479
- f3 = Foo.new()
481
+ f3 = @scope.Foo.new()
480
482
  f3.save
481
483
 
482
- b1 = Bar.new({:foo_ids => [f1.id, f2.id], :foo_id => f3.id})
484
+ b1 = @scope.Bar.new({:foo_ids => [f1.id, f2.id], :foo_id => f3.id})
483
485
  b1.save
484
486
 
485
487
  assert_equal 2, b1.foos.length
486
488
 
487
- b2 = Bar.new({:foo_ids => [f2.id, f3.id], :foo_id =>f1.id})
489
+ b2 = @scope.Bar.new({:foo_ids => [f2.id, f3.id], :foo_id =>f1.id})
488
490
  b2.save
489
491
 
490
492
  f1.delete
491
493
 
492
- b1_rel = Bar.find(b1.id)
494
+ b1_rel = @scope.Bar.find(b1.id)
493
495
  assert_equal 1, b1_rel.foos.length
494
496
  assert_equal f2.id, b1_rel.foos.first.id
495
497
 
@@ -497,13 +499,13 @@ class FirstTest < Test::Unit::TestCase
497
499
  f2.bar_ids=[b1.id]
498
500
  f2.other_bar_ids=[b2.id]
499
501
  f2.save
500
- f2_rel = Foo.find(f2.id)
502
+ f2_rel = @scope.Foo.find(f2.id)
501
503
  assert_equal 1, f2_rel.bars.length
502
504
  assert_equal 1, f2_rel.other_bars.length
503
505
 
504
506
  b2.delete
505
507
 
506
- f2_rel = Foo.find(f2.id)
508
+ f2_rel = @scope.Foo.find(f2.id)
507
509
  assert_equal 1, f2_rel.bars.length
508
510
  assert_equal 0, f2_rel.other_bars.length
509
511
  assert_equal b1.id, f2_rel.bars.first.id
@@ -511,21 +513,21 @@ class FirstTest < Test::Unit::TestCase
511
513
  end
512
514
 
513
515
  def test_has_many_with_belongs_to
514
- f1 = Foo.new()
516
+ f1 = @scope.Foo.new()
515
517
  f1.save
516
- f2 = Foo.new()
518
+ f2 = @scope.Foo.new()
517
519
  f2.save
518
- f3 = Foo.new()
520
+ f3 = @scope.Foo.new()
519
521
  f3.save
520
522
 
521
- b1 = Bar.new({:other_foo_id => f1.id, :foo_id => f3.id})
523
+ b1 = @scope.Bar.new({:other_foo_id => f1.id, :foo_id => f3.id})
522
524
  b1.save
523
- b2 = Bar.new({:other_foo_id => f2.id, :foo_id => f1.id})
525
+ b2 = @scope.Bar.new({:other_foo_id => f2.id, :foo_id => f1.id})
524
526
  b2.save
525
527
 
526
- f1_rel = Foo.find(f1.id)
527
- f2_rel = Foo.find(f2.id)
528
- f3_rel = Foo.find(f3.id)
528
+ f1_rel = @scope.Foo.find(f1.id)
529
+ f2_rel = @scope.Foo.find(f2.id)
530
+ f3_rel = @scope.Foo.find(f3.id)
529
531
 
530
532
  assert_equal 1, f1_rel.bars.length
531
533
  assert_equal b1.id, f1_rel.other_bars.first.id
@@ -539,19 +541,19 @@ class FirstTest < Test::Unit::TestCase
539
541
  b1.save
540
542
 
541
543
 
542
- f3_rel = Foo.find(f3.id)
544
+ f3_rel = @scope.Foo.find(f3.id)
543
545
  assert f3_rel.bars.empty?
544
- f2_rel = Foo.find(f2.id)
546
+ f2_rel = @scope.Foo.find(f2.id)
545
547
  assert_equal b1.id, f2_rel.bars.first.id
546
548
 
547
549
  b1.delete
548
- f1_rel = Foo.find(f1.id)
550
+ f1_rel = @scope.Foo.find(f1.id)
549
551
  assert f1_rel.other_bars.empty?
550
552
  end
551
553
 
552
554
  def test_equality_non_persistent
553
- zoo1 = Zoo.new(:name => 'zoo1')
554
- zoo2 = Zoo.new(:name => 'zoo2')
555
+ zoo1 = @scope.Zoo.new(:name => 'zoo1')
556
+ zoo2 = @scope.Zoo.new(:name => 'zoo2')
555
557
  zoo1.id = '1'
556
558
  zoo2.id = '1'
557
559
 
@@ -563,8 +565,8 @@ class FirstTest < Test::Unit::TestCase
563
565
  end
564
566
 
565
567
  def test_equality
566
- zoo1 = Zoo.new(:name => 'zoo1')
567
- zoo2 = Zoo.new(:name => 'zoo2')
568
+ zoo1 = @scope.Zoo.new(:name => 'zoo1')
569
+ zoo2 = @scope.Zoo.new(:name => 'zoo2')
568
570
 
569
571
  assert zoo1.save, 'simple zoo should be saveable'
570
572
  assert zoo2.save, 'simple zoo should be saveable'
@@ -577,12 +579,12 @@ class FirstTest < Test::Unit::TestCase
577
579
 
578
580
  assert_not_equal zoo1, nil, 'Anactual object should not equal nil'
579
581
 
580
- zoo1_reloaded = Zoo.find(zoo1.id)
582
+ zoo1_reloaded = @scope.Zoo.find(zoo1.id)
581
583
  assert_not_nil zoo1_reloaded
582
584
 
583
585
  assert zoo1 == zoo1_reloaded, "Objects of the same class with the same id should be equal"
584
586
 
585
- foo = Foo.new()
587
+ foo = @scope.Foo.new()
586
588
  foo.id = zoo1.id
587
589
 
588
590
  assert_not_equal zoo1, foo, "Objects of different classes should not be euqal, even if they have the same id"
@@ -592,7 +594,7 @@ class FirstTest < Test::Unit::TestCase
592
594
  end
593
595
 
594
596
  def test_has_many_sub_resource_attr_setter
595
- b = BarWithHasManySubResource.new()
597
+ b = @scope.BarWithHasManySubResource.new()
596
598
  b.save
597
599
 
598
600
  assert_raise ArgumentError do
@@ -607,7 +609,7 @@ class FirstTest < Test::Unit::TestCase
607
609
  end
608
610
 
609
611
  def test_update_attribute
610
- zoo1 = Zoo.new(:name => 'zoo1')
612
+ zoo1 = @scope.Zoo.new(:name => 'zoo1')
611
613
  zoo1.update_attributes({:name => "updated"})
612
614
  assert_equal "updated", zoo1.name
613
615
  end