+
+ assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
+
+ new_language_code = "de"
+
+ # Now try creating a diary entry in a different language
+ assert_difference "DiaryEntry.count", 1 do
+ post :new, { :commit => "save",
+ :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
+ :longitude => new_longitude, :language_code => new_language_code } },
+ { :user => users(:normal_user).id }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
+ entry = DiaryEntry.order(:id).last
+ assert_equal users(:normal_user).id, entry.user_id
+ assert_equal new_title, entry.title
+ assert_equal new_body, entry.body
+ assert_equal new_latitude.to_f, entry.latitude
+ assert_equal new_longitude.to_f, entry.longitude
+ assert_equal new_language_code, entry.language_code
+
+ assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
+ end
+
+ def test_new_spammy
+ # Generate some spammy content
+ spammy_title = "Spam Spam Spam Spam Spam"
+ spammy_body = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
+
+ # Try creating a spammy diary entry
+ assert_difference "DiaryEntry.count", 1 do
+ post :new, { :commit => "save",
+ :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" } },
+ { :user => users(:normal_user).id }
+ end
+ assert_response :redirect
+ assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
+ entry = DiaryEntry.order(:id).last
+ assert_equal users(:normal_user).id, entry.user_id
+ assert_equal spammy_title, entry.title
+ assert_equal spammy_body, entry.body
+ assert_equal "en", entry.language_code
+ assert_equal "suspended", User.find(users(:normal_user).id).status
+
+ # Follow the redirect
+ get :list, { :display_name => users(:normal_user).display_name }, { :user => users(:normal_user).id }
+ assert_response :redirect
+ assert_redirected_to :controller => :user, :action => :suspended