Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 206
- Log:
Initial import of Gullery, an open source photo gallery:
http://nubyonrails.com/pages/gullery
- Author:
- rool
- Date:
- Sun May 20 19:05:59 +0100 2007
- Size:
- 3433 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | require 'assets_controller' |
3 | |
4 | # Re-raise errors caught by the controller. |
5 | class AssetsController; def rescue_action(e) raise e end; end |
6 | |
7 | class AssetsControllerTest < Test::Unit::TestCase |
8 | |
9 | def setup |
10 | @controller = AssetsController.new |
11 | @request = ActionController::TestRequest.new |
12 | @response = ActionController::TestResponse.new |
13 | end |
14 | |
15 | def test_restricted_create |
16 | assert_requires_login() { post :create } |
17 | assert_accepts_login(:quentin) { post :create, :name => 'Fox Tall Action Figure' } |
18 | end |
19 | |
20 | def test_restricted_update_caption |
21 | assert_requires_login() { post :update_caption, :id => 1, :value => 'A caption' } |
22 | assert_accepts_login(:quentin) { post :update_caption, :id => 1, :value => 'The can...even closer' } |
23 | end |
24 | |
25 | def test_restricted_destroy |
26 | assert_requires_login() { get :destroy, :id => 1 } |
27 | assert_accepts_login(:quentin) { get :destroy, :id => 1 } |
28 | end |
29 | |
30 | def test_restricted_sort |
31 | assert_requires_login() { post :sort } |
32 | assert_accepts_login(:quentin) { post :sort, :asset_list => [3, 2, 1] } |
33 | end |
34 | |
35 | def test_create |
36 | login_as :quentin |
37 | post :create, :asset => { :project_id => 1, |
38 | :caption => 'Cloneberry logo', |
39 | :file_field => uploaded_file("photo.jpg","image/jpeg","photo_uploaded.jpg") |
40 | } |
41 | asset = Asset.find_by_caption('Cloneberry logo') |
42 | |
43 | assert File.exists?(asset.absolute_path(:original)) |
44 | assert File.exists?(asset.absolute_path(:normal)) |
45 | assert File.exists?(asset.absolute_path(:thumb)) |
46 | |
47 | assert_response :redirect |
48 | assert_redirected_to projects_url(:id => 1, :action => 'show') |
49 | assert_not_nil assigns(:asset) |
50 | assert assigns(:asset).valid? |
51 | |
52 | asset.destroy |
53 | end |
54 | |
55 | def test_update_caption |
56 | login_as :quentin |
57 | post :update_caption, :id => 1, :value => 'Alternate logo on can' |
58 | assert_response :success |
59 | assert_not_nil assigns(:asset) |
60 | assert assigns(:asset).valid? |
61 | |
62 | assert_equal 'Alternate logo on can', Asset.find(1).caption |
63 | end |
64 | |
65 | def test_destroy |
66 | login_as :quentin |
67 | asset = Asset.find(1) |
68 | project = asset.project |
69 | old_count = project.assets.length |
70 | post :destroy, :id => 1 |
71 | assert_response :success |
72 | assert_equal 'text/javascript', @response.headers['Content-Type'] |
73 | |
74 | assert_equal old_count - 1, project.assets.count |
75 | end |
76 | |
77 | def test_rotate |
78 | FileUtils.cp File.expand_path("test/fixtures/files/photo.jpg", RAILS_ROOT), |
79 | File.expand_path("public/system/photo.jpg", RAILS_ROOT) |
80 | |
81 | image = MiniMagick::Image.from_file(assets(:photo).absolute_path(:original)) |
82 | assert image.height < image.width |
83 | |
84 | login_as :quentin |
85 | post :rotate, :id => 5, :direction => 'cw' |
86 | |
87 | image = MiniMagick::Image.from_file(assets(:photo).absolute_path(:original)) |
88 | assert image.height > image.width |
89 | |
90 | assert_redirected_to projects_url(:action => 'show', :id => 1) |
91 | assets(:photo).destroy |
92 | end |
93 | |
94 | private |
95 | |
96 | def uploaded_file(tmp_filename, content_type, filename) |
97 | t = Tempfile.new(filename); |
98 | t.binmode |
99 | path = File.expand_path("test/fixtures/files/" + tmp_filename, RAILS_ROOT) |
100 | FileUtils.copy_file(path, t.path) |
101 | (class << t; self; end).class_eval do |
102 | alias local_path path |
103 | define_method(:original_filename) {filename} |
104 | define_method(:content_type) {content_type} |
105 | end |
106 | return t |
107 | end |
108 | |
109 | end |