From 6ab6ef412a7427967b38c4b00c14620582ebdb00 Mon Sep 17 00:00:00 2001 From: eagletmt Date: Mon, 29 Oct 2012 20:05:02 +0900 Subject: [PATCH] Make Apk#revison protected Teachers cannot set revison even if the first creation of tasks. --- CutenServer/app/controllers/tasks_controller.rb | 1 + CutenServer/app/models/apk.rb | 3 ++- CutenServer/app/views/tasks/_form.html.haml | 3 --- CutenServer/test/functional/apks_controller_test.rb | 4 ++-- CutenServer/test/functional/tasks_controller_test.rb | 15 +-------------- 5 files changed, 6 insertions(+), 20 deletions(-) diff --git a/CutenServer/app/controllers/tasks_controller.rb b/CutenServer/app/controllers/tasks_controller.rb index 454d3a8..7dd118d 100644 --- a/CutenServer/app/controllers/tasks_controller.rb +++ b/CutenServer/app/controllers/tasks_controller.rb @@ -43,6 +43,7 @@ class TasksController < ApplicationController @apk = Apk.new params[:apk] uploaded_file = params[:apkfile] && params[:apkfile][:file] @apk.task = @task + @apk.revision = 1 format.html do if @task.lecture.teacher.id == current_teacher.id diff --git a/CutenServer/app/models/apk.rb b/CutenServer/app/models/apk.rb index 091c5df..b0c4b5e 100644 --- a/CutenServer/app/models/apk.rb +++ b/CutenServer/app/models/apk.rb @@ -1,6 +1,7 @@ class Apk < ActiveRecord::Base belongs_to :task - attr_accessible :name, :revision + attr_accessible :name + attr_protected :revision validates_presence_of :task, :name, :revision diff --git a/CutenServer/app/views/tasks/_form.html.haml b/CutenServer/app/views/tasks/_form.html.haml index 5e5f974..7d566b7 100644 --- a/CutenServer/app/views/tasks/_form.html.haml +++ b/CutenServer/app/views/tasks/_form.html.haml @@ -15,9 +15,6 @@ = label :apk, :name = text_field :apk, :name .field - = label :apk, :revision - = text_field :apk, :revision - .field = label :apkfile, :file = file_field :apkfile, :file .actions diff --git a/CutenServer/test/functional/apks_controller_test.rb b/CutenServer/test/functional/apks_controller_test.rb index 7cc3e87..cbb534d 100644 --- a/CutenServer/test/functional/apks_controller_test.rb +++ b/CutenServer/test/functional/apks_controller_test.rb @@ -19,7 +19,7 @@ class ApksControllerTest < ActionController::TestCase test "should NOT create apk" do assert_no_routes do - post :create, apk: { name: @apk.name, revision: @apk.revision } + post :create, apk: { name: @apk.name } end end @@ -30,7 +30,7 @@ class ApksControllerTest < ActionController::TestCase test "should NOT update apk" do assert_no_routes do - put :update, id: @apk, apk: { name: @apk.name, revision: @apk.revision } + put :update, id: @apk, apk: { name: @apk.name } end end diff --git a/CutenServer/test/functional/tasks_controller_test.rb b/CutenServer/test/functional/tasks_controller_test.rb index 3955c09..1f14e0d 100644 --- a/CutenServer/test/functional/tasks_controller_test.rb +++ b/CutenServer/test/functional/tasks_controller_test.rb @@ -104,7 +104,6 @@ class TasksControllerTest < ActionController::TestCase assert_not_nil created_task assert_equal task.name, created_task.name assert_equal apk.name, created_apk.name - assert_equal apk.revision, created_apk.revision assert File.readable?(created_apk.path) assert_equal @lecture.id, created_task.lecture.id end @@ -162,21 +161,9 @@ class TasksControllerTest < ActionController::TestCase end end - test "should reject empty apk revision" do - sign_in @teacher - - task = FactoryGirl.build :task, :lecture => @lecture - apk = FactoryGirl.build :apk, :revision => nil, :task => task - assert_difference('Task.count', 0) do - assert_difference('Apk.count', 0) do - create_apk apk, @apkfile - end - end - end - def create_apk(apk, apkfile) task = apk.task lecture = task.lecture - post :create, :lecture_id => lecture.id, :task => { :name => task.name }, :apk => { :name => apk.name, :revision => apk.revision }, :apkfile => { :file => apkfile } + post :create, :lecture_id => lecture.id, :task => { :name => task.name }, :apk => { :name => apk.name }, :apkfile => { :file => apkfile } end end -- 2.11.0