]> git.openstreetmap.org Git - rails.git/blobdiff - test/functional/message_controller_test.rb
Preserve message details over validation errors
[rails.git] / test / functional / message_controller_test.rb
index 77fdfbeb915f20915db2b3ca9de5eb0378d5a732..66ca8bc7008f3a27ce28a9a06d885ab9e84b9009 100644 (file)
@@ -65,6 +65,44 @@ class MessageControllerTest < ActionController::TestCase
       assert_select "input[type='submit'][value='Send']", :count => 1
     end
 
       assert_select "input[type='submit'][value='Send']", :count => 1
     end
 
+    # Check that the subject is preserved over errors
+    assert_difference "ActionMailer::Base.deliveries.size", 0 do
+      assert_difference "Message.count", 0 do
+        post :new,
+          :display_name => users(:public_user).display_name,
+          :message => { :title => "Test Message", :body => "" }
+      end
+    end
+    assert_response :success
+    assert_template "new"
+    assert_select "title", "OpenStreetMap | Send message"
+    assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+      assert_select "input#message_title", :count => 1 do
+        assert_select "[value=Test Message]"
+      end
+      assert_select "textarea#message_body", :text => "", :count => 1
+      assert_select "input[type='submit'][value='Send']", :count => 1
+    end
+
+    # Check that the body text is preserved over errors
+    assert_difference "ActionMailer::Base.deliveries.size", 0 do
+      assert_difference "Message.count", 0 do
+        post :new,
+          :display_name => users(:public_user).display_name,
+          :message => { :title => "", :body => "Test message body" }
+      end
+    end
+    assert_response :success
+    assert_template "new"
+    assert_select "title", "OpenStreetMap | Send message"
+    assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+      assert_select "input#message_title", :count => 1 do
+        assert_select "[value=]"
+      end
+      assert_select "textarea#message_body", :text => "Test message body", :count => 1
+      assert_select "input[type='submit'][value='Send']", :count => 1
+    end
+
     # Check that sending a message works
     assert_difference "ActionMailer::Base.deliveries.size", 1 do
       assert_difference "Message.count", 1 do
     # Check that sending a message works
     assert_difference "ActionMailer::Base.deliveries.size", 1 do
       assert_difference "Message.count", 1 do
@@ -93,7 +131,7 @@ class MessageControllerTest < ActionController::TestCase
     get :new, :display_name => "non_existent_user"
     assert_response :not_found
     assert_template "user/no_such_user"
     get :new, :display_name => "non_existent_user"
     assert_response :not_found
     assert_template "user/no_such_user"
-    assert_select "h2", "The user non_existent_user does not exist"
+    assert_select "h1", "The user non_existent_user does not exist"
   end
 
   ##
   end
 
   ##