public
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/halorgium/mephisto.git
mephisto / test / functional / admin / articles_controller_assets_test.rb
100644 128 lines (109 sloc) 4.78 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require File.dirname(__FILE__) + '/../../test_helper'
require 'admin/articles_controller'
 
# Re-raise errors caught by the controller.
class Admin::ArticlesController; def rescue_action(e) raise e end; end
 
context "Admin Articles Controller Assets" do
  fixtures :contents, :content_versions, :sections, :assigned_sections, :users, :sites, :tags, :taggings, :memberships, :assigned_assets, :assets
 
  setup do
    @controller = Admin::ArticlesController.new
    @request = ActionController::TestRequest.new
    @response = ActionController::TestResponse.new
    login_as :quentin
    FileUtils.mkdir_p ASSET_PATH
  end
 
  specify "should upload asset" do
    asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
    
    assert_difference Asset, :count, asset_count do
      post :upload, :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') }
      assert_response :success
      assert_template 'new'
    end
  end
 
  specify "should upload asset and redirect to article" do
    asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
    
    assert_difference Asset, :count, asset_count do
      post :upload, :id => contents(:welcome).id,
                    :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') }
      assert_response :success
      assert_template 'edit'
      assert_equal contents(:welcome), assigns(:article)
    end
  end
 
  specify "should upload asset as member" do
    asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
    
    login_as :ben
    assert_difference Asset, :count, asset_count do
      post :upload, :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') }
      assert_response :success
      assert_template 'new'
    end
  end
 
  specify "should upload asset and redirect to article as member" do
    asset_count = has_image_processor? ? 3 : 1 # asset + 2 thumbnails
    
    login_as :ben
    assert_difference Asset, :count, asset_count do
      post :upload, :id => contents(:site_map).id,
                    :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') }
      assert_response :success
      assert_template 'edit'
      assert_equal contents(:site_map), assigns(:article)
    end
  end
 
  specify "should not error on new article asset upload" do
    assert_no_difference Asset, :count do
      post :upload
      assert_response :success
      assert_template 'new'
    end
  end
 
  specify "should not error on article asset upload" do
    assert_no_difference Asset, :count do
      post :upload, :id => contents(:welcome).id
      assert_response :success
      assert_template 'edit'
      assert_equal contents(:welcome), assigns(:article)
    end
  end
 
  specify "should not create article when uploading asset" do
    Time.mock! Time.local(2005, 1, 1, 12, 0, 0) do
      assert_no_difference Article, :count do
        post :upload, :asset => { :uploaded_data => fixture_file_upload('assets/logo.png', 'image/png') },
          :article => { :title => "My Red Hot Car", :excerpt => "Blah Blah", :body => "Blah Blah",
          'published_at(1i)' => '2005', 'published_at(2i)' => '1', 'published_at(3i)' => '1', 'published_at(4i)' => '10' }, :submit => :save
        assert_response :success
        assert_template 'new'
        assert_valid assigns(:article)
        assert assigns(:article).new_record?
        assert_equal Time.local(2005, 1, 1, 9, 0, 0).utc, assigns(:article).published_at
        assert_equal users(:quentin), assigns(:article).updater
      end
    end
  end
 
  # TODO: Fails due to asset test deleting asset fixtures
  specify "should add asset to article" do
    return if Asset.count == 1
    assert_difference AssignedAsset, :count do
      post :attach, :id => contents(:welcome).id, :version => assets(:mov).id
    end
    assert_models_equal [assets(:gif), assets(:mp3), assets(:mov)], contents(:welcome).assets(true)
  end
  
  # TODO: Fails due to asset test deleting asset fixtures
  specify "should add inactive asset to article" do
    return if Asset.count == 1
    assert_no_difference AssignedAsset, :count do
      post :attach, :id => contents(:welcome).id, :version => assets(:png).id
    end
    assert_models_equal [assets(:gif), assets(:mp3), assets(:png)], contents(:welcome).assets(true)
  end
 
  # TODO: Fails due to asset test deleting asset fixtures
  specify "should find deactivate article assets" do
    return if Asset.count == 1
    assert_no_difference AssignedAsset, :count do
      post :detach, :id => contents(:welcome).id, :version => assets(:mp3).id
    end
    assert_models_equal [assets(:gif)], contents(:welcome).assets
  end
 
  teardown do
    FileUtils.rm_rf ASSET_PATH
  end
end