2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-25 03:07:15 +00:00
moebooru/test/controllers/note_controller_test.rb

103 lines
3.0 KiB
Ruby
Raw Normal View History

require "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_file("#{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
2016-08-16 07:50:23 +09:00
post :update, :params => { :note => { :post_id => @post1.id, :x => 100, :y => 200, :height => 300, :width => 400, :body => "moogles" } }, :session => { :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)
2016-08-16 07:50:23 +09:00
post :update, :params => { :id => note.id, :note => { :body => "hoge" } }, :session => { :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(:body => "mark ii")
note.update(:body => "mark iii")
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
post :revert, :params => { :id => note.id, :version => 1 }, :session => { :user_id => 1 }
note.reload
assert_equal("hoge", note.body)
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
post :revert, :params => { :id => note.id, :version => 3 }, :session => { :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
2016-08-16 07:50:23 +09:00
get :history, :session => { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
get :history, :params => { :id => note.id }, :session => { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
get :history, :params => { :post_id => @post1.id }, :session => { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
get :history, :params => { :user_id => 1 }, :session => { :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
create_note("hoge", @post1.id)
2016-08-16 07:50:23 +09:00
get :index, :session => { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
get :index, :params => { :post_id => @post1.id }, :session => { :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
create_note("hoge", @post1.id)
2016-08-16 07:50:23 +09:00
get :search, :session => { :user_id => 1 }
assert_response :success
2014-08-23 16:19:01 +09:00
2016-08-16 07:50:23 +09:00
get :search, :params => { :query => "hoge" }, :session => { :user_id => 1 }
assert_response :success
end
end