Description:
add announcement controller test
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r642:a8976e9a07cd - - 2 files changed: 4 inserted, 4 deleted
@@ -66,51 +66,51 | |||
|
66 | 66 | |
|
67 | 67 | respond_to do |format| |
|
68 | 68 | if @announcement.update_attributes(announcement_params) |
|
69 | 69 | flash[:notice] = 'Announcement was successfully updated.' |
|
70 | 70 | format.html { redirect_to(@announcement) } |
|
71 | 71 | format.js {} |
|
72 | 72 | format.xml { head :ok } |
|
73 | 73 | else |
|
74 | 74 | format.html { render :action => "edit" } |
|
75 | 75 | format.js {} |
|
76 | 76 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def toggle |
|
82 | 82 | @announcement = Announcement.find(params[:id]) |
|
83 | 83 | @announcement.update_attributes( published: !@announcement.published? ) |
|
84 | 84 | respond_to do |format| |
|
85 | 85 | format.js { render partial: 'toggle_button', |
|
86 | 86 | locals: {button_id: "#announcement_toggle_#{@announcement.id}",button_on: @announcement.published? } } |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def toggle_front |
|
91 | 91 | @announcement = Announcement.find(params[:id]) |
|
92 | 92 | @announcement.update_attributes( frontpage: !@announcement.frontpage? ) |
|
93 | 93 | respond_to do |format| |
|
94 | 94 | format.js { render partial: 'toggle_button', |
|
95 | 95 | locals: {button_id: "#announcement_toggle_front_#{@announcement.id}",button_on: @announcement.frontpage? } } |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | # DELETE /announcements/1 |
|
100 | 100 | # DELETE /announcements/1.xml |
|
101 | 101 | def destroy |
|
102 | 102 | @announcement = Announcement.find(params[:id]) |
|
103 | 103 | @announcement.destroy |
|
104 | 104 | |
|
105 | 105 | respond_to do |format| |
|
106 | 106 | format.html { redirect_to(announcements_url) } |
|
107 | 107 | format.xml { head :ok } |
|
108 | 108 | end |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | private |
|
112 | 112 | |
|
113 | 113 | def announcement_params |
|
114 |
- params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only,:title |
|
|
114 | + params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title) | |
|
115 | 115 | end |
|
116 | 116 | end |
@@ -1,50 +1,50 | |||
|
1 | 1 | require 'test_helper' |
|
2 | 2 | |
|
3 | 3 | class AnnouncementsControllerTest < ActionController::TestCase |
|
4 | 4 | setup do |
|
5 | 5 | @announcement = announcements(:one) |
|
6 | - @request.session[:user_id] = user(:admin).id | |
|
6 | + @request.session[:user_id] = users(:admin).id | |
|
7 | 7 | end |
|
8 | 8 | |
|
9 | 9 | test "should get index" do |
|
10 | 10 | get :index |
|
11 | 11 | assert_response :success |
|
12 | 12 | assert_not_nil assigns(:announcements) |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | test "should get new" do |
|
16 | 16 | get :new |
|
17 | 17 | assert_response :success |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | test "should create announcement" do |
|
21 | 21 | assert_difference('Announcement.count') do |
|
22 | - post :create, announcement: { } | |
|
22 | + post :create, announcement: { author: 'aa',body: 'bb', published: true, frontpage: true, title: 'test'} | |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | test "should show announcement" do |
|
29 | 29 | get :show, id: @announcement |
|
30 | 30 | assert_response :success |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | test "should get edit" do |
|
34 | 34 | get :edit, id: @announcement |
|
35 | 35 | assert_response :success |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | test "should update announcement" do |
|
39 | - patch :update, id: @announcement, announcement: { } | |
|
39 | + patch :update, id: @announcement, announcement: { author: 'aa',body: 'bb', published: true, frontpage: true, title: 'test'} | |
|
40 | 40 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | test "should destroy announcement" do |
|
44 | 44 | assert_difference('Announcement.count', -1) do |
|
45 | 45 | delete :destroy, id: @announcement |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | assert_redirected_to announcements_path |
|
49 | 49 | end |
|
50 | 50 | end |
You need to be logged in to leave comments.
Login now