2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-26 19:57:37 +00:00
moebooru/test/functional/note_controller_test.rb

103 lines
2.9 KiB
Ruby
Raw Normal View History

require File.dirname(__FILE__) + "/../test_helper"
class NoteControllerTest < ActionController::TestCase
fixtures :users
2014-08-23 16:19:01 +09:00
def create_post(tags, user_id = 1, params = {})
post = Post.create({ :user_id => user_id, :score => 0, :source => "", :rating => "s", :width => 100, :height => 100, :ip_addr => "127.0.0.1", :updater_ip_addr => "127.0.0.1", :updater_user_id => 1, :tags => tags, :status => "active", :file => upload_jpeg("#{RAILS_ROOT}/test/mocks/test/test#{@post_number}.jpg") }.merge(params))
@post_number += 1
post
end
2014-08-23 16:19:01 +09:00
def create_note(body, post_id, params = {})
Note.create({ :user_id => 1, :x => 0, :y => 0, :width => 100, :height => 100, :ip_addr => "127.0.0.1", :is_active => true, :post_id => post_id, :body => body }.merge(params))
end
2014-08-23 16:19:01 +09:00
def setup_test
@post_number = 1
@post1 = create_post("tag1")
@post2 = create_post("tag2")
end
2014-08-23 16:19:01 +09:00
def test_create
setup_test
2014-08-23 16:19:01 +09:00
# Assume note locking is tested in the unit tests
post :update, { :note => { :post_id => @post1.id, :x => 100, :y => 200, :height => 300, :width => 400, :body => "moogles" } }, { :user_id => 1 }
assert_equal(1, @post1.notes.size)
assert_equal(100, @post1.notes[0].x)
assert_equal("moogles", @post1.notes[0].body)
assert_equal(1, @post1.notes[0].user_id)
2014-08-23 16:19:01 +09:00
# TODO: test privileges
end
2014-08-23 16:19:01 +09:00
def test_update
setup_test
2014-08-23 16:19:01 +09:00
note = create_note("moogles", @post1.id)
post :update, { :id => note.id, :note => { :body => "hoge" } }, { :user_id => 1 }
note.reload
assert_equal("hoge", note.body)
# TODO: test privileges
end
2014-08-23 16:19:01 +09:00
def test_revert
setup_test
2014-08-23 16:19:01 +09:00
note = create_note("hoge", @post1.id)
note.update_attributes(:body => "mark ii")
note.update_attributes(:body => "mark iii")
2014-08-23 16:19:01 +09:00
post :revert, { :id => note.id, :version => 1 }, { :user_id => 1 }
note.reload
assert_equal("hoge", note.body)
2014-08-23 16:19:01 +09:00
post :revert, { :id => note.id, :version => 3 }, { :user_id => 1 }
note.reload
assert_equal("mark iii", note.body)
end
2014-08-23 16:19:01 +09:00
def test_history
setup_test
2014-08-23 16:19:01 +09:00
note = create_note("hoge", @post1.id)
2014-08-23 16:19:01 +09:00
get :history, {}, { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
get :history, { :id => note.id }, { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
get :history, { :post_id => @post1.id }, { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
get :history, { :user_id => 1 }, { :user_id => 1 }
assert_response :success
end
2014-08-23 16:19:01 +09:00
def test_index
setup_test
2014-08-23 16:19:01 +09:00
note = create_note("hoge", @post1.id)
get :index, {}, { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
get :index, { :post_id => @post1.id }, { :user_id => 1 }
assert_response :success
end
2014-08-23 16:19:01 +09:00
def test_search
setup_test
2014-08-23 16:19:01 +09:00
note = create_note("hoge", @post1.id)
get :search, {}, { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
get :search, { :query => "hoge" }, { :user_id => 1 }
assert_response :success
end
end