public
Description: resources_controller rails plugin: rc makes RESTful controllers fun
Homepage: http://plugins.ardes.com/doc/resources_controller
Clone URL: git://github.com/ianwhite/resources_controller.git
Click here to lend your support to: resources_controller and make a donation at www.pledgie.com !
resource_saved? has different semantics
Removed the Saved AR mixin
ianwhite (author)
Mon Sep 08 07:19:21 -0700 2008
commit  9418e02f40a40faa1da70235e3a2143a0560f5f6
tree    71812e0414acd49c4009a966c3f2cfd4b90a6fb6
parent  2f496874436e334346d4b0d8029a055c6821c93b
...
1
 
2
3
4
 
5
6
7
 
 
 
 
8
9
10
...
 
1
2
 
 
3
4
 
 
5
6
7
8
9
10
11
0
@@ -1,10 +1,11 @@
0
-* API change: save_resource and resource_saved? deprecated
0
+* API change: save_resource deprecated
0
 
0
-  ActiveRecord::Base now has a saved? and attempted_save? method, which makes response_for much easier
0
-  to write, and leaves less artefacts in the controller instance.
0
+  So save_resource is now deprecated, just use resource.save
0
   
0
-  So save_resource, and resource_saved? are now deprecated, just use resource.save, and resource.saved?
0
-  instead.  See response_for_resources_controller if you're into response_for.
0
+  resource_saved? has slightly different semantics - it returns true if the record is not new and has no errors
0
+  
0
+  WTF?: save_resource used to set an instance var to track whether the resource was saved.  This is so that
0
+        controller can make decisions based on this outside the scope of an action (in response_for, and after_filters)
0
   
0
 * rspec compat:  Added new rake task to test that an RC controller passes the default rspec_scaffold
0
   controller specs.
...
575
576
577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
579
580
...
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
...
871
872
873
874
875
876
877
...
894
895
896
897
 
898
899
 
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
787
788
789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
791
792
...
870
871
872
 
873
874
875
...
892
893
894
 
895
896
 
897
0
@@ -575,6 +575,25 @@ Requesting /forums/2/owner using DELETE
0
 - should set the flash notice
0
 - should redirect to forums/2
0
 
0
+CommentsController#resource_saved Comment.new(<invalid attrs>)
0
+- should not be resource saved
0
+
0
+CommentsController#resource_saved Comment.new(<invalid attrs>).save
0
+- should not be resource saved
0
+
0
+CommentsController#resource_saved Comment.new(<invalid attrs>).save then update_attributes(<valid attrs>)
0
+- should be resource saved
0
+
0
+CommentsController#resource_saved Comment.find(<id>)
0
+- should be resource saved
0
+- .save should be saved
0
+
0
+CommentsController#resource_saved Comment.find(<id>) then update_attributes(<invalid attrs>)
0
+- should not be resource saved
0
+
0
+CommentsController#resource_saved Comment.find(<id>) then update_attributes(<new valid attrs>)
0
+- should be resource saved
0
+
0
 Routing shortcuts for Tags should map
0
 - resources_path to /tags
0
 - resource_path to /tags/2
0
@@ -768,26 +787,6 @@ UsersController handling PUT /users/dave
0
 UsersController handling DELETE /users/dave
0
 - should be unknown action
0
 
0
-(re: saved?) Comment.new(<invalid attrs>)
0
-- should not be attempted save
0
-- should not be saved
0
-
0
-(re: saved?) Comment.new(<invalid attrs>).save
0
-- should be attempted save
0
-- should not be saved
0
-
0
-(re: saved?) Comment.new(<invalid attrs>).save then update_attributes(<valid attrs>)
0
-- should be attempted save
0
-- should be saved
0
-
0
-(re: saved?) Comment.new(<invalid attrs>).save then update_attributes(<valid attrs>).reload
0
-- should not be attempted save
0
-- should not be saved
0
-
0
-(re: saved?) Comment.new(<invalid attrs>).save then update_attributes(<valid attrs>).reload.save
0
-- should be attempted save
0
-- should be saved
0
-
0
 ActionView with resources_controller Helper
0
 - should forward #resource_name to controller
0
 - should forward #resources_name to controller
0
@@ -871,7 +870,6 @@ A controller's resource_service
0
 
0
 deprecated methods
0
 - #save_resource should send resource.save
0
-- #resource_saved? should send resource.saved?
0
 
0
 #route_enclosing_names TagsController for named_route:
0
 - :tags should be []
0
@@ -894,6 +892,6 @@ deprecated methods
0
 #route_enclosing_names Admin::Superduper::ForumsController for named_route:
0
 - :admin_superduper_forums should be []
0
 
0
-Finished in 8.867688 seconds
0
+Finished in 8.299069 seconds
0
 
0
-605 examples, 0 failures
0
+601 examples, 0 failures
...
1
2
3
4
5
 
6
...
 
 
 
1
 
2
3
0
@@ -1,5 +1,2 @@
0
-require 'ardes/active_record/saved'
0
-ActiveRecord::Base.send :include, Ardes::ActiveRecord::Saved
0
-
0
 require 'ardes/resources_controller'
0
-ActionController::Base.extend Ardes::ResourcesController
0
+ActionController::Base.extend Ardes::ResourcesController
0
\ No newline at end of file
...
665
666
667
668
 
669
670
671
672
673
674
675
676
 
 
 
677
678
679
680
681
...
665
666
667
 
668
669
 
 
 
 
 
 
 
670
671
672
673
 
674
675
676
0
@@ -665,17 +665,12 @@ module Ardes#:nodoc:
0
         @enclosing_collection_resources ||= []
0
       end
0
       
0
-      # DEPRECATED: just use resource.saved?
0
+      # Has the resource been saved?
0
       #
0
-      # Returns self.resource.save and caches the result for future calls.
0
-      # This is useful when you want to know outside of an action whether the resource was saved.
0
-      #
0
-      # Pass true to ignore the cached value
0
-      def resource_saved?(reload = false)
0
-        resource.save unless resource.attempted_save?
0
-        resource.saved?
0
+      # Returns true if the record is not new, and there are no errors
0
+      def resource_saved?
0
+        !resource.new_record? && resource.errors.empty?
0
       end
0
-      deprecate :resource_saved? => 'Use resource.saved?'
0
       
0
       # DEPRECATED: just use resource.save
0
       def save_resource
...
54
55
56
57
58
59
60
61
62
63
64
65
...
54
55
56
 
 
 
 
 
 
 
57
58
0
@@ -54,11 +54,4 @@ describe "deprecated methods" do
0
       @controller.save_resource
0
     end
0
   end
0
-  
0
-  it "#resource_saved? should send resource.saved?" do
0
-    ActiveSupport::Deprecation.silence do
0
-      @controller.resource.should_receive(:saved?)
0
-      @controller.resource_saved?
0
-    end
0
-  end
0
 end
0
\ No newline at end of file

Comments

jlsync Thu Sep 11 03:47:26 -0700 2008

I don’t know how, but this change seems to break resources_controller (create action no longer works) with rails 2.1.1

ianwhite Fri Sep 12 03:35:14 -0700 2008

Thanks for the HU, reverted in c21f35c until I write some specs to figure this problem out