resources_controller 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.rdoc +330 -0
- data/TODO +0 -0
- data/VERSION.yml +4 -0
- data/generators/scaffold_resource/USAGE +29 -0
- data/generators/scaffold_resource/scaffold_resource_generator.rb +179 -0
- data/generators/scaffold_resource/templates/controller.rb +2 -0
- data/generators/scaffold_resource/templates/fixtures.yml +10 -0
- data/generators/scaffold_resource/templates/functional_test.rb +57 -0
- data/generators/scaffold_resource/templates/helper.rb +2 -0
- data/generators/scaffold_resource/templates/migration.rb +15 -0
- data/generators/scaffold_resource/templates/model.rb +2 -0
- data/generators/scaffold_resource/templates/old_migration.rb +13 -0
- data/generators/scaffold_resource/templates/rspec/functional_spec.rb +255 -0
- data/generators/scaffold_resource/templates/rspec/helper_spec.rb +11 -0
- data/generators/scaffold_resource/templates/rspec/routing_spec.rb +61 -0
- data/generators/scaffold_resource/templates/rspec/unit_spec.rb +11 -0
- data/generators/scaffold_resource/templates/rspec/views/edit_spec.rb +28 -0
- data/generators/scaffold_resource/templates/rspec/views/index_spec.rb +26 -0
- data/generators/scaffold_resource/templates/rspec/views/new_spec.rb +30 -0
- data/generators/scaffold_resource/templates/rspec/views/show_spec.rb +25 -0
- data/generators/scaffold_resource/templates/shoulda_functional_test.rb +19 -0
- data/generators/scaffold_resource/templates/unit_test.rb +7 -0
- data/generators/scaffold_resource/templates/view__form.erb +6 -0
- data/generators/scaffold_resource/templates/view__form.haml +5 -0
- data/generators/scaffold_resource/templates/view_edit.erb +16 -0
- data/generators/scaffold_resource/templates/view_edit.haml +11 -0
- data/generators/scaffold_resource/templates/view_index.erb +22 -0
- data/generators/scaffold_resource/templates/view_index.haml +19 -0
- data/generators/scaffold_resource/templates/view_new.erb +12 -0
- data/generators/scaffold_resource/templates/view_new.haml +9 -0
- data/generators/scaffold_resource/templates/view_show.erb +9 -0
- data/generators/scaffold_resource/templates/view_show.haml +9 -0
- data/lib/resource_controller/accessors.rb +77 -0
- data/lib/resource_controller/action_options.rb +40 -0
- data/lib/resource_controller/actions.rb +75 -0
- data/lib/resource_controller/base.rb +15 -0
- data/lib/resource_controller/controller.rb +69 -0
- data/lib/resource_controller/failable_action_options.rb +25 -0
- data/lib/resource_controller/helpers/current_objects.rb +82 -0
- data/lib/resource_controller/helpers/internal.rb +80 -0
- data/lib/resource_controller/helpers/nested.rb +82 -0
- data/lib/resource_controller/helpers/singleton_customizations.rb +64 -0
- data/lib/resource_controller/helpers/urls.rb +132 -0
- data/lib/resource_controller/helpers.rb +34 -0
- data/lib/resource_controller/response_collector.rb +27 -0
- data/lib/resource_controller/singleton.rb +15 -0
- data/lib/resource_controller.rb +54 -0
- data/lib/urligence.rb +52 -0
- data/rails/init.rb +6 -0
- data/test/Gemfile +11 -0
- data/test/Rakefile +10 -0
- data/test/app/controllers/accounts_controller.rb +6 -0
- data/test/app/controllers/application_controller.rb +5 -0
- data/test/app/controllers/cms/options_controller.rb +3 -0
- data/test/app/controllers/cms/personnel_controller.rb +2 -0
- data/test/app/controllers/cms/photos_controller.rb +6 -0
- data/test/app/controllers/cms/products_controller.rb +3 -0
- data/test/app/controllers/comments_controller.rb +3 -0
- data/test/app/controllers/images_controller.rb +4 -0
- data/test/app/controllers/options_controller.rb +8 -0
- data/test/app/controllers/people_controller.rb +9 -0
- data/test/app/controllers/photos_controller.rb +12 -0
- data/test/app/controllers/posts_controller.rb +10 -0
- data/test/app/controllers/projects_controller.rb +3 -0
- data/test/app/controllers/somethings_controller.rb +3 -0
- data/test/app/controllers/tags_controller.rb +13 -0
- data/test/app/controllers/users_controller.rb +12 -0
- data/test/app/helpers/accounts_helper.rb +2 -0
- data/test/app/helpers/application_helper.rb +3 -0
- data/test/app/helpers/cms/products_helper.rb +2 -0
- data/test/app/helpers/comments_helper.rb +2 -0
- data/test/app/helpers/images_helper.rb +2 -0
- data/test/app/helpers/options_helper.rb +2 -0
- data/test/app/helpers/people_helper.rb +2 -0
- data/test/app/helpers/photos_helper.rb +2 -0
- data/test/app/helpers/posts_helper.rb +2 -0
- data/test/app/helpers/projects_helper.rb +2 -0
- data/test/app/helpers/somethings_helper.rb +2 -0
- data/test/app/helpers/tags_helper.rb +2 -0
- data/test/app/helpers/users_helper.rb +2 -0
- data/test/app/models/account.rb +4 -0
- data/test/app/models/comment.rb +3 -0
- data/test/app/models/image.rb +3 -0
- data/test/app/models/option.rb +3 -0
- data/test/app/models/personnel.rb +3 -0
- data/test/app/models/photo.rb +5 -0
- data/test/app/models/post.rb +3 -0
- data/test/app/models/product.rb +3 -0
- data/test/app/models/project.rb +2 -0
- data/test/app/models/something.rb +2 -0
- data/test/app/models/tag.rb +3 -0
- data/test/app/models/user.rb +3 -0
- data/test/app/views/accounts/_form.html.erb +4 -0
- data/test/app/views/accounts/edit.html.erb +14 -0
- data/test/app/views/accounts/new.html.erb +12 -0
- data/test/app/views/accounts/show.html.erb +5 -0
- data/test/app/views/cms/options/edit.rhtml +17 -0
- data/test/app/views/cms/options/index.rhtml +20 -0
- data/test/app/views/cms/options/new.rhtml +16 -0
- data/test/app/views/cms/options/show.rhtml +8 -0
- data/test/app/views/cms/photos/edit.rhtml +17 -0
- data/test/app/views/cms/photos/index.rhtml +20 -0
- data/test/app/views/cms/photos/new.rhtml +16 -0
- data/test/app/views/cms/photos/show.rhtml +8 -0
- data/test/app/views/cms/products/edit.rhtml +17 -0
- data/test/app/views/cms/products/index.rhtml +20 -0
- data/test/app/views/cms/products/new.rhtml +16 -0
- data/test/app/views/cms/products/show.rhtml +8 -0
- data/test/app/views/comments/edit.rhtml +27 -0
- data/test/app/views/comments/index.rhtml +24 -0
- data/test/app/views/comments/new.rhtml +26 -0
- data/test/app/views/comments/show.rhtml +18 -0
- data/test/app/views/images/_form.html.erb +4 -0
- data/test/app/views/images/edit.html.erb +14 -0
- data/test/app/views/images/new.html.erb +12 -0
- data/test/app/views/layouts/application.rhtml +17 -0
- data/test/app/views/layouts/comments.rhtml +17 -0
- data/test/app/views/layouts/options.rhtml +17 -0
- data/test/app/views/layouts/people.rhtml +17 -0
- data/test/app/views/layouts/photos.rhtml +17 -0
- data/test/app/views/layouts/projects.rhtml +17 -0
- data/test/app/views/layouts/somethings.rhtml +17 -0
- data/test/app/views/layouts/tags.rhtml +17 -0
- data/test/app/views/options/_form.html.erb +8 -0
- data/test/app/views/options/edit.html.erb +16 -0
- data/test/app/views/options/index.html.erb +21 -0
- data/test/app/views/options/new.html.erb +12 -0
- data/test/app/views/options/show.html.erb +10 -0
- data/test/app/views/people/edit.rhtml +17 -0
- data/test/app/views/people/index.rhtml +20 -0
- data/test/app/views/people/new.rhtml +16 -0
- data/test/app/views/people/show.rhtml +8 -0
- data/test/app/views/photos/edit.rhtml +17 -0
- data/test/app/views/photos/index.rhtml +20 -0
- data/test/app/views/photos/new.rhtml +16 -0
- data/test/app/views/photos/show.rhtml +8 -0
- data/test/app/views/posts/edit.rhtml +22 -0
- data/test/app/views/posts/index.rhtml +22 -0
- data/test/app/views/posts/new.rhtml +21 -0
- data/test/app/views/posts/show.rhtml +13 -0
- data/test/app/views/projects/edit.rhtml +17 -0
- data/test/app/views/projects/index.rhtml +20 -0
- data/test/app/views/projects/new.rhtml +16 -0
- data/test/app/views/projects/show.rhtml +8 -0
- data/test/app/views/somethings/edit.rhtml +17 -0
- data/test/app/views/somethings/index.rhtml +20 -0
- data/test/app/views/somethings/new.rhtml +16 -0
- data/test/app/views/somethings/show.rhtml +8 -0
- data/test/app/views/tags/edit.rhtml +17 -0
- data/test/app/views/tags/index.rhtml +20 -0
- data/test/app/views/tags/index.rjs +0 -0
- data/test/app/views/tags/new.rhtml +16 -0
- data/test/app/views/tags/show.rhtml +8 -0
- data/test/app/views/users/edit.rhtml +17 -0
- data/test/app/views/users/index.rhtml +20 -0
- data/test/app/views/users/new.rhtml +16 -0
- data/test/app/views/users/show.rhtml +8 -0
- data/test/config/application.rb +41 -0
- data/test/config/boot.rb +6 -0
- data/test/config/database.yml +9 -0
- data/test/config/environment.rb +5 -0
- data/test/config/environments/development.rb +19 -0
- data/test/config/environments/test.rb +32 -0
- data/test/config/initializers/inflections.rb +14 -0
- data/test/config/initializers/secret_token.rb +7 -0
- data/test/config/initializers/session_store.rb +8 -0
- data/test/config/routes.rb +35 -0
- data/test/config.ru +4 -0
- data/test/db/migrate/001_create_posts.rb +12 -0
- data/test/db/migrate/002_create_products.rb +11 -0
- data/test/db/migrate/003_create_comments.rb +13 -0
- data/test/db/migrate/004_create_options.rb +13 -0
- data/test/db/migrate/005_create_photos.rb +11 -0
- data/test/db/migrate/006_create_tags.rb +17 -0
- data/test/db/migrate/007_create_somethings.rb +11 -0
- data/test/db/migrate/008_create_accounts.rb +11 -0
- data/test/db/migrate/009_add_account_id_to_photos.rb +9 -0
- data/test/db/migrate/010_create_projects.rb +11 -0
- data/test/db/migrate/011_create_images.rb +12 -0
- data/test/db/migrate/012_create_users.rb +11 -0
- data/test/db/migrate/013_create_personnel.rb +11 -0
- data/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
- data/test/db/schema.rb +78 -0
- data/test/script/console +3 -0
- data/test/script/destroy +3 -0
- data/test/script/generate +3 -0
- data/test/script/rails +6 -0
- data/test/script/server +3 -0
- data/test/test/fixtures/accounts.yml +7 -0
- data/test/test/fixtures/comments.yml +11 -0
- data/test/test/fixtures/images.yml +6 -0
- data/test/test/fixtures/options.yml +9 -0
- data/test/test/fixtures/personnel.yml +5 -0
- data/test/test/fixtures/photos.yml +9 -0
- data/test/test/fixtures/photos_tags.yml +3 -0
- data/test/test/fixtures/posts.yml +9 -0
- data/test/test/fixtures/products.yml +7 -0
- data/test/test/fixtures/projects.yml +7 -0
- data/test/test/fixtures/somethings.yml +7 -0
- data/test/test/fixtures/tags.yml +7 -0
- data/test/test/fixtures/users.yml +5 -0
- data/test/test/functional/cms/options_controller_test.rb +140 -0
- data/test/test/functional/cms/photos_controller_test.rb +37 -0
- data/test/test/functional/cms/products_controller_test.rb +37 -0
- data/test/test/functional/comments_controller_test.rb +140 -0
- data/test/test/functional/images_controller_test.rb +30 -0
- data/test/test/functional/people_controller_test.rb +147 -0
- data/test/test/functional/photos_controller_test.rb +199 -0
- data/test/test/functional/posts_controller_test.rb +21 -0
- data/test/test/functional/projects_controller_test.rb +137 -0
- data/test/test/functional/somethings_controller_test.rb +15 -0
- data/test/test/functional/tags_controller_test.rb +53 -0
- data/test/test/functional/users_controller_test.rb +137 -0
- data/test/test/test_helper.rb +14 -0
- data/test/test/unit/accessors_test.rb +110 -0
- data/test/test/unit/account_test.rb +7 -0
- data/test/test/unit/action_options_test.rb +109 -0
- data/test/test/unit/base_test.rb +11 -0
- data/test/test/unit/comment_test.rb +10 -0
- data/test/test/unit/failable_action_options_test.rb +77 -0
- data/test/test/unit/helpers/current_objects_test.rb +133 -0
- data/test/test/unit/helpers/internal_test.rb +106 -0
- data/test/test/unit/helpers/nested_test.rb +86 -0
- data/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
- data/test/test/unit/helpers/singleton_nested_test.rb +77 -0
- data/test/test/unit/helpers/singleton_urls_test.rb +67 -0
- data/test/test/unit/helpers/urls_test.rb +75 -0
- data/test/test/unit/helpers_test.rb +25 -0
- data/test/test/unit/image_test.rb +7 -0
- data/test/test/unit/option_test.rb +10 -0
- data/test/test/unit/photo_test.rb +10 -0
- data/test/test/unit/post_test.rb +10 -0
- data/test/test/unit/project_test.rb +10 -0
- data/test/test/unit/response_collector_test.rb +49 -0
- data/test/test/unit/something_test.rb +10 -0
- data/test/test/unit/tag_test.rb +10 -0
- data/test/test/unit/urligence_test.rb +205 -0
- data/test/vendor/plugins/d +1 -0
- data/test/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
- data/test/vendor/plugins/dynamic_form/README +13 -0
- data/test/vendor/plugins/dynamic_form/Rakefile +10 -0
- data/test/vendor/plugins/dynamic_form/init.rb +5 -0
- data/test/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
- data/test/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
- data/test/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
- data/test/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
- data/test/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
- metadata +403 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class CommentsControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@post = posts :one
|
|
6
|
+
@comment = Comment.find 1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
context "on GET to index" do
|
|
10
|
+
setup do
|
|
11
|
+
get :index, :post_id => 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should assign_to(:comments).with_kind_of(Array)
|
|
15
|
+
should assign_to(:post).with_kind_of(Post)
|
|
16
|
+
should respond_with :success
|
|
17
|
+
should render_with_layout
|
|
18
|
+
should render_template :index
|
|
19
|
+
should_not set_the_flash
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "on GET to :show" do
|
|
23
|
+
setup do
|
|
24
|
+
get :show, :id => 1, :post_id => 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should assign_to(:comment).with_kind_of(Comment)
|
|
28
|
+
should assign_to(:post).with_kind_of(Post)
|
|
29
|
+
should respond_with(:success)
|
|
30
|
+
should render_template(:show)
|
|
31
|
+
should_not set_the_flash
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "on GET to :new" do
|
|
35
|
+
setup do
|
|
36
|
+
get :new, :post_id => 1
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should assign_to(:comment).with_kind_of(Comment)
|
|
40
|
+
should assign_to(:post).with_kind_of(Post)
|
|
41
|
+
should respond_with :success
|
|
42
|
+
should render_with_layout :comments
|
|
43
|
+
should render_template :new
|
|
44
|
+
should_not set_the_flash
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "on POST to :create" do
|
|
48
|
+
context "that succeeds" do
|
|
49
|
+
setup do
|
|
50
|
+
post :create, :comment => {:body => "My comment", :author => "Somebody"}, :post_id => 1
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should assign_to(:comment).with_kind_of(Comment)
|
|
54
|
+
should redirect_to("post comments index") { post_comment_url(@post, assigns(:comment)) }
|
|
55
|
+
should set_the_flash.to "Successfully created!"
|
|
56
|
+
|
|
57
|
+
should "create the record" do
|
|
58
|
+
assert Comment.find_by_body("My comment")
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "that fails" do
|
|
63
|
+
setup do
|
|
64
|
+
Comment.any_instance.stubs(:save).returns(false)
|
|
65
|
+
post :create, :comment => {}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
should assign_to(:comment).with_kind_of(Comment)
|
|
69
|
+
should respond_with :success
|
|
70
|
+
should render_with_layout :comments
|
|
71
|
+
should render_template :new
|
|
72
|
+
should_not set_the_flash
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "on GET to :edit" do
|
|
77
|
+
setup do
|
|
78
|
+
get :edit, :id => @comment.id
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
should assign_to(:comment).with(@comment)
|
|
82
|
+
should respond_with :success
|
|
83
|
+
should render_with_layout :comments
|
|
84
|
+
should render_template :edit
|
|
85
|
+
should_not set_the_flash
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "on PUT to :update" do
|
|
89
|
+
context "that succeeds" do
|
|
90
|
+
setup do
|
|
91
|
+
put :update, :id => @comment.id, :comment => {:body => 'My new comment'}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
should assign_to(:comment){ @comment }
|
|
95
|
+
should redirect_to("comment page") { comment_path(assigns(:comment)) }
|
|
96
|
+
should set_the_flash.to "Successfully updated!"
|
|
97
|
+
|
|
98
|
+
should "update the record" do
|
|
99
|
+
@comment.reload
|
|
100
|
+
assert_equal 'My new comment', @comment.body
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "that fails" do
|
|
105
|
+
setup do
|
|
106
|
+
Comment.any_instance.stubs(:update_attributes).returns(false)
|
|
107
|
+
put :update, :id => @comment.id, :comment => {:body => 'My new comment'}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should assign_to(:object).with_kind_of(Comment)
|
|
111
|
+
should assign_to(:comment).with_kind_of(Comment)
|
|
112
|
+
should respond_with :success
|
|
113
|
+
should render_with_layout :comments
|
|
114
|
+
should render_template :edit
|
|
115
|
+
should_not set_the_flash
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context "on DELETE to :destroy" do
|
|
120
|
+
context "that succeeds" do
|
|
121
|
+
setup do
|
|
122
|
+
delete :destroy, :id => @comment.id
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
should assign_to(:comment){ @comment }
|
|
126
|
+
should redirect_to("comments index"){ comments_path }
|
|
127
|
+
should set_the_flash.to "Successfully removed!"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context "that fails" do
|
|
131
|
+
setup do
|
|
132
|
+
Comment.any_instance.stubs(:destroy).returns(false)
|
|
133
|
+
delete :destroy, :id => @comment.to_param
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
should respond_with(:redirect)
|
|
137
|
+
should redirect_to("comment url") { comment_url @comment }
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ImagesControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@image = images :one
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "with user as parent" do
|
|
9
|
+
|
|
10
|
+
context "on post to :create" do
|
|
11
|
+
setup do
|
|
12
|
+
post :create, :user_id => 1, :photo => {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should redirect_to("user image page") { user_image_path(@image.user) }
|
|
16
|
+
should assign_to :image
|
|
17
|
+
should assign_to :user
|
|
18
|
+
should "scope image to user" do
|
|
19
|
+
assert users(:one), assigns(:image).user
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should "not respond to show" do
|
|
26
|
+
assert_raise(ActionController::UnknownAction) do
|
|
27
|
+
get :show
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PeopleControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@person = accounts :one
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# should_be_restful do |resource|
|
|
9
|
+
# resource.formats = [:html]
|
|
10
|
+
# resource.klass = Account
|
|
11
|
+
# resource.object = :person
|
|
12
|
+
#
|
|
13
|
+
# resource.create.redirect = 'person_url(@person)'
|
|
14
|
+
# resource.update.redirect = 'person_url(@person)'
|
|
15
|
+
# resource.destroy.redirect = 'people_url'
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
|
+
context "on GET to index" do
|
|
19
|
+
setup do
|
|
20
|
+
get :index
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should assign_to(:people).with_kind_of(Array)
|
|
24
|
+
should respond_with :success
|
|
25
|
+
should render_with_layout
|
|
26
|
+
should render_template :index
|
|
27
|
+
should_not set_the_flash
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "on GET to :show" do
|
|
31
|
+
setup do
|
|
32
|
+
get :show, :id => 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should assign_to(:person)
|
|
36
|
+
should respond_with(:success)
|
|
37
|
+
should render_template(:show)
|
|
38
|
+
should_not set_the_flash
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "on GET to :new" do
|
|
42
|
+
setup do
|
|
43
|
+
get :new
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should assign_to(:person).with_kind_of(Account)
|
|
47
|
+
should respond_with :success
|
|
48
|
+
should render_with_layout :people
|
|
49
|
+
should render_template :new
|
|
50
|
+
should_not set_the_flash
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "on POST to :create" do
|
|
54
|
+
context "that succeeds" do
|
|
55
|
+
setup do
|
|
56
|
+
post :create, :person => {}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
should assign_to(:person).with_kind_of(Account)
|
|
60
|
+
should redirect_to("people index") { person_url(assigns(:person)) }
|
|
61
|
+
should set_the_flash.to "Successfully created!"
|
|
62
|
+
|
|
63
|
+
should "create the record" do
|
|
64
|
+
assert Account.find_by_name("Bob Loblaw")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "that fails" do
|
|
69
|
+
setup do
|
|
70
|
+
Account.any_instance.stubs(:save).returns(false)
|
|
71
|
+
post :create, :person => {}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
should assign_to(:person).with_kind_of(Account)
|
|
75
|
+
should respond_with :success
|
|
76
|
+
should render_with_layout :people
|
|
77
|
+
should render_template :new
|
|
78
|
+
should_not set_the_flash
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "on GET to :edit" do
|
|
83
|
+
setup do
|
|
84
|
+
get :edit, :id => @person.id
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should assign_to(:person).with(@person)
|
|
88
|
+
should respond_with :success
|
|
89
|
+
should render_with_layout :people
|
|
90
|
+
should render_template :edit
|
|
91
|
+
should_not set_the_flash
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "on PUT to :update" do
|
|
95
|
+
context "that succeeds" do
|
|
96
|
+
setup do
|
|
97
|
+
put :update, :id => @person.id, :person => {:name => 'Marcel Marceau'}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
should assign_to(:person){ @person }
|
|
101
|
+
should redirect_to("person page") { person_path(assigns(:person)) }
|
|
102
|
+
should set_the_flash.to "Successfully updated!"
|
|
103
|
+
|
|
104
|
+
should "update the record" do
|
|
105
|
+
@person.reload
|
|
106
|
+
assert_equal 'Marcel Marceau', @person.name
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context "that fails" do
|
|
111
|
+
setup do
|
|
112
|
+
Account.any_instance.stubs(:update_attributes).returns(false)
|
|
113
|
+
put :update, :id => @person.id, :person => {:name => 'Marcel Marceau'}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
should assign_to(:object).with_kind_of(Account)
|
|
117
|
+
should assign_to(:person).with_kind_of(Account)
|
|
118
|
+
should respond_with :success
|
|
119
|
+
should render_with_layout :people
|
|
120
|
+
should render_template :edit
|
|
121
|
+
should_not set_the_flash
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "on DELETE to :destroy" do
|
|
126
|
+
context "that succeeds" do
|
|
127
|
+
setup do
|
|
128
|
+
delete :destroy, :id => @person.id
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
should assign_to(:person){ @person }
|
|
132
|
+
should redirect_to("people index"){ people_path }
|
|
133
|
+
should set_the_flash.to "Successfully removed!"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context "that fails" do
|
|
137
|
+
setup do
|
|
138
|
+
Account.any_instance.stubs(:destroy).returns(false)
|
|
139
|
+
delete :destroy, :id => @person.to_param
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
should respond_with(:redirect)
|
|
143
|
+
should redirect_to("person url") { person_url @person }
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PhotosControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@user = users :one
|
|
6
|
+
@photo = Photo.find 1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
context "actions specified" do
|
|
10
|
+
should "not respond to update" do
|
|
11
|
+
assert !@controller.respond_to?(:update)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# should_be_restful do |resource|
|
|
16
|
+
# resource.formats = [:html]
|
|
17
|
+
#
|
|
18
|
+
# resource.actions = [:index, :new, :create, :destroy, :show, :edit]
|
|
19
|
+
# resource.create.params = {:title => 'Some Photo Title'}
|
|
20
|
+
# resource.create.flash = "Some Photo Title was created!"
|
|
21
|
+
# end
|
|
22
|
+
|
|
23
|
+
# RESTful test
|
|
24
|
+
#
|
|
25
|
+
context "on GET to index" do
|
|
26
|
+
setup do
|
|
27
|
+
get :index, :user_id => 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
should assign_to(:photos).with_kind_of(Array)
|
|
31
|
+
should assign_to(:user).with_kind_of(Account)
|
|
32
|
+
should respond_with :success
|
|
33
|
+
should render_with_layout
|
|
34
|
+
should render_template :index
|
|
35
|
+
should_not set_the_flash
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "on GET to :show" do
|
|
39
|
+
setup do
|
|
40
|
+
get :show, :id => 1, :user_id => 1
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
should assign_to(:photo).with_kind_of(Photo)
|
|
44
|
+
should assign_to(:user).with_kind_of(Account)
|
|
45
|
+
should respond_with(:success)
|
|
46
|
+
should render_template(:show)
|
|
47
|
+
should_not set_the_flash
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "on GET to :new" do
|
|
51
|
+
setup do
|
|
52
|
+
get :new, :user_id => 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
should assign_to(:photo).with_kind_of(Photo)
|
|
56
|
+
should assign_to(:user).with_kind_of(Account)
|
|
57
|
+
should respond_with :success
|
|
58
|
+
should render_with_layout :photos
|
|
59
|
+
should render_template :new
|
|
60
|
+
should_not set_the_flash
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "on POST to :create" do
|
|
64
|
+
context "that succeeds" do
|
|
65
|
+
setup do
|
|
66
|
+
post :create, :photo => {:title => "My photo"}, :user_id => 1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
should assign_to(:photo).with_kind_of(Photo)
|
|
70
|
+
should redirect_to("user photos page") { user_photo_url(@user, assigns(:photo)) }
|
|
71
|
+
should set_the_flash.to "My photo was created!"
|
|
72
|
+
|
|
73
|
+
should "create the record" do
|
|
74
|
+
assert Photo.find_by_title("My photo")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "that fails" do
|
|
79
|
+
setup do
|
|
80
|
+
Photo.any_instance.stubs(:save).returns(false)
|
|
81
|
+
post :create, :photo => {}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
should assign_to(:photo).with_kind_of(Photo)
|
|
85
|
+
should respond_with :success
|
|
86
|
+
should render_with_layout :photos
|
|
87
|
+
should render_template :new
|
|
88
|
+
should_not set_the_flash
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "on GET to :edit" do
|
|
93
|
+
setup do
|
|
94
|
+
get :edit, :id => @photo.id
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
should assign_to(:photo).with(@photo)
|
|
98
|
+
should respond_with :success
|
|
99
|
+
should render_with_layout :photos
|
|
100
|
+
should render_template :edit
|
|
101
|
+
should_not set_the_flash
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "on DELETE to :destroy" do
|
|
105
|
+
context "that succeeds" do
|
|
106
|
+
setup do
|
|
107
|
+
delete :destroy, :id => @photo.id
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should assign_to(:photo){ @photo }
|
|
111
|
+
should redirect_to("photos index"){ photos_path }
|
|
112
|
+
should set_the_flash.to "Successfully removed!"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context "that fails" do
|
|
116
|
+
setup do
|
|
117
|
+
Photo.any_instance.stubs(:destroy).returns(false)
|
|
118
|
+
delete :destroy, :id => @photo.to_param
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
should respond_with(:redirect)
|
|
122
|
+
should redirect_to("photo url") { photo_url @photo }
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# url helpers integration
|
|
128
|
+
|
|
129
|
+
context "url, path, and hash_for helpers" do
|
|
130
|
+
setup do
|
|
131
|
+
get :index
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
should "return collection url" do
|
|
135
|
+
assert_equal photos_url, @controller.send(:collection_url)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
should "return collection path" do
|
|
139
|
+
assert_equal photos_path, @controller.send(:collection_path)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
should "return hash for collection url" do
|
|
143
|
+
assert_equal hash_for_photos_url, @controller.send(:hash_for_collection_url)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
should "return hash for collection path" do
|
|
147
|
+
assert_equal hash_for_photos_path, @controller.send(:hash_for_collection_path)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
should "return object url" do
|
|
151
|
+
assert_equal photo_url(photos(:one)), @controller.send(:object_url, photos(:one))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
should "return object path" do
|
|
155
|
+
assert_equal photo_path(photos(:one)), @controller.send(:object_path, photos(:one))
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
should "return hash_for object url" do
|
|
159
|
+
assert_equal hash_for_photo_url(:id => @photo.to_param), @controller.send(:hash_for_object_url, photos(:one))
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
should "return hash_for object path" do
|
|
163
|
+
assert_equal hash_for_photo_path(:id => @photo.to_param), @controller.send(:hash_for_object_path, photos(:one))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
should "return edit object url" do
|
|
167
|
+
assert_equal edit_photo_url(photos(:one)), @controller.send(:edit_object_url, photos(:one))
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
should "return edit object path" do
|
|
171
|
+
assert_equal edit_photo_path(photos(:one)), @controller.send(:edit_object_path, photos(:one))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
should "return hash_for_edit object url" do
|
|
175
|
+
assert_equal hash_for_edit_photo_url(:id => @photo.to_param), @controller.send(:hash_for_edit_object_url, photos(:one))
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
should "return hash_for_edit object path" do
|
|
179
|
+
assert_equal hash_for_edit_photo_path(:id => @photo.to_param), @controller.send(:hash_for_edit_object_path, photos(:one))
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
should "return new object url" do
|
|
183
|
+
assert_equal new_photo_url, @controller.send(:new_object_url)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
should "return new object path" do
|
|
187
|
+
assert_equal new_photo_path, @controller.send(:new_object_path)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
should "return hash_for_new object url" do
|
|
191
|
+
assert_equal hash_for_new_photo_url, @controller.send(:hash_for_new_object_url)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
should "return hash_for_new object path" do
|
|
195
|
+
assert_equal hash_for_new_photo_path, @controller.send(:hash_for_new_object_path)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PostsControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@post = Post.find 1
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "on post to :create" do
|
|
9
|
+
setup do
|
|
10
|
+
post :create, :post => {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should "name the post 'a great post'" do
|
|
14
|
+
assert_equal 'a great post', assigns(:post).title
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
should "give the post a body of '...'" do
|
|
18
|
+
assert_equal '...', assigns(:post).body
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ProjectsControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@project = projects :one
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "on GET to index" do
|
|
9
|
+
setup do
|
|
10
|
+
get :index
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should assign_to(:projects).with_kind_of(Array)
|
|
14
|
+
should respond_with :success
|
|
15
|
+
should render_with_layout
|
|
16
|
+
should render_template :index
|
|
17
|
+
should_not set_the_flash
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "on GET to :show" do
|
|
21
|
+
setup do
|
|
22
|
+
get :show, :id => 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should assign_to(:project)
|
|
26
|
+
should respond_with(:success)
|
|
27
|
+
should render_template(:show)
|
|
28
|
+
should_not set_the_flash
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "on GET to :new" do
|
|
32
|
+
setup do
|
|
33
|
+
get :new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
should assign_to(:project).with_kind_of(Project)
|
|
37
|
+
should respond_with :success
|
|
38
|
+
should render_with_layout :projects
|
|
39
|
+
should render_template :new
|
|
40
|
+
should_not set_the_flash
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "on POST to :create" do
|
|
44
|
+
context "that succeeds" do
|
|
45
|
+
setup do
|
|
46
|
+
post :create, :project => {:title => "My Project"}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should assign_to(:project).with_kind_of(Project)
|
|
50
|
+
should redirect_to("projects page") { project_url(assigns(:project)) }
|
|
51
|
+
should set_the_flash.to "Successfully created!"
|
|
52
|
+
|
|
53
|
+
should "create the record" do
|
|
54
|
+
assert Project.find_by_title("My Project")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "that fails" do
|
|
59
|
+
setup do
|
|
60
|
+
Project.any_instance.stubs(:save).returns(false)
|
|
61
|
+
post :create, :project => {}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
should assign_to(:project).with_kind_of(Project)
|
|
65
|
+
should respond_with :success
|
|
66
|
+
should render_with_layout :projects
|
|
67
|
+
should render_template :new
|
|
68
|
+
should_not set_the_flash
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "on GET to :edit" do
|
|
73
|
+
setup do
|
|
74
|
+
get :edit, :id => @project.id
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should assign_to(:project).with(@project)
|
|
78
|
+
should respond_with :success
|
|
79
|
+
should render_with_layout :projects
|
|
80
|
+
should render_template :edit
|
|
81
|
+
should_not set_the_flash
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "on PUT to :update" do
|
|
85
|
+
context "that succeeds" do
|
|
86
|
+
setup do
|
|
87
|
+
put :update, :id => @project.id, :project => {:title => 'My new project'}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
should assign_to(:project){ @project }
|
|
91
|
+
should redirect_to("project page") { project_path(assigns(:project)) }
|
|
92
|
+
should set_the_flash.to "Successfully updated!"
|
|
93
|
+
|
|
94
|
+
should "update the record" do
|
|
95
|
+
@project.reload
|
|
96
|
+
assert_equal 'My new project', @project.title
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "that fails" do
|
|
101
|
+
setup do
|
|
102
|
+
Project.any_instance.stubs(:update_attributes).returns(false)
|
|
103
|
+
put :update, :id => @project.id, :project => {:title => 'My new project'}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
should assign_to(:object).with_kind_of(Project)
|
|
107
|
+
should assign_to(:project).with_kind_of(Project)
|
|
108
|
+
should respond_with :success
|
|
109
|
+
should render_with_layout :projects
|
|
110
|
+
should render_template :edit
|
|
111
|
+
should_not set_the_flash
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context "on DELETE to :destroy" do
|
|
116
|
+
context "that succeeds" do
|
|
117
|
+
setup do
|
|
118
|
+
delete :destroy, :id => @project.id
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
should assign_to(:project){ @project }
|
|
122
|
+
should redirect_to("projects index"){ projects_path }
|
|
123
|
+
should set_the_flash.to "Successfully removed!"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "that fails" do
|
|
127
|
+
setup do
|
|
128
|
+
Project.any_instance.stubs(:destroy).returns(false)
|
|
129
|
+
delete :destroy, :id => @project.to_param
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
should respond_with(:redirect)
|
|
133
|
+
should redirect_to("project url") { project_url @project }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class SomethingsControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@something = somethings :one
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "actions specified" do
|
|
9
|
+
[:create, :edit, :update, :destroy, :new].each do |action|
|
|
10
|
+
should "not respond to #{action}" do
|
|
11
|
+
assert !@controller.respond_to?(action)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|