controllers

This commit is contained in:
HuJiaxuan 2016-12-27 12:15:05 +00:00
parent 1b15e08a97
commit 4748bd0d92
16 changed files with 309 additions and 52 deletions

View File

@ -1,6 +1,5 @@
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record

View File

@ -0,0 +1,34 @@
class MissionsController < ApplicationController
before_action :authenticate
#获取当前项目某状态的任务列表
def getlist
#Todo
end
#获取任务详细信息
def detail
#Todo
end
#修改任务信息
def update
#Todo
end
#当前用户发表评论
def commentPublish
#Todo
end
end

View File

@ -0,0 +1,12 @@
class NotesController < ApplicationController
before_action :authenticate
#获取用户当前的通知列表
def getNotesList
#Todo
end
end

View File

@ -0,0 +1,36 @@
class ProjectsController < ApplicationController
before_action :authenticate
#获取我的项目列表user_id保存在session中.
def index
#Todo
end
#创建项目
def create
#Todo
end
#项目添加用户
def addUsers
#Todo
end
#项目详情
def detail
#Todo
end
end

View File

@ -0,0 +1,19 @@
class SharesController < ApplicationController
before_action :authenticate
#当前用户创建分享
def create
#Todo
end
#获取项目的分享列表
def getShareList
#Todo
end
end

View File

@ -1,6 +1,30 @@
class Comment << ActiveRecord:: Base
class Comment < ActiveRecord:: Base
belongs_to :mission
validates :content, presence: true
validates :mission_id, presence: true
private
def comment_has_atleast_one_character
tmp = content.strip
if tmp.length < 1
errors[:content] = 'content should has at least one character'
end
end
# mission 是否存在的验证将放在controller中进行
# def mission_id_should_be_exist
# @mission = Mission.find(:mission_id)
# if @mission == nil
# errors[:mission_id] = "mission is not exist"
# end
# end
end

View File

@ -1,6 +1,33 @@
class Mission < ActiveRecord:: Base
has_many :comments, dependent: :destory
has_many :comments
validates :name, presence: true
validates :deadline, presence: true
validates :priority, presence: true
validates :status, presence: true
validates :content, presence: true
validate :priority_is_among_valid_values
validate :status_is_among_valid_values
private
def priority_is_among_valid_values
if priority != 1 and priority != 2 and priority != 3
errors[:priority] = "priority is not among valid values"
end
end
def status_is_among_valid_values
values = ["未开始","进行中","已完成","已测试"]
if !values.include?(status)
errors[:status] = "status is not among valid values"
end
end
end

View File

@ -2,5 +2,7 @@ class Mission_user <ActiveRecord:: Base
validates :mission_id, presence: true, uniqueness: true
validates :user_id, presence: true
end

View File

@ -1,7 +1,19 @@
class Note < ActiveRecord: Base
class Note < ActiveRecord:: Base
belongs_to :user
validates :content, presence: true
validates :user_id, presence: true
validates :type, presence: true
validate :note_has_atleast_one_character
private
def note_has_atleast_one_character
tmp = content.strip
if tmp.length < 1
errors[:content] = "note content should has at least one character"
end
end
end

View File

@ -1,4 +1,4 @@
class Projects_user <ActiveRecord: Base
class Projects_user < ActiveRecord:: Base
validates :project_id, presence: true
validates :user_id, presence: true

View File

@ -1,3 +1,16 @@
class Share < ActiveRecord::Base
validates :content, presence: true
validate :share_has_atleast_one_character
private
def share_has_atleast_one_character
tmp = content.strip
if tmp.length < 1
errors[:content] = "share content should has at least one character"
end
end
end

View File

@ -6,14 +6,15 @@ FactoryGirl.define do
sequence(:content){ |n| "This is comment content#{n}"}
factory :comment_content_null do
content ""
factory :comment_content_nil do
content nil
end
factory :comment_conten_allspace do
factory :comment_content_allspace do
content " "
end
end
end

View File

@ -1,17 +1,42 @@
require 'faker'
FactoryGirl.define do
factory :mission do
name { Faker::Name.title }
deadline "2016-10-17 10:00:00"
priority {Faker::Number.between(1, 3)}
sequence(:name){ |n| "Mission name #{n}" }
sequence(:content){ |n| "Mission #{n}" }
status "已完成"
after(:build) do |mission|
3.times { mission.users << FactoryGirl.create(:user_with_sequence_number) }
priority 1
deadline "2016-10-17 10:00:00"
factory :no_content_mission do
content nil
end
factory :mission_name_length_gt_20 do
name { Faker::Internet.password(51, 51) }
factory :no_deadline_mission do
deadline nil
end
factory :no_status_mission do
status nil
end
factory :no_priority_mission do
priority nil
end
factory :priority_not_among_valid_values do
priority 5
end
factory :status_not_among_valid_values do
status "不存在"
end
end
end

View File

@ -1,15 +1,28 @@
require 'rails_helper'
RSpec.describe Comment , type: model do
RSpec.describe Comment , type: :model do
it 'has a valid factory' do
expect(build(:comment)).to be_valid
it 'has a valid comment' do
params = {content:"good job",mission_id:123}
expect(Comment.new(params)).to be_valid
end
describe "comment content test" do
it 'the content should not be empty' do
expect(build(:comment, content: nil)).not_to be_valid
end
it "content should not be empty" do
params = {content: nil,mission_id: 123}
expect(Comment.new(params)).to_not be_valid
end
it "mission_id should not be empty" do
params = {content:"good job", mission_id: nil}
expect(Comment.new(params)).to_not be_valid
end
it "content should has at least one word " do
comment_with_allspace = build(:comment_content_allspace)
comment_with_allspace.validate
expect(comment_with_allspace.errors[:content].size).to eq(1)
end
end

View File

@ -1,32 +1,73 @@
require 'rails_helper'
RSpec.describe Mission, type: :model do
it 'has a valid factory' do
expect(build(:project)).to be_valid
end
describe 'users test' do
it 'has at least on user' do
mission_with_no_user = build(:mission)
mission_with_no_user.users = []
mission_with_no_user.valid?
expect(mission_with_no_user.errors[:users].size).to eq(1)
RSpec.describe Mission , type: :model do
it 'has a valid mission' do
params = {name: "mission1",content: "mission content",deadline:"2016-10-17 10:00:00",priority:1,status:"进行中"}
mission = Mission.new(params)
mission.validate
expect(mission).to be_valid
end
end
describe 'name test' do
it 'does not allow absence of name' do
expect(build(:mission, name: nil)).to_not be_valid
it 'content should not be nil' do
expect(build(:no_content_mission)).to_not be_valid
end
it 'length of name in [1,20]' do
expect(build(:mission_name_length_gt_20)).to_not be_valid
it 'deadline should not be nil' do
expect(build(:no_deadline_mission)).to_not be_valid
end
# it 'does not allow duplicate name' do
# create(:mission, name: 'mission1')
# expect(build(:mission, name: 'mission1')).to_not be_valid
# end
end
it 'status should not be nil' do
expect(build(:no_status_mission)).to_not be_valid
end
it 'priority should not be nil' do
expect(build(:no_priority_mission)).to_not be_valid
end
it 'priority is not among valid values' do
mission = build(:priority_not_among_valid_values)
mission.validate
expect(mission.errors[:priority].size).to eq(1)
end
it 'status is not among valid values' do
mission = build(:status_not_among_valid_values)
mission.validate
expect(mission.errors[:status].size).to eq(1)
end
end
# require 'rails_helper'
# RSpec.describe Mission, type: :model do
# it 'has a valid mission' do
# expect(build(:project)).to be_valid
# end
# describe 'users test' do
# it 'has at least on user' do
# mission_with_no_user = build(:mission)
# mission_with_no_user.users = []
# mission_with_no_user.valid?
# expect(mission_with_no_user.errors[:users].size).to eq(1)
# end
# end
# describe 'name test' do
# it 'does not allow absence of name' do
# expect(build(:mission, name: nil)).to_not be_valid
# end
# it 'length of name in [1,20]' do
# expect(build(:mission_name_length_gt_20)).to_not be_valid
# end
# end
# end

View File

@ -49,7 +49,6 @@ RSpec.configure do |config|
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via: