Changeset 7532
- Timestamp:
- 09/21/07 23:31:21 (1 year ago)
- Files:
-
- trunk/activeresource/test/base_errors_test.rb (modified) (2 diffs)
- trunk/activeresource/test/base/custom_methods_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activeresource/test/base_errors_test.rb
r5967 r7532 10 10 assert_equal @person.save, false 11 11 end 12 12 13 13 def test_should_mark_as_invalid 14 14 assert !@person.valid? 15 15 end 16 16 17 17 def test_should_parse_xml_errors 18 18 assert_kind_of ActiveResource::Errors, @person.errors … … 21 21 22 22 def test_should_parse_errors_to_individual_attributes 23 assert @person.errors.invalid?(:name) 23 24 assert_equal "can't be blank", @person.errors.on(:age) 24 25 assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] 25 26 assert_equal "Person quota full for today.", @person.errors.on_base 27 end 28 29 def test_should_iterate_over_errors 30 errors = [] 31 @person.errors.each { |attribute, message| errors << [attribute, message] } 32 assert_equal ["name", "can't be blank"], errors.first 33 end 34 35 def test_should_iterate_over_full_errors 36 errors = [] 37 @person.errors.each_full { |message| errors << message } 38 assert_equal "Name can't be blank", errors.first 26 39 end 27 40 trunk/activeresource/test/base/custom_methods_test.rb
r7074 r7532 19 19 mock.get "/people/retrieve.xml?name=Matz", {}, @matz_array 20 20 mock.get "/people/managers.xml", {}, @matz_array 21 mock.post "/people/hire.xml?name=Matz", {}, nil, 201 21 22 mock.put "/people/1/promote.xml?position=Manager", {}, nil, 204 22 23 mock.put "/people/promote.xml?name=Matz", {}, nil, 204, {} … … 25 26 mock.delete "/people/1/deactivate.xml", {}, nil, 200 26 27 mock.post "/people/new/register.xml", {}, @ryan, 201, 'Location' => '/people/5.xml' 28 mock.post "/people/1/register.xml", {}, @matz, 201 27 29 mock.get "/people/1/addresses/1.xml", {}, @addy 28 30 mock.get "/people/1/addresses/1/deep.xml", {}, @addy_deep … … 36 38 ActiveResource::HttpMock.reset! 37 39 end 38 40 39 41 def test_custom_collection_method 40 42 # GET 41 43 assert_equal([{ "id" => 1, "name" => 'Matz' }], Person.get(:retrieve, :name => 'Matz')) 42 44 45 # POST 46 assert_equal(ActiveResource::Response.new("", 201, {}), Person.post(:hire, :name => 'Matz')) 47 43 48 # PUT 44 49 assert_equal ActiveResource::Response.new("", 204, {}), 45 50 Person.put(:promote, {:name => 'Matz'}, 'atestbody') 46 51 assert_equal ActiveResource::Response.new("", 204, {}), Person.put(:sort, :by => 'name') 47 52 48 53 # DELETE 49 54 Person.delete :deactivate, :name => 'Matz' 50 55 51 56 # Nested resource 52 57 assert_equal ActiveResource::Response.new("", 204, {}), StreetAddress.put(:sort, :person_id => 1, :by => 'name') 53 58 end 54 59 55 60 def test_custom_element_method 56 61 # Test GET against an element URL … … 70 75 StreetAddress.find(1, :params => { :person_id => 1 }).put(:normalize_phone, :locale => 'US') 71 76 end 72 77 73 78 def test_custom_new_element_method 74 79 # Test POST against a new element URL 75 80 ryan = Person.new(:name => 'Ryan') 76 81 assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register) 77 82 78 83 # Test POST against a nested collection URL 79 84 addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1) … … 81 86 201, {'Location' => '/people/1/addresses/2.xml'}), 82 87 addy.post(:link) 88 89 matz = Person.new(:id => 1, :name => 'Matz') 90 assert_equal ActiveResource::Response.new(@matz, 201), matz.post(:register) 83 91 end 84 92 85 93 def test_find_custom_resources 86 94 assert_equal 'Matz', Person.find(:all, :from => :managers).first.name