typus 3.0.8 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -1
- data/README.md +2 -2
- data/Rakefile +6 -14
- data/app/controllers/admin/base_controller.rb +1 -1
- data/app/controllers/admin/dashboard_controller.rb +0 -1
- data/app/controllers/admin/resources_controller.rb +8 -11
- data/app/controllers/admin/session_controller.rb +5 -4
- data/app/helpers/admin/base_helper.rb +9 -2
- data/app/helpers/admin/dashboard_helper.rb +0 -6
- data/app/helpers/admin/display_helper.rb +1 -0
- data/app/helpers/admin/file_preview_helper.rb +0 -2
- data/app/helpers/admin/filters_helper.rb +6 -3
- data/app/helpers/admin/form_helper.rb +2 -4
- data/app/helpers/admin/list_helper.rb +1 -3
- data/app/helpers/admin/relationships_helper.rb +2 -4
- data/app/helpers/admin/resources_helper.rb +0 -2
- data/app/helpers/admin/search_helper.rb +0 -2
- data/app/helpers/admin/sidebar_helper.rb +0 -2
- data/app/helpers/admin/table_helper.rb +3 -6
- data/app/views/admin/account/forgot_password.html.erb +2 -2
- data/app/views/admin/account/new.html.erb +3 -7
- data/app/views/admin/{helpers/dashboard → dashboard}/_applications.html.erb +0 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +1 -1
- data/app/views/admin/dashboard/show.html.erb +7 -1
- data/app/views/admin/helpers/base/_apps.html.erb +1 -1
- data/app/views/admin/helpers/base/_login_info.html.erb +2 -2
- data/app/views/admin/helpers/filters/_filters.html.erb +3 -1
- data/app/views/admin/resources/_form.html.erb +5 -2
- data/app/views/admin/resources/edit.html.erb +1 -1
- data/app/views/admin/resources/index.html.erb +1 -1
- data/app/views/admin/resources/show.html.erb +2 -2
- data/app/views/admin/session/new.html.erb +3 -7
- data/app/views/admin/templates/_belongs_to.html.erb +8 -1
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +1 -1
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +3 -1
- data/app/views/admin/templates/_string.html.erb +1 -1
- data/app/views/admin/templates/_text.html.erb +1 -1
- data/app/views/layouts/admin/base.html.erb +2 -0
- data/app/views/layouts/admin/headless.html.erb +2 -0
- data/app/views/layouts/admin/session.html.erb +6 -0
- data/config/routes.rb +4 -1
- data/lib/support/active_record.rb +0 -10
- data/lib/support/fake_user.rb +4 -6
- data/lib/support/object.rb +4 -0
- data/lib/support/string.rb +0 -8
- data/lib/typus.rb +2 -3
- data/lib/typus/authentication/base.rb +0 -1
- data/lib/typus/authentication/session.rb +22 -29
- data/lib/typus/orm/active_record.rb +5 -5
- data/lib/typus/orm/active_record/admin_user_v1.rb +93 -0
- data/lib/typus/orm/active_record/admin_user_v2.rb +49 -0
- data/lib/typus/orm/active_record/class_methods.rb +23 -143
- data/lib/typus/orm/active_record/user/instance_methods.rb +64 -0
- data/lib/typus/orm/base.rb +170 -0
- data/lib/typus/orm/mongo/class_methods.rb +11 -0
- data/lib/typus/resources.rb +2 -1
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/account_controller_test.rb +4 -2
- data/test/app/controllers/admin/assets_controller_test.rb +12 -12
- data/test/app/controllers/admin/categories_controller_test.rb +5 -12
- data/test/app/controllers/admin/comments_controller_test.rb +1 -1
- data/test/app/controllers/admin/image_holders_controller_test.rb +1 -1
- data/test/app/controllers/admin/invoices_controller_test.rb +1 -1
- data/test/app/controllers/admin/posts_controller_test.rb +32 -32
- data/test/app/controllers/admin/projects_controller_test.rb +1 -1
- data/test/app/controllers/admin/typus_users_controller_test.rb +13 -17
- data/test/app/controllers/admin/users_controller_test.rb +9 -9
- data/test/app/helpers/admin/list_helper_test.rb +17 -0
- data/test/app/models/admin_user_test.rb +5 -0
- data/test/app/models/typus_user_roles_test.rb +1 -0
- data/test/app/models/typus_user_test.rb +45 -11
- data/test/factories.rb +1 -1
- data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +40 -0
- data/test/fixtures/rails_app/app/controllers/admin_user.rb +3 -0
- data/test/fixtures/rails_app/app/models/asset.rb +0 -6
- data/test/fixtures/rails_app/app/models/hit.rb +27 -0
- data/test/fixtures/rails_app/app/views/admin/hits/_edit.html.erb +7 -0
- data/test/fixtures/rails_app/app/views/admin/hits/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/hits/index.html.erb +28 -0
- data/test/fixtures/rails_app/config/boot.rb +3 -10
- data/test/fixtures/rails_app/config/deploy.rb +1 -1
- data/test/fixtures/rails_app/config/mongoid.yml +20 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -0
- data/test/fixtures/rails_app/config/typus/mongo_db.yml +4 -0
- data/test/fixtures/rails_app/config/typus/mongo_db_roles.yml +2 -0
- data/test/fixtures/rails_app/db/schema.rb +11 -0
- data/test/lib/support/fake_user_test.rb +4 -0
- data/test/lib/support/string_test.rb +0 -18
- data/test/lib/typus/orm/active_record/class_methods_test.rb +14 -2
- data/test/lib/typus/orm/active_record/search_test.rb +1 -1
- data/test/lib/typus_test.rb +2 -1
- data/typus.gemspec +1 -1
- metadata +32 -45
- data/lib/typus/orm/active_record/instance_methods.rb +0 -13
- data/lib/typus/orm/active_record/user.rb +0 -157
- data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
- data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
- data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
- data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -6001
- data/test/fixtures/rails_app/public/javascripts/rails.js +0 -175
data/lib/typus/resources.rb
CHANGED
data/lib/typus/version.rb
CHANGED
@@ -88,7 +88,7 @@ class Admin::AccountControllerTest < ActionController::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
should "test_should_create_admin_user_session_and_redirect_user_to_its_details" do
|
91
|
-
get :show,
|
91
|
+
get :show, :id => @typus_user.token
|
92
92
|
|
93
93
|
assert_equal @typus_user.id, @request.session[:typus_user_id]
|
94
94
|
assert_response :redirect
|
@@ -96,7 +96,9 @@ class Admin::AccountControllerTest < ActionController::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
should "test_should_return_404_on_reset_passsword_if_token_is_not_valid" do
|
99
|
-
|
99
|
+
assert_raises ActiveRecord::RecordNotFound do
|
100
|
+
get :show, :id => "unexisting"
|
101
|
+
end
|
100
102
|
end
|
101
103
|
|
102
104
|
end
|
@@ -24,17 +24,17 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
should "verify there is a file link" do
|
27
|
-
get :edit,
|
27
|
+
get :edit, :id => @asset.id
|
28
28
|
assert_match /media/, @response.body
|
29
29
|
end
|
30
30
|
|
31
31
|
should "verify dragonfly can be removed" do
|
32
|
-
get :edit,
|
32
|
+
get :edit, :id => @asset.id
|
33
33
|
assert_match /Remove/, @response.body
|
34
34
|
|
35
35
|
assert @asset.dragonfly_uid.present?
|
36
36
|
|
37
|
-
get :update,
|
37
|
+
get :update, :id => @asset.id, :attribute => "dragonfly"
|
38
38
|
assert_response :redirect
|
39
39
|
assert_redirected_to "/admin/assets/edit/#{@asset.id}"
|
40
40
|
assert_equal "Asset successfully updated.", flash[:notice]
|
@@ -44,10 +44,10 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
should "verify dragonfly_required can not removed" do
|
47
|
-
get :edit,
|
47
|
+
get :edit, :id => @asset.id
|
48
48
|
assert_no_match /Remove required file/, @response.body
|
49
49
|
|
50
|
-
get :update,
|
50
|
+
get :update, :id => @asset.id, :attribute => "dragonfly_required"
|
51
51
|
assert_response :success
|
52
52
|
|
53
53
|
@asset.reload
|
@@ -56,7 +56,7 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
56
56
|
|
57
57
|
should "verify message on polymorphic relationship" do
|
58
58
|
asset = Factory(:asset)
|
59
|
-
get :edit,
|
59
|
+
get :edit, :id => asset.id, :resource => @post.class.name, :resource_id => @post.id
|
60
60
|
assert_select 'body div#flash', "Cancel adding a new asset?"
|
61
61
|
end
|
62
62
|
|
@@ -65,20 +65,20 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
65
65
|
context "Headless" do
|
66
66
|
|
67
67
|
should "render index with a custom layout" do
|
68
|
-
get :index,
|
68
|
+
get :index, :layout => "admin/headless"
|
69
69
|
assert_response :success
|
70
70
|
assert_template "admin/headless"
|
71
71
|
end
|
72
72
|
|
73
73
|
should "render new with a custom layout" do
|
74
|
-
get :new,
|
74
|
+
get :new, :layout => "admin/headless"
|
75
75
|
assert_response :success
|
76
76
|
assert_template "admin/headless"
|
77
77
|
end
|
78
78
|
|
79
79
|
should "render edit with a custom layout" do
|
80
80
|
asset = Factory(:asset)
|
81
|
-
get :edit,
|
81
|
+
get :edit, :id => asset.id, :layout => "admin/headless"
|
82
82
|
assert_response :success
|
83
83
|
assert_template "admin/headless"
|
84
84
|
end
|
@@ -125,13 +125,13 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
125
125
|
|
126
126
|
should "redirect to edit with custom layout" do
|
127
127
|
asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
|
128
|
-
post :update,
|
128
|
+
post :update, :id => @asset.id, :asset => asset, :layout => "admin/headless"
|
129
129
|
assert_response :redirect
|
130
130
|
assert_redirected_to :action => "edit", :id => @asset.id, :layout => "admin/headless"
|
131
131
|
end
|
132
132
|
|
133
133
|
should "render update with custom layout after an error" do
|
134
|
-
post :update,
|
134
|
+
post :update, :id => @asset.id, :asset => { :dragonfly_required => nil }, :layout => "admin/headless"
|
135
135
|
assert_response :success
|
136
136
|
assert_template "admin/helpers/resources/_errors"
|
137
137
|
assert_template "admin/resources/edit"
|
@@ -141,7 +141,7 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
141
141
|
should "redirect to index with custom layout" do
|
142
142
|
Typus::Resources.expects(:action_after_save).returns("index")
|
143
143
|
asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
|
144
|
-
post :update,
|
144
|
+
post :update, :id => @asset.id, :asset => asset, :layout => "admin/headless"
|
145
145
|
assert_response :redirect
|
146
146
|
assert_redirected_to :action => "index", :layout => "admin/headless"
|
147
147
|
end
|
@@ -44,30 +44,23 @@ class Admin::CategoriesControllerTest < ActionController::TestCase
|
|
44
44
|
|
45
45
|
should "position item one step down" do
|
46
46
|
get :position, { :id => @first_category.id, :go => 'move_lower' }
|
47
|
-
|
48
47
|
assert_equal "Category successfully updated.", flash[:notice]
|
49
|
-
assert_equal 2,
|
50
|
-
assert_equal 1, @second_category.reload.position
|
48
|
+
assert_equal 2, assigns(:item).position
|
51
49
|
end
|
52
50
|
|
53
51
|
should "position item one step up" do
|
54
52
|
get :position, { :id => @second_category.id, :go => 'move_higher' }
|
55
|
-
|
56
|
-
assert_equal "Category successfully updated.", flash[:notice]
|
57
|
-
assert_equal 2, @first_category.reload.position
|
58
|
-
assert_equal 1, @second_category.reload.position
|
53
|
+
assert_equal 1, assigns(:item).position
|
59
54
|
end
|
60
55
|
|
61
56
|
should "position top item to bottom" do
|
62
57
|
get :position, { :id => @first_category.id, :go => 'move_to_bottom' }
|
63
|
-
assert_equal
|
64
|
-
assert_equal 2, @first_category.reload.position
|
58
|
+
assert_equal 2, assigns(:item).position
|
65
59
|
end
|
66
60
|
|
67
61
|
should "position bottom item to top" do
|
68
62
|
get :position, { :id => @second_category.id, :go => 'move_to_top' }
|
69
|
-
assert_equal
|
70
|
-
assert_equal 1, @second_category.reload.position
|
63
|
+
assert_equal 1, assigns(:item).position
|
71
64
|
end
|
72
65
|
|
73
66
|
end
|
@@ -93,7 +86,7 @@ class Admin::CategoriesControllerTest < ActionController::TestCase
|
|
93
86
|
|
94
87
|
should "unrelate category from post" do
|
95
88
|
assert_difference('@category.posts.count', -1) do
|
96
|
-
post :unrelate,
|
89
|
+
post :unrelate, :id => @category.id, :resource => 'Post', :resource_id => @category.posts.first
|
97
90
|
end
|
98
91
|
|
99
92
|
assert_response :redirect
|
@@ -38,7 +38,7 @@ class Admin::CommentsControllerTest < ActionController::TestCase
|
|
38
38
|
@post = comment.post
|
39
39
|
|
40
40
|
assert_difference('@post.comments.count', -1) do
|
41
|
-
post :unrelate,
|
41
|
+
post :unrelate, :id => comment.id, :resource => 'Post', :resource_id => @post.id
|
42
42
|
end
|
43
43
|
|
44
44
|
assert comment.reload.post.nil?
|
@@ -66,7 +66,7 @@ class Admin::ImageHoldersControllerTest < ActionController::TestCase
|
|
66
66
|
|
67
67
|
should "work" do
|
68
68
|
assert_difference('@bird.image_holders.count', -1) do
|
69
|
-
post :unrelate,
|
69
|
+
post :unrelate, :id => @image_holder.id, :resource => "Bird", :resource_id => @bird.id
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -68,7 +68,7 @@ class Admin::InvoicesControllerTest < ActionController::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
should "work for unrelate Invoice from Order" do
|
71
|
-
post :unrelate,
|
71
|
+
post :unrelate, :id => @invoice.id, :resource => 'Order', :resource_id => @order.id
|
72
72
|
assert @order.reload.invoice.nil?
|
73
73
|
assert_equal "Order successfully updated.", flash[:notice]
|
74
74
|
end
|
@@ -60,26 +60,26 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
60
60
|
|
61
61
|
should "create" do
|
62
62
|
assert_difference('Post.count') do
|
63
|
-
post :create,
|
63
|
+
post :create, :post => @post.attributes
|
64
64
|
assert_response :redirect
|
65
65
|
assert_redirected_to "/admin/posts/edit/#{Post.last.id}"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
should "render show" do
|
70
|
-
get :show,
|
70
|
+
get :show, :id => @post.id
|
71
71
|
assert_response :success
|
72
72
|
assert_template 'show'
|
73
73
|
end
|
74
74
|
|
75
75
|
should "render edit" do
|
76
|
-
get :edit,
|
76
|
+
get :edit, :id => @post.id
|
77
77
|
assert_response :success
|
78
78
|
assert_template 'edit'
|
79
79
|
end
|
80
80
|
|
81
81
|
should "update" do
|
82
|
-
post :update,
|
82
|
+
post :update, :id => @post.id, :post => { :title => 'Updated' }
|
83
83
|
assert_response :redirect
|
84
84
|
assert_redirected_to "/admin/posts/edit/#{@post.id}"
|
85
85
|
end
|
@@ -96,7 +96,7 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
96
96
|
|
97
97
|
should "work" do
|
98
98
|
assert !@post.published
|
99
|
-
get :toggle,
|
99
|
+
get :toggle, :id => @post.id, :field => "published"
|
100
100
|
|
101
101
|
assert_response :redirect
|
102
102
|
assert_redirected_to @request.env["HTTP_REFERER"]
|
@@ -107,7 +107,7 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
107
107
|
should "render edit post when validation fails" do
|
108
108
|
@post.body = nil
|
109
109
|
@post.save(:validate => false)
|
110
|
-
get :toggle,
|
110
|
+
get :toggle, :id => @post.id, :field => "published"
|
111
111
|
assert_response :success
|
112
112
|
assert_template "admin/resources/edit"
|
113
113
|
end
|
@@ -120,28 +120,28 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
120
120
|
|
121
121
|
should "render index with accepted params" do
|
122
122
|
@post.update_attributes(:published => true)
|
123
|
-
get :index,
|
123
|
+
get :index, :published => 'true'
|
124
124
|
assert_response :success
|
125
125
|
assert_template 'index'
|
126
126
|
assert assigns(:items).size.eql?(1)
|
127
127
|
|
128
|
-
get :index,
|
128
|
+
get :index, :published => 'false'
|
129
129
|
assert assigns(:items).size.eql?(0)
|
130
130
|
end
|
131
131
|
|
132
132
|
should "render index with accepted params - search" do
|
133
133
|
@post.update_attributes(:title => "neinonon")
|
134
|
-
get :index,
|
134
|
+
get :index, :search => 'neinonon'
|
135
135
|
assert_response :success
|
136
136
|
assert_template 'index'
|
137
137
|
assert assigns(:items).size.eql?(1)
|
138
138
|
|
139
|
-
get :index,
|
139
|
+
get :index, :search => 'unexisting'
|
140
140
|
assert assigns(:items).size.eql?(0)
|
141
141
|
end
|
142
142
|
|
143
143
|
should "render index with non-accepted params" do
|
144
|
-
get :index,
|
144
|
+
get :index, :non_accepted_param => 'non_accepted_param'
|
145
145
|
assert_response :success
|
146
146
|
assert_template 'index'
|
147
147
|
end
|
@@ -247,14 +247,14 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
247
247
|
|
248
248
|
should "create an item and redirect to index" do
|
249
249
|
assert_difference('Post.count') do
|
250
|
-
post :create,
|
250
|
+
post :create, :post => @post.attributes
|
251
251
|
assert_response :redirect
|
252
252
|
assert_redirected_to :action => 'index'
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
256
|
should "update an item and redirect to index" do
|
257
|
-
post :update,
|
257
|
+
post :update, :id => @post.id, :post => { :title => 'Updated' }
|
258
258
|
assert_response :redirect
|
259
259
|
assert_redirected_to :action => 'index'
|
260
260
|
end
|
@@ -323,7 +323,7 @@ title;status
|
|
323
323
|
|
324
324
|
should "be able to edit any record" do
|
325
325
|
Post.all.each do |post|
|
326
|
-
get :edit,
|
326
|
+
get :edit, :id => post.id
|
327
327
|
assert_response :success
|
328
328
|
assert_template 'edit'
|
329
329
|
end
|
@@ -331,12 +331,12 @@ title;status
|
|
331
331
|
|
332
332
|
should "verify_admin_updating_an_item_does_not_change_typus_user_id_if_not_defined" do
|
333
333
|
_post = @post
|
334
|
-
post :update,
|
334
|
+
post :update, :id => @post.id, :post => { :title => 'Updated by admin' }
|
335
335
|
assert_equal _post.typus_user_id, @post.reload.typus_user_id
|
336
336
|
end
|
337
337
|
|
338
338
|
should "verify_admin_updating_an_item_does_change_typus_user_id_to_whatever_admin_wants" do
|
339
|
-
post :update,
|
339
|
+
post :update, :id => @post.id, :post => { :title => 'Updated', :typus_user_id => 108 }
|
340
340
|
assert_equal 108, @post.reload.typus_user_id
|
341
341
|
end
|
342
342
|
|
@@ -356,25 +356,24 @@ title;status
|
|
356
356
|
|
357
357
|
should "verify_editor_can_show_any_record" do
|
358
358
|
Post.all.each do |post|
|
359
|
-
get :show,
|
359
|
+
get :show, :id => post.id
|
360
360
|
assert_response :success
|
361
361
|
assert_template 'show'
|
362
362
|
end
|
363
363
|
end
|
364
364
|
|
365
365
|
should "verify_editor_tried_to_edit_a_post_owned_by_himself" do
|
366
|
-
|
367
|
-
get :edit, { :id => post_.id }
|
366
|
+
get :edit, :id => Factory(:post, :typus_user => @typus_user).id
|
368
367
|
assert_response :success
|
369
368
|
end
|
370
369
|
|
371
370
|
should "verify_editor_tries_to_edit_a_post_owned_by_the_admin" do
|
372
|
-
get :edit,
|
371
|
+
get :edit, :id => Factory(:post).id
|
373
372
|
assert_response :unprocessable_entity
|
374
373
|
end
|
375
374
|
|
376
375
|
should "verify_editor_tries_to_show_a_post_owned_by_the_admin" do
|
377
|
-
get :show,
|
376
|
+
get :show, :id => Factory(:post).id
|
378
377
|
assert_response :success
|
379
378
|
end
|
380
379
|
|
@@ -395,23 +394,24 @@ title;status
|
|
395
394
|
should "verify_editor_tries_to_show_a_post_owned_by_the_admin when only user items" do
|
396
395
|
Typus::Resources.expects(:only_user_items).returns(true)
|
397
396
|
post = Factory(:post)
|
398
|
-
get :show,
|
397
|
+
get :show, :id => post.id
|
399
398
|
assert_response :unprocessable_entity
|
400
399
|
end
|
401
400
|
|
402
401
|
should "verify_typus_user_id_of_item_when_creating_record" do
|
403
|
-
|
404
|
-
|
402
|
+
assert_difference('Post.count') do
|
403
|
+
post :create, :post => { :title => "Chunky Bacon", :body => "Lorem ipsum ..." }
|
404
|
+
end
|
405
405
|
|
406
|
-
assert_equal @request.session[:typus_user_id],
|
406
|
+
assert_equal @request.session[:typus_user_id], assigns(:item).typus_user_id
|
407
407
|
end
|
408
408
|
|
409
409
|
should "verify_editor_updating_an_item_does_not_change_typus_user_id" do
|
410
410
|
[ 108, nil ].each do |typus_user_id|
|
411
411
|
post_ = Factory(:post, :typus_user => @typus_user)
|
412
|
-
post :update,
|
412
|
+
post :update, :id => post_.id, :post => { :title => 'Updated', :typus_user_id => @typus_user.id }
|
413
413
|
post_updated = Post.find(post_.id)
|
414
|
-
assert_equal
|
414
|
+
assert_equal @request.session[:typus_user_id], post_updated.typus_user_id
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
@@ -432,7 +432,7 @@ title;status
|
|
432
432
|
end
|
433
433
|
|
434
434
|
should "be able to destroy posts" do
|
435
|
-
get :destroy,
|
435
|
+
get :destroy, :id => Factory(:post).id, :method => :delete
|
436
436
|
|
437
437
|
assert_response :redirect
|
438
438
|
assert_equal "Post successfully removed.", flash[:notice]
|
@@ -458,7 +458,7 @@ title;status
|
|
458
458
|
|
459
459
|
should "not be able to destroy posts" do
|
460
460
|
assert_no_difference('Post.count') do
|
461
|
-
get :destroy,
|
461
|
+
get :destroy, :id => @post.id, :method => :delete
|
462
462
|
end
|
463
463
|
assert_response :unprocessable_entity
|
464
464
|
end
|
@@ -544,7 +544,7 @@ title;status
|
|
544
544
|
context "Edit" do
|
545
545
|
|
546
546
|
setup do
|
547
|
-
get :edit,
|
547
|
+
get :edit, :id => Factory(:post).id
|
548
548
|
end
|
549
549
|
|
550
550
|
should "render_edit_and_verify_presence_of_custom_partials" do
|
@@ -560,7 +560,7 @@ title;status
|
|
560
560
|
context "Show" do
|
561
561
|
|
562
562
|
setup do
|
563
|
-
get :show,
|
563
|
+
get :show, :id => Factory(:post).id
|
564
564
|
end
|
565
565
|
|
566
566
|
should "render_show_and_verify_presence_of_custom_partials" do
|
@@ -627,7 +627,7 @@ title;status
|
|
627
627
|
Typus::Resources.stubs(:default_action_on_item).returns(action)
|
628
628
|
get :index
|
629
629
|
Post.all.each do |post|
|
630
|
-
if
|
630
|
+
if @typus_user.owns?(post)
|
631
631
|
assert_match "/posts/#{action}/#{post.id}", @response.body
|
632
632
|
else
|
633
633
|
assert_no_match /\/posts\/#{action}\/#{post.id}/, @response.body
|
@@ -19,7 +19,7 @@ class Admin::ProjectsControllerTest < ActionController::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
should_eventually "be able to destroy items" do
|
22
|
-
get :destroy,
|
22
|
+
get :destroy, :id => @user.id, :method => :delete
|
23
23
|
|
24
24
|
assert_response :redirect
|
25
25
|
assert_equal "User successfully removed.", flash[:notice]
|
@@ -52,12 +52,12 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
should "not be able to change his role" do
|
55
|
-
post :update,
|
55
|
+
post :update, :id => @typus_user.id, :typus_user => { :role => 'editor' }
|
56
56
|
assert_response :unprocessable_entity
|
57
57
|
end
|
58
58
|
|
59
59
|
should "be able to update other users role" do
|
60
|
-
post :update,
|
60
|
+
post :update, :id => @typus_user_editor.id, :typus_user => { :role => 'admin' }
|
61
61
|
assert_response :redirect
|
62
62
|
assert_redirected_to "/admin/typus_users/edit/#{@typus_user_editor.id}"
|
63
63
|
assert_equal "Typus user successfully updated.", flash[:notice]
|
@@ -79,19 +79,19 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
should "be able to edit his profile" do
|
82
|
-
get :edit,
|
82
|
+
get :edit, :id => @editor.id
|
83
83
|
assert_response :success
|
84
84
|
end
|
85
85
|
|
86
86
|
should "be able to update his profile" do
|
87
|
-
post :update,
|
87
|
+
post :update, :id => @editor.id, :typus_user => { :role => 'editor' }
|
88
88
|
assert_response :redirect
|
89
89
|
assert_redirected_to "/admin/typus_users/edit/#{@editor.id}"
|
90
90
|
assert_equal "Typus user successfully updated.", flash[:notice]
|
91
91
|
end
|
92
92
|
|
93
93
|
should "not be able to change his role" do
|
94
|
-
post :update,
|
94
|
+
post :update, :id => @editor.id, :typus_user => { :role => 'admin' }
|
95
95
|
assert_response :unprocessable_entity
|
96
96
|
end
|
97
97
|
|
@@ -106,26 +106,22 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
106
106
|
end
|
107
107
|
|
108
108
|
should "not be able to edit other profiles" do
|
109
|
-
|
110
|
-
get :edit, { :id => user.id }
|
109
|
+
get :edit, :id => Factory(:typus_user).id
|
111
110
|
assert_response :unprocessable_entity
|
112
111
|
end
|
113
112
|
|
114
113
|
should "not be able to update other profiles" do
|
115
|
-
|
116
|
-
post :update, { :id => user.id, :typus_user => { :role => 'admin' } }
|
114
|
+
post :update, :id => Factory(:typus_user).id, :typus_user => { :role => 'admin' }
|
117
115
|
assert_response :unprocessable_entity
|
118
116
|
end
|
119
117
|
|
120
118
|
should "not be able to destroy other profiles" do
|
121
|
-
|
122
|
-
delete :destroy, :id => user.id
|
119
|
+
delete :destroy, :id => Factory(:typus_user).id
|
123
120
|
assert_response :unprocessable_entity
|
124
121
|
end
|
125
122
|
|
126
123
|
should "not be able to toggle other profiles status" do
|
127
|
-
|
128
|
-
get :toggle, { :id => user.id, :field => 'status' }
|
124
|
+
get :toggle, { :id => Factory(:typus_user).id, :field => 'status' }
|
129
125
|
assert_response :unprocessable_entity
|
130
126
|
end
|
131
127
|
|
@@ -138,21 +134,21 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
138
134
|
context "Designer" do
|
139
135
|
|
140
136
|
setup do
|
141
|
-
@designer = Factory(:typus_user, :
|
137
|
+
@designer = Factory(:typus_user, :role => "designer")
|
142
138
|
@request.session[:typus_user_id] = @designer.id
|
143
139
|
end
|
144
140
|
|
145
141
|
should "be able to edit his profile" do
|
146
|
-
get :edit,
|
142
|
+
get :edit, :id => @designer.id
|
147
143
|
assert_response :success
|
148
144
|
end
|
149
145
|
|
150
146
|
should "be able to update his profile" do
|
151
|
-
post :update,
|
147
|
+
post :update, :id => @designer.id, :typus_user => { :role => 'designer', :email => 'designer@withafancydomain.com' }
|
152
148
|
assert_response :redirect
|
153
149
|
assert_redirected_to "/admin/typus_users/edit/#{@designer.id}"
|
154
150
|
assert_equal "Typus user successfully updated.", flash[:notice]
|
155
|
-
assert_equal "designer@withafancydomain.com",
|
151
|
+
assert_equal "designer@withafancydomain.com", assigns(:item).email
|
156
152
|
end
|
157
153
|
|
158
154
|
end
|