mirror of
https://github.com/redmine/redmine.git
synced 2026-07-08 10:23:20 +02:00
Allows attachments on news (#1972).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8728 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -53,6 +53,16 @@ class NewsControllerTest < ActionController::TestCase
|
||||
assert_tag :tag => 'h2', :content => /eCookbook first release/
|
||||
end
|
||||
|
||||
def test_show_should_show_attachments
|
||||
attachment = Attachment.first
|
||||
attachment.container = News.find(1)
|
||||
attachment.save!
|
||||
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
assert_tag 'a', :content => attachment.filename
|
||||
end
|
||||
|
||||
def test_show_not_found
|
||||
get :show, :id => 999
|
||||
assert_response 404
|
||||
@@ -83,19 +93,19 @@ class NewsControllerTest < ActionController::TestCase
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
def test_post_create_with_attachment
|
||||
set_tmp_attachments_directory
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_put_update
|
||||
@request.session[:user_id] = 2
|
||||
put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
|
||||
assert_redirected_to '/news/1'
|
||||
news = News.find(1)
|
||||
assert_equal 'Description changed by test_post_edit', news.description
|
||||
assert_difference 'News.count' do
|
||||
assert_difference 'Attachment.count' do
|
||||
post :create, :project_id => 1,
|
||||
:news => { :title => 'Test', :description => 'This is the description' },
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||||
end
|
||||
end
|
||||
attachment = Attachment.first(:order => 'id DESC')
|
||||
news = News.first(:order => 'id DESC')
|
||||
assert_equal news, attachment.container
|
||||
end
|
||||
|
||||
def test_post_create_with_validation_failure
|
||||
@@ -111,6 +121,35 @@ class NewsControllerTest < ActionController::TestCase
|
||||
:content => /1 error/
|
||||
end
|
||||
|
||||
def test_get_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_put_update
|
||||
@request.session[:user_id] = 2
|
||||
put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
|
||||
assert_redirected_to '/news/1'
|
||||
news = News.find(1)
|
||||
assert_equal 'Description changed by test_post_edit', news.description
|
||||
end
|
||||
|
||||
def test_put_update_with_attachment
|
||||
set_tmp_attachments_directory
|
||||
@request.session[:user_id] = 2
|
||||
assert_no_difference 'News.count' do
|
||||
assert_difference 'Attachment.count' do
|
||||
put :update, :id => 1,
|
||||
:news => { :description => 'This is the description' },
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||||
end
|
||||
end
|
||||
attachment = Attachment.first(:order => 'id DESC')
|
||||
assert_equal News.find(1), attachment.container
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
@request.session[:user_id] = 2
|
||||
delete :destroy, :id => 1
|
||||
|
||||
@@ -71,4 +71,19 @@ class NewsTest < ActiveSupport::TestCase
|
||||
10.times { projects(:projects_001).news.create(valid_news) }
|
||||
assert_equal 5, News.latest(users(:users_004)).size
|
||||
end
|
||||
|
||||
def test_attachments_should_be_visible
|
||||
assert News.find(1).attachments_visible?(User.anonymous)
|
||||
end
|
||||
|
||||
def test_attachments_should_be_deletable_with_manage_news_permission
|
||||
manager = User.find(2)
|
||||
assert News.find(1).attachments_deletable?(manager)
|
||||
end
|
||||
|
||||
def test_attachments_should_not_be_deletable_without_manage_news_permission
|
||||
manager = User.find(2)
|
||||
Role.find_by_name('Manager').remove_permission!(:manage_news)
|
||||
assert !News.find(1).attachments_deletable?(manager)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user