rezource 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rezource.rb +2 -2
- data/rezource.gemspec +1 -1
- data/test/test_rezource.rb +35 -6
- metadata +2 -2
data/lib/rezource.rb
CHANGED
@@ -175,7 +175,7 @@ module Rezource
|
|
175
175
|
def parent_ivar; parent_class.name.split("::").last.underscore; end
|
176
176
|
def parent_ivar_set(value); instance_variable_set("@#{parent_ivar}", value); value; end
|
177
177
|
def parent_ivar_get; instance_variable_get "@#{parent_ivar}"; end
|
178
|
-
def parent; parent_ivar_get; end
|
178
|
+
def parent; parent_ivar_get || find_parent; end
|
179
179
|
|
180
180
|
|
181
181
|
# -----------
|
@@ -233,7 +233,7 @@ module Rezource
|
|
233
233
|
def resources_ivar; resource_class.name.split("::").last.pluralize.underscore; end
|
234
234
|
def resources_ivar_set(value); instance_variable_set("@#{resources_ivar}", value); value; end
|
235
235
|
def resources_ivar_get; instance_variable_get "@#{resources_ivar}"; end
|
236
|
-
def resources; resources_ivar_get; end
|
236
|
+
def resources; resources_ivar_get || find_resources; end
|
237
237
|
|
238
238
|
def before_create(resource); end
|
239
239
|
def before_update(resource); end
|
data/rezource.gemspec
CHANGED
data/test/test_rezource.rb
CHANGED
@@ -450,9 +450,15 @@ class RezourceTest < Test::Unit::TestCase
|
|
450
450
|
assert_equal 123, c.resources_ivar_get
|
451
451
|
end
|
452
452
|
|
453
|
-
def
|
453
|
+
def test_resources__without_existing_ivar
|
454
454
|
c = SamplesController.new
|
455
|
-
c.expects(:
|
455
|
+
c.expects(:find_resources)
|
456
|
+
c.resources
|
457
|
+
end
|
458
|
+
|
459
|
+
def test_resources__existing_ivar
|
460
|
+
c = SamplesController.new
|
461
|
+
c.expects(:resources_ivar_get).returns 1
|
456
462
|
c.resources
|
457
463
|
end
|
458
464
|
|
@@ -480,7 +486,7 @@ class RezourceTest < Test::Unit::TestCase
|
|
480
486
|
assert_equal SampleParent, c.parent_class
|
481
487
|
end
|
482
488
|
|
483
|
-
def
|
489
|
+
def test_find_parent
|
484
490
|
c = SamplesController.resource(belongs_to: SampleParent).new
|
485
491
|
|
486
492
|
scope = mock()
|
@@ -511,9 +517,15 @@ class RezourceTest < Test::Unit::TestCase
|
|
511
517
|
assert_equal 123, c.parent_ivar_get
|
512
518
|
end
|
513
519
|
|
514
|
-
def
|
520
|
+
def test_parent__existing_ivar
|
521
|
+
c = SamplesController.resource(belongs_to: SampleParent).new
|
522
|
+
c.expects(:parent_ivar_get).returns 1
|
523
|
+
c.parent
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_parent__without_existing_ivar
|
515
527
|
c = SamplesController.resource(belongs_to: SampleParent).new
|
516
|
-
c.expects(:
|
528
|
+
c.expects(:find_parent)
|
517
529
|
c.parent
|
518
530
|
end
|
519
531
|
|
@@ -566,7 +578,24 @@ class RezourceTest < Test::Unit::TestCase
|
|
566
578
|
c.resource_update m, attributes
|
567
579
|
end
|
568
580
|
|
569
|
-
|
581
|
+
def test_resource_update__valid_and_singleton
|
582
|
+
c = SamplesController.resource(singleton: true).new
|
583
|
+
attributes = {name: "joe"}
|
584
|
+
|
585
|
+
m = mock()
|
586
|
+
e = mock()
|
587
|
+
|
588
|
+
c.expects(:before_update).with(m)
|
589
|
+
m.expects(:errors).returns e
|
590
|
+
e.expects(:any?).returns false
|
591
|
+
m.expects(:update_attributes).with(attributes)
|
592
|
+
c.expects(:after_update).with(m)
|
593
|
+
c.expects(:respond_with).with(*(c.namespace + [m]))
|
594
|
+
|
595
|
+
c.resource_update m, attributes
|
596
|
+
end
|
597
|
+
|
598
|
+
def test_resource_update__invalid
|
570
599
|
c = SamplesController.new
|
571
600
|
attributes = {name: "joe"}
|
572
601
|
m = mock()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rezource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Make Rails restful controller even more simple
|
15
15
|
email: jan.zimmek@web.de
|