fassets_core 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +21 -0
- data/README.md +22 -0
- data/Rakefile +39 -0
- data/app/assets/images/fassets_core/add.png +0 -0
- data/app/assets/images/fassets_core/archive.png +0 -0
- data/app/assets/images/fassets_core/classify.png +0 -0
- data/app/assets/images/fassets_core/clipboard.png +0 -0
- data/app/assets/images/fassets_core/collapse.png +0 -0
- data/app/assets/images/fassets_core/collapsed.png +0 -0
- data/app/assets/images/fassets_core/delete.png +0 -0
- data/app/assets/images/fassets_core/drag.png +0 -0
- data/app/assets/images/fassets_core/edit.png +0 -0
- data/app/assets/images/fassets_core/link.png +0 -0
- data/app/assets/images/fassets_core/markup_preview.png +0 -0
- data/app/assets/images/fassets_core/remove.png +0 -0
- data/app/assets/images/fassets_core/sort.png +0 -0
- data/app/assets/images/fassets_core/warning.png +0 -0
- data/app/assets/javascripts/fassets_core/add_asset_box.js +102 -0
- data/app/assets/javascripts/fassets_core/application.js.erb +14 -0
- data/app/assets/javascripts/fassets_core/assets.js +31 -0
- data/app/assets/javascripts/fassets_core/catalog_box.js +73 -0
- data/app/assets/javascripts/fassets_core/catalogs.js +46 -0
- data/app/assets/javascripts/fassets_core/classification.js +37 -0
- data/app/assets/javascripts/fassets_core/edit_box.js +63 -0
- data/app/assets/javascripts/fassets_core/facets.js.erb +32 -0
- data/app/assets/javascripts/fassets_core/tray.js +30 -0
- data/app/assets/stylesheets/fassets_core/add_asset_box.css.scss +77 -0
- data/app/assets/stylesheets/fassets_core/application.css +16 -0
- data/app/assets/stylesheets/fassets_core/assets.css.scss +74 -0
- data/app/assets/stylesheets/fassets_core/catalog_box.css.scss +45 -0
- data/app/assets/stylesheets/fassets_core/collapsible.css.scss +54 -0
- data/app/assets/stylesheets/fassets_core/edit_box.css.scss +58 -0
- data/app/assets/stylesheets/fassets_core/facet.css.scss +56 -0
- data/app/assets/stylesheets/fassets_core/filter.css.scss +20 -0
- data/app/assets/stylesheets/fassets_core/forms.css.scss +12 -0
- data/app/assets/stylesheets/fassets_core/labels.css.scss +13 -0
- data/app/assets/stylesheets/fassets_core/master.css.scss +127 -0
- data/app/assets/stylesheets/fassets_core/sidebar.css.scss +84 -0
- data/app/assets/stylesheets/fassets_core/tray.css.scss +106 -0
- data/app/controllers/assets_controller.rb +115 -0
- data/app/controllers/catalogs_controller.rb +99 -0
- data/app/controllers/classifications_controller.rb +56 -0
- data/app/controllers/facets_controller.rb +57 -0
- data/app/controllers/fassets_core/application_controller.rb +5 -0
- data/app/controllers/labels_controller.rb +54 -0
- data/app/controllers/tray_positions_controller.rb +81 -0
- data/app/helpers/assets_helper.rb +20 -0
- data/app/helpers/catalogs_helper.rb +3 -0
- data/app/helpers/classifications_helper.rb +8 -0
- data/app/helpers/fassets_core/application_helper.rb +48 -0
- data/app/helpers/labels_helper.rb +3 -0
- data/app/helpers/tray_positions_helper.rb +3 -0
- data/app/models/asset.rb +52 -0
- data/app/models/catalog.rb +16 -0
- data/app/models/classification.rb +8 -0
- data/app/models/facet.rb +19 -0
- data/app/models/label.rb +11 -0
- data/app/models/label_filter.rb +16 -0
- data/app/models/labeling.rb +5 -0
- data/app/models/tray_position.rb +9 -0
- data/app/views/assets/_add_asset_sidebar.html.haml +8 -0
- data/app/views/assets/_classification.html.haml +33 -0
- data/app/views/assets/_form.html.haml +30 -0
- data/app/views/assets/_put_on_tray.html.haml +7 -0
- data/app/views/assets/edit.html.haml +15 -0
- data/app/views/assets/new.html.haml +25 -0
- data/app/views/assets/show.html.haml +13 -0
- data/app/views/catalogs/_box_catalog_list.html.haml +6 -0
- data/app/views/catalogs/_box_content.html.haml +13 -0
- data/app/views/catalogs/_catalog.html.haml +2 -0
- data/app/views/catalogs/_facet.html.haml +13 -0
- data/app/views/catalogs/_filter_item.html.haml +3 -0
- data/app/views/catalogs/_form.html.haml +6 -0
- data/app/views/catalogs/box.html.haml +6 -0
- data/app/views/catalogs/edit.html.haml +8 -0
- data/app/views/catalogs/index.html.haml +17 -0
- data/app/views/catalogs/new.html.haml +8 -0
- data/app/views/catalogs/show.html.haml +30 -0
- data/app/views/classifications/update.js.erb +4 -0
- data/app/views/facets/_form.html.haml +9 -0
- data/app/views/facets/edit.html.haml +15 -0
- data/app/views/labels/_form.haml +3 -0
- data/app/views/labels/_sidebar.html.haml +22 -0
- data/app/views/labels/destroy.js.erb +13 -0
- data/app/views/layouts/fassets_core/application.html.haml +16 -0
- data/app/views/shared/_asset.html.haml +22 -0
- data/app/views/shared/_asset_form.html.haml +7 -0
- data/app/views/shared/_classification.html.haml +23 -0
- data/app/views/shared/_clipboard.html.haml +10 -0
- data/app/views/shared/_error.html.haml +6 -0
- data/app/views/shared/_tray.html.haml +13 -0
- data/app/views/shared/_tray_position.html.haml +8 -0
- data/app/views/tray_positions/create.js.rjs +10 -0
- data/app/views/tray_positions/destroy.js.rjs +1 -0
- data/app/views/tray_positions/sort.js.rjs +15 -0
- data/config/initializers/mime_types.rb +2 -0
- data/config/initializers/uploader.rb +2 -0
- data/config/initializers/users.rb +7 -0
- data/config/routes.rb +34 -0
- data/db/migrate/001_create_catalogs.rb +13 -0
- data/db/migrate/002_create_facets.rb +14 -0
- data/db/migrate/003_create_labels.rb +12 -0
- data/db/migrate/005_create_classifications.rb +12 -0
- data/db/migrate/006_create_labelings.rb +12 -0
- data/db/migrate/007_create_tray_positions.rb +13 -0
- data/db/migrate/008_create_assets.rb +16 -0
- data/db/migrate/010_add_label_ordering.rb +10 -0
- data/db/migrate/017_add_clipboard.rb +11 -0
- data/db/migrate/20120803150826_add_position_to_facet.rb +5 -0
- data/db/schema.rb +141 -0
- data/db/seeds.rb +7 -0
- data/lib/acts_as_asset.rb +36 -0
- data/lib/authenticated_system.rb +187 -0
- data/lib/authenticated_test_helper.rb +20 -0
- data/lib/fassets_core.rb +6 -0
- data/lib/fassets_core/engine.rb +7 -0
- data/lib/fassets_core/plugins.rb +13 -0
- data/lib/fassets_core/test_helper.rb +3 -0
- data/lib/fassets_core/test_helper/every_assets_controller.rb +161 -0
- data/lib/fassets_core/test_helper/every_authenticated_controller.rb +10 -0
- data/lib/fassets_core/version.rb +3 -0
- data/lib/tasks/cucumber.rake +57 -0
- data/lib/tasks/fassets-core_tasks.rake +4 -0
- data/lib/template_manager.rb +27 -0
- data/test/fassets-core_test.rb +7 -0
- data/test/fixtures/asset_contents.yml +7 -0
- data/test/fixtures/assets.yml +7 -0
- data/test/fixtures/catalogs.yml +9 -0
- data/test/fixtures/classifications.yml +7 -0
- data/test/fixtures/facets.yml +9 -0
- data/test/fixtures/frames.yml +11 -0
- data/test/fixtures/image_assets.yml +7 -0
- data/test/fixtures/labellings.yml +7 -0
- data/test/fixtures/labels.yml +9 -0
- data/test/fixtures/presentations.yml +7 -0
- data/test/fixtures/slides.yml +11 -0
- data/test/fixtures/slots.yml +0 -0
- data/test/fixtures/topics.yml +11 -0
- data/test/fixtures/tray_positions.yml +7 -0
- data/test/fixtures/users.yml +31 -0
- data/test/functional/assets_controller_test.rb +8 -0
- data/test/functional/catalogs_controller_test.rb +8 -0
- data/test/functional/classifications_controller_test.rb +8 -0
- data/test/functional/content_controller_test.rb +8 -0
- data/test/functional/facets_controller_test.rb +8 -0
- data/test/functional/file_assets_controller_test.rb +8 -0
- data/test/functional/files_controller_test.rb +8 -0
- data/test/functional/labellings_controller_test.rb +8 -0
- data/test/functional/labels_controller_test.rb +8 -0
- data/test/functional/presentations_controller_test.rb +8 -0
- data/test/functional/sessions_controller_test.rb +82 -0
- data/test/functional/slides_controller_test.rb +8 -0
- data/test/functional/slots_controller_test.rb +8 -0
- data/test/functional/tray_positions_controller_test.rb +8 -0
- data/test/functional/urls_controller_test.rb +8 -0
- data/test/functional/users_controller_test.rb +58 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/asset_content_test.rb +8 -0
- data/test/unit/asset_test.rb +8 -0
- data/test/unit/catalog_test.rb +8 -0
- data/test/unit/classification_test.rb +8 -0
- data/test/unit/facet_test.rb +8 -0
- data/test/unit/frame_test.rb +8 -0
- data/test/unit/image_asset_test.rb +8 -0
- data/test/unit/label_test.rb +8 -0
- data/test/unit/labelling_test.rb +8 -0
- data/test/unit/presentation_test.rb +8 -0
- data/test/unit/slide_test.rb +8 -0
- data/test/unit/slot_test.rb +8 -0
- data/test/unit/topic_test.rb +8 -0
- data/test/unit/tray_position_test.rb +8 -0
- data/test/unit/user_test.rb +103 -0
- metadata +453 -0
data/db/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Acts
|
3
|
+
module Asset
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
module ClassMethods
|
8
|
+
def acts_as_asset
|
9
|
+
has_one :asset, :as => :content, :dependent => :destroy, :class_name => "Asset"
|
10
|
+
accepts_nested_attributes_for :asset
|
11
|
+
include ActiveRecord::Acts::Asset::InstanceMethods
|
12
|
+
end
|
13
|
+
end
|
14
|
+
module InstanceMethods
|
15
|
+
def name
|
16
|
+
asset.name
|
17
|
+
end
|
18
|
+
def class_underscore
|
19
|
+
self.class.to_s.underscore
|
20
|
+
end
|
21
|
+
def media_type
|
22
|
+
"generic"
|
23
|
+
end
|
24
|
+
def icon
|
25
|
+
"/images/#{media_type}.png"
|
26
|
+
end
|
27
|
+
protected
|
28
|
+
def put_on_tray
|
29
|
+
tray_positions.create(:user_id => self.user_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveRecord::Base.send(:include, ActiveRecord::Acts::Asset)
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module AuthenticatedSystem
|
2
|
+
protected
|
3
|
+
# Returns true or false if the user is logged in.
|
4
|
+
# Preloads @current_user with the user model if they're logged in.
|
5
|
+
def logged_in?
|
6
|
+
!!current_user
|
7
|
+
end
|
8
|
+
|
9
|
+
# Accesses the current user from the session.
|
10
|
+
# Future calls avoid the database because nil is not equal to false.
|
11
|
+
def current_user
|
12
|
+
@current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie) unless @current_user == false
|
13
|
+
end
|
14
|
+
|
15
|
+
# Store the given user id in the session.
|
16
|
+
def current_user=(new_user)
|
17
|
+
session[:user_id] = new_user ? new_user.id : nil
|
18
|
+
@current_user = new_user || false
|
19
|
+
end
|
20
|
+
|
21
|
+
# Check if the user is authorized
|
22
|
+
#
|
23
|
+
# Override this method in your controllers if you want to restrict access
|
24
|
+
# to only a few actions or if you want to check if the user
|
25
|
+
# has the correct rights.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
#
|
29
|
+
# # only allow nonbobs
|
30
|
+
# def authorized?
|
31
|
+
# current_user.login != "bob"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
def authorized?(action=nil, resource=nil, *args)
|
35
|
+
user_signed_in??
|
36
|
+
end
|
37
|
+
|
38
|
+
# Filter method to enforce a login requirement.
|
39
|
+
#
|
40
|
+
# To require logins for all actions, use this in your controllers:
|
41
|
+
#
|
42
|
+
# before_filter :login_required
|
43
|
+
#
|
44
|
+
# To require logins for specific actions, use this in your controllers:
|
45
|
+
#
|
46
|
+
# before_filter :login_required, :only => [ :edit, :update ]
|
47
|
+
#
|
48
|
+
# To skip this in a subclassed controller:
|
49
|
+
#
|
50
|
+
# skip_before_filter :login_required
|
51
|
+
#
|
52
|
+
def login_required
|
53
|
+
authorized? || access_denied
|
54
|
+
end
|
55
|
+
|
56
|
+
# Redirect as appropriate when an access request fails.
|
57
|
+
#
|
58
|
+
# The default action is to redirect to the login screen.
|
59
|
+
#
|
60
|
+
# Override this method in your controllers if you want to have special
|
61
|
+
# behavior in case the user is not authorized
|
62
|
+
# to access the requested action. For example, a popup window might
|
63
|
+
# simply close itself.
|
64
|
+
def access_denied
|
65
|
+
respond_to do |format|
|
66
|
+
format.html do
|
67
|
+
store_location
|
68
|
+
redirect_to new_session_path
|
69
|
+
end
|
70
|
+
# format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
|
71
|
+
# you may want to change format.any to e.g. format.any(:js, :xml)
|
72
|
+
format.any do
|
73
|
+
request_http_basic_authentication 'Web Password'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Store the URI of the current request in the session.
|
79
|
+
#
|
80
|
+
# We can return to this location by calling #redirect_back_or_default.
|
81
|
+
def store_location
|
82
|
+
session[:return_to] = request.request_uri
|
83
|
+
end
|
84
|
+
|
85
|
+
# Redirect to the URI stored by the most recent store_location call or
|
86
|
+
# to the passed default. Set an appropriately modified
|
87
|
+
# after_filter :store_location, :only => [:index, :new, :show, :edit]
|
88
|
+
# for any controller you want to be bounce-backable.
|
89
|
+
def redirect_back_or_default(default)
|
90
|
+
redirect_to(session[:return_to] || default)
|
91
|
+
session[:return_to] = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
# Inclusion hook to make #current_user and #logged_in?
|
95
|
+
# available as ActionView helper methods.
|
96
|
+
def self.included(base)
|
97
|
+
base.send :helper_method, :current_user, :user_signed_in?, :authorized? if base.respond_to? :helper_method
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Login
|
102
|
+
#
|
103
|
+
|
104
|
+
# Called from #current_user. First attempt to login by the user id stored in the session.
|
105
|
+
def login_from_session
|
106
|
+
self.current_user = User.find_by_id(session[:user_id]) if session[:user_id]
|
107
|
+
end
|
108
|
+
|
109
|
+
# Called from #current_user. Now, attempt to login by basic authentication information.
|
110
|
+
def login_from_basic_auth
|
111
|
+
authenticate_with_http_basic do |login, password|
|
112
|
+
self.current_user = User.authenticate(login, password)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Logout
|
118
|
+
#
|
119
|
+
|
120
|
+
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
|
121
|
+
# for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
|
122
|
+
def login_from_cookie
|
123
|
+
user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
|
124
|
+
if user && user.remember_token?
|
125
|
+
self.current_user = user
|
126
|
+
handle_remember_cookie! false # freshen cookie token (keeping date)
|
127
|
+
self.current_user
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# This is ususally what you want; resetting the session willy-nilly wreaks
|
132
|
+
# havoc with forgery protection, and is only strictly necessary on login.
|
133
|
+
# However, **all session state variables should be unset here**.
|
134
|
+
def logout_keeping_session!
|
135
|
+
# Kill server-side auth cookie
|
136
|
+
@current_user.forget_me if @current_user.is_a? User
|
137
|
+
@current_user = false # not logged in, and don't do it for me
|
138
|
+
kill_remember_cookie! # Kill client-side auth cookie
|
139
|
+
session[:user_id] = nil # keeps the session but kill our variable
|
140
|
+
# explicitly kill any other session variables you set
|
141
|
+
end
|
142
|
+
|
143
|
+
# The session should only be reset at the tail end of a form POST --
|
144
|
+
# otherwise the request forgery protection fails. It's only really necessary
|
145
|
+
# when you cross quarantine (logged-out to logged-in).
|
146
|
+
def logout_killing_session!
|
147
|
+
logout_keeping_session!
|
148
|
+
reset_session
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Remember_me Tokens
|
153
|
+
#
|
154
|
+
# Cookies shouldn't be allowed to persist past their freshness date,
|
155
|
+
# and they should be changed at each login
|
156
|
+
|
157
|
+
# Cookies shouldn't be allowed to persist past their freshness date,
|
158
|
+
# and they should be changed at each login
|
159
|
+
|
160
|
+
def valid_remember_cookie?
|
161
|
+
return nil unless @current_user
|
162
|
+
(@current_user.remember_token?) &&
|
163
|
+
(cookies[:auth_token] == @current_user.remember_token)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Refresh the cookie auth token if it exists, create it otherwise
|
167
|
+
def handle_remember_cookie! new_cookie_flag
|
168
|
+
return unless @current_user
|
169
|
+
case
|
170
|
+
when valid_remember_cookie? then @current_user.refresh_token # keeping same expiry date
|
171
|
+
when new_cookie_flag then @current_user.remember_me
|
172
|
+
else @current_user.forget_me
|
173
|
+
end
|
174
|
+
send_remember_cookie!
|
175
|
+
end
|
176
|
+
|
177
|
+
def kill_remember_cookie!
|
178
|
+
cookies.delete :auth_token
|
179
|
+
end
|
180
|
+
|
181
|
+
def send_remember_cookie!
|
182
|
+
cookies[:auth_token] = {
|
183
|
+
:value => @current_user.remember_token,
|
184
|
+
:expires => @current_user.remember_token_expires_at }
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AuthenticatedTestHelper
|
2
|
+
# Sets the current user in the session from the user fixtures.
|
3
|
+
def login_as(user)
|
4
|
+
@request.session[:user_id] = user ? users(user).id : nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def authorize_as(user)
|
8
|
+
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'monkey') : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
# rspec
|
12
|
+
def mock_user
|
13
|
+
user = mock_model(User, :id => 1,
|
14
|
+
:login => 'user_name',
|
15
|
+
:name => 'U. Surname',
|
16
|
+
:to_xml => "User-in-XML", :to_json => "User-in-JSON",
|
17
|
+
:errors => [])
|
18
|
+
user
|
19
|
+
end
|
20
|
+
end
|
data/lib/fassets_core.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
module FassetsCore
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initializer :assets do |config|
|
4
|
+
Rails.application.config.assets.precompile += %w( flowplayer.js form.js jquery.collapsiblePanel-0.2.0.js jquery.fileupload.js jquery.fileupload-ui.js jquery.iframe-transport.js jquery.tmpl.min.js jquery.ui.widget.js jquery.fileupload-ui.css jquery-ui-theme_base.css)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rspec' # needed for rcov
|
2
|
+
|
3
|
+
shared_examples_for "Every AssetsController" do
|
4
|
+
include_examples "every authenticated controller"
|
5
|
+
|
6
|
+
describe "GET 'new'" do
|
7
|
+
it "should assign content" do
|
8
|
+
get 'new', additional_request_params
|
9
|
+
assigns(:content).class.should == @controller.content_model
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not assign all asset types" do
|
13
|
+
get 'new', additional_request_params
|
14
|
+
assigns(:asset_types).should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not assign selected_type" do
|
18
|
+
get 'new', additional_request_params
|
19
|
+
assigns(:selected_type).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
context "HTML request" do
|
23
|
+
it "should be successful and render all partials" do
|
24
|
+
get 'new', additional_request_params
|
25
|
+
response.should be_success
|
26
|
+
response.should render_template("assets/new")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "actions with assets" do
|
32
|
+
before(:each) do
|
33
|
+
setup_content
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should render the edit template" do
|
37
|
+
get 'edit', additional_request_params.merge({ :id => asset.id })
|
38
|
+
response.should be_success
|
39
|
+
response.should render_template("assets/edit")
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "GET 'show'" do
|
43
|
+
it "should assign content" do
|
44
|
+
get 'show', additional_request_params.merge({ :id => asset.id })
|
45
|
+
assigns(:content).should_not be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "DELETE asset" do
|
50
|
+
it "should delete the asset and show a notice" do
|
51
|
+
delete "destroy", additional_request_params.merge({ :id => asset.id })
|
52
|
+
assigns(:content).should respond_to(:destroy).with(0).arguments
|
53
|
+
response.should redirect_to root_path
|
54
|
+
request.flash[:notice].should =~ /^Asset has been deleted!$/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "update asset" do
|
59
|
+
it "should show a 'successful' message on success" do
|
60
|
+
controller.stub!(:url_for) { "/asset" }
|
61
|
+
post 'update', additional_request_params.merge({ :id => asset.id })
|
62
|
+
assigns(:content).should_not be_nil
|
63
|
+
assigns(:content).should respond_to(:update_attributes).with(1).argument
|
64
|
+
request.flash[:notice].should =~ /^Succesfully updated asset!$/
|
65
|
+
response.should be_success
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should throw an error when update fails" do
|
69
|
+
controller.instance_eval { @content.stub!(:update_attributes) { false } }
|
70
|
+
post 'update', additional_request_params.merge({ :id => asset.id })
|
71
|
+
assigns(:content).should respond_to(:update_attributes).with(1).argument
|
72
|
+
request.flash[:error].should =~ /^Could not update asset!$/
|
73
|
+
response.should render_template 'assets/edit'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "actions without assets" do
|
79
|
+
it "should redirect to root with error message on error" do
|
80
|
+
get 'show', additional_request_params.merge({ :id => asset.id })
|
81
|
+
response.should redirect_to(root_path)
|
82
|
+
request.flash[:error].should =~ /not found$/
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should delete the asset and show a notice" do
|
86
|
+
delete "destroy", additional_request_params.merge({ :id => asset.id })
|
87
|
+
response.should redirect_to(root_path)
|
88
|
+
request.flash[:error].should =~ /not found$/
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "create asset" do
|
92
|
+
after(:each) do
|
93
|
+
assigns(:content).should_not be_nil
|
94
|
+
assigns(:content).asset.name.should eq("Test")
|
95
|
+
end
|
96
|
+
|
97
|
+
let(:meta_data) do
|
98
|
+
{"asset" => {"name" => "Test"},
|
99
|
+
"classification" => {}}
|
100
|
+
end
|
101
|
+
|
102
|
+
context "HTML request" do
|
103
|
+
it "should create a new asset" do
|
104
|
+
p = meta_data.merge(create_params)
|
105
|
+
controller.current_user.stub!(:tray_positions) { double(TrayPosition, :maximum => nil) }
|
106
|
+
post 'create', additional_request_params.merge(p)
|
107
|
+
content = assigns(:content)
|
108
|
+
content.errors.messages.should == {}
|
109
|
+
request.flash[:notice].should =~ /^Created new asset!$/
|
110
|
+
response.should redirect_to controller.url_for(content) + "/edit"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should fail when asset cannot be saved" do
|
114
|
+
p = meta_data
|
115
|
+
post 'create', additional_request_params.merge(p)
|
116
|
+
response.should render_template 'assets/new'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "JS request" do
|
121
|
+
it "should create a new asset" do
|
122
|
+
p = meta_data.merge(create_params).merge({:format => :js})
|
123
|
+
post 'create', additional_request_params.merge(p)
|
124
|
+
content = assigns(:content)
|
125
|
+
content.errors.messages.should == {}
|
126
|
+
JSON.parse(response.body).class.should == Hash
|
127
|
+
JSON.parse(response.body)["status"].should == "ok"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should fail when asset cannot be saved" do
|
131
|
+
p = meta_data
|
132
|
+
post 'create', additional_request_params.merge(p).merge({:format => :js})
|
133
|
+
JSON.parse(response.body)["errors"].should_not be_nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
module FassetsCore::TestHelpers
|
141
|
+
def setup_content
|
142
|
+
my_a = asset
|
143
|
+
my_a.stub!(:destroy)
|
144
|
+
my_a.stub!(:update_attributes) { true }
|
145
|
+
my_a.stub!(:asset) { double(Asset, :update_attributes => true, :name => "Example Asset") }
|
146
|
+
controller.stub!(:find_content) { }
|
147
|
+
controller.instance_eval { @content = my_a }
|
148
|
+
end
|
149
|
+
|
150
|
+
def root_path
|
151
|
+
"/"
|
152
|
+
end
|
153
|
+
|
154
|
+
def additional_request_params
|
155
|
+
{}
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
RSpec.configure do |config|
|
160
|
+
config.include FassetsCore::TestHelpers, :type => :controller
|
161
|
+
end
|