rezource 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -245,7 +245,7 @@ module Rezource
245
245
 
246
246
  def resource_create(resource)
247
247
  before_create resource
248
- resource.save if resource.valid?
248
+ resource.save unless resource.errors.any?
249
249
  after_create resource
250
250
 
251
251
  # respond_with *namespace, resource
@@ -254,11 +254,11 @@ module Rezource
254
254
 
255
255
  def resource_update(resource, attributes={})
256
256
  before_update resource
257
- resource.update_attributes attributes if resource.valid?
257
+ resource.update_attributes attributes unless resource.errors.any?
258
258
  after_update resource
259
259
 
260
260
  if _action = params[:_action]
261
- if resource.valid?
261
+ unless resource.errors.any?
262
262
  respond_with *namespace, resource, location: action_resource_path(_action)
263
263
  else
264
264
  respond_with *namespace, resource, action: _action
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rezource"
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
4
4
 
5
5
  s.authors = ["Jan Zimmek"]
6
6
  s.email = %q{jan.zimmek@web.de}
@@ -521,10 +521,12 @@ class RezourceTest < Test::Unit::TestCase
521
521
 
522
522
  def test_resource_create__valid
523
523
  c = SamplesController.new
524
+ e = mock()
524
525
  m = mock()
525
526
 
526
527
  c.expects(:before_create).with(m)
527
- m.expects(:valid?).returns true
528
+ m.expects(:errors).returns e
529
+ e.expects(:any?).returns false
528
530
  m.expects(:save)
529
531
  c.expects(:after_create).with(m)
530
532
  c.expects(:respond_with).with(*(c.namespace + [m]))
@@ -534,10 +536,13 @@ class RezourceTest < Test::Unit::TestCase
534
536
 
535
537
  def test_resource_create__invalid
536
538
  c = SamplesController.new
539
+
540
+ e = mock()
537
541
  m = mock()
538
542
 
539
543
  c.expects(:before_create).with(m)
540
- m.expects(:valid?).returns false
544
+ m.expects(:errors).returns e
545
+ e.expects(:any?).returns true
541
546
  c.expects(:after_create).with(m)
542
547
  c.expects(:respond_with).with(*(c.namespace + [m]))
543
548
 
@@ -547,10 +552,13 @@ class RezourceTest < Test::Unit::TestCase
547
552
  def test_resource_update__valid
548
553
  c = SamplesController.new
549
554
  attributes = {name: "joe"}
555
+
550
556
  m = mock()
557
+ e = mock()
551
558
 
552
559
  c.expects(:before_update).with(m)
553
- m.expects(:valid?).returns true
560
+ m.expects(:errors).returns e
561
+ e.expects(:any?).returns false
554
562
  m.expects(:update_attributes).with(attributes)
555
563
  c.expects(:after_update).with(m)
556
564
  c.expects(:respond_with).with(*(c.namespace + [m]))
@@ -562,9 +570,11 @@ class RezourceTest < Test::Unit::TestCase
562
570
  c = SamplesController.new
563
571
  attributes = {name: "joe"}
564
572
  m = mock()
573
+ e = mock()
565
574
 
566
575
  c.expects(:before_update).with(m)
567
- m.expects(:valid?).returns false
576
+ m.expects(:errors).returns e
577
+ e.expects(:any?).returns true
568
578
  c.expects(:after_update).with(m)
569
579
  c.expects(:respond_with).with(*(c.namespace + [m]))
570
580
 
@@ -575,13 +585,16 @@ class RezourceTest < Test::Unit::TestCase
575
585
  c = SamplesController.new
576
586
  attributes = {name: "joe"}
577
587
  m = mock()
588
+ e = mock()
578
589
 
579
590
  c.expects(:before_update).with(m)
580
- m.expects(:valid?).returns false
591
+ m.expects(:errors).returns e
592
+ e.expects(:any?).returns true
581
593
  c.expects(:after_update).with(m)
582
594
 
583
595
  c.expects(:"params").returns({_action: "custom"})
584
- m.expects(:valid?).returns false
596
+ m.expects(:errors).returns e
597
+ e.expects(:any?).returns true
585
598
 
586
599
  c.expects(:respond_with).with(*(c.namespace + [m] + [{action: "custom"}]))
587
600
 
@@ -592,14 +605,18 @@ class RezourceTest < Test::Unit::TestCase
592
605
  c = SamplesController.new
593
606
  attributes = {name: "joe"}
594
607
  m = mock()
608
+ e = mock()
595
609
 
596
610
  c.expects(:before_update).with(m)
597
- m.expects(:valid?).returns true
611
+
612
+ m.expects(:errors).returns e
613
+ e.expects(:any?).returns false
598
614
  m.expects(:update_attributes).with(attributes)
599
615
  c.expects(:after_update).with(m)
600
616
 
601
617
  c.expects(:"params").returns({_action: "custom"})
602
- m.expects(:valid?).returns true
618
+ m.expects(:errors).returns e
619
+ e.expects(:any?).returns false
603
620
 
604
621
  c.expects(:"custom_sample_path").returns "/sample/XYZ/custom"
605
622
 
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.5
4
+ version: 0.0.6
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-19 00:00:00.000000000 Z
12
+ date: 2013-08-21 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