model层测试完成
This commit is contained in:
commit
51e155dafa
|
@ -57,8 +57,30 @@ class MissionsController < ApplicationController
|
|||
|
||||
def update
|
||||
#Todo
|
||||
id = params[:id]
|
||||
body = request.body.read
|
||||
|
||||
mission = Mission.find(id)
|
||||
mission.name = body[:name]
|
||||
mission.content = body[:content]
|
||||
mission.priority = body[:priority]
|
||||
mission.status = body[:status]
|
||||
mission.deadline = body[:deadline]
|
||||
mission.save!
|
||||
pid = mission.project_id
|
||||
Mission_user.destory_all(:mission_id => id)
|
||||
body[:users].each do |i|
|
||||
uid = User.where(:email => i).id
|
||||
mu = Mission_user.new
|
||||
mu.mission_id = id
|
||||
mu.user_id = uid
|
||||
mu.save!
|
||||
note = Note.new
|
||||
note.project_id = pid
|
||||
note.user_id = uid
|
||||
note.type = 3
|
||||
note.content = "任务信息发生了变化"
|
||||
note.save!
|
||||
end
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,31 @@ class NotesController < ApplicationController
|
|||
|
||||
def getNotesList
|
||||
#Todo
|
||||
|
||||
pid = params[:project_id]
|
||||
uid = session[:user_id]
|
||||
note = {}
|
||||
Note.where(:user_id => uid).where(:project_id => pid).each do |i|
|
||||
date = i.created_at.to_date.to_s
|
||||
if not note[date] then
|
||||
note[date] = []
|
||||
end
|
||||
note[:date] += [{
|
||||
:content => i.content,
|
||||
:time => i.created_at.to_time,
|
||||
:type => i.type
|
||||
}]
|
||||
end
|
||||
data = []
|
||||
note.each do |date, list|
|
||||
data += [{
|
||||
:time => date,
|
||||
:notes => list
|
||||
}]
|
||||
end
|
||||
render :json => {
|
||||
:code => 0,
|
||||
:data => data
|
||||
}
|
||||
end
|
||||
|
||||
end
|
|
@ -8,9 +8,9 @@ class ProjectsController < ApplicationController
|
|||
def index
|
||||
#Todo
|
||||
uid = session[:user_id]
|
||||
pid = Project_user.find(uid)
|
||||
pid = Projects_user.find_by(project_id: uid)
|
||||
mc = Mission.where(:project_id => pid).size
|
||||
uc = Project_user.where(:project_id => pid).size
|
||||
uc = Projects_user.where(:project_id => pid).size
|
||||
sc = Share.where(:project_id => pid).size
|
||||
data = []
|
||||
Project.find(pid) do |i|
|
||||
|
@ -46,10 +46,19 @@ class ProjectsController < ApplicationController
|
|||
def addUsers
|
||||
#Todo
|
||||
body = request.body.read
|
||||
uid = body[:user_id].to_i
|
||||
pid = body[:project_id].to_i
|
||||
pu = Project_user.new()
|
||||
pu.project_id = body[:project_id]
|
||||
#pu.user_id = body[:user_id]
|
||||
pu.project_id = pid
|
||||
pu.user_id = uid
|
||||
pu.save!
|
||||
note = Note.new
|
||||
note.user_id = uid
|
||||
note.project_id = pid
|
||||
note.type = 2
|
||||
note.content = User.find(uid).name + "邀请您进入项目" +
|
||||
Project.find(pid).name
|
||||
note.save!
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
|
@ -58,8 +67,8 @@ class ProjectsController < ApplicationController
|
|||
def detail
|
||||
#Todo
|
||||
pid = params[:id]
|
||||
project = Project.find(pid)
|
||||
uid = Project_user.where(:project_id => pid)
|
||||
project = Project.find_by(id: pid)
|
||||
uid = Projects_user.where(:project_id => pid)
|
||||
users = []
|
||||
Users.find(uid).each do |i|
|
||||
users += [{
|
||||
|
|
|
@ -7,11 +7,22 @@ class SharesController < ApplicationController
|
|||
def create
|
||||
#Todo
|
||||
body = request.body.read
|
||||
uid = session[:user_id].to_i
|
||||
pid = body[:project_id].to_i
|
||||
put = Share.new()
|
||||
put.content = body[:content]
|
||||
put.project_id = body[:project_id]
|
||||
put.user_id = session[:user_id]
|
||||
put.project_id = pid
|
||||
put.user_id = uid
|
||||
put.save!
|
||||
content = User.find(uid).name + "分享了一些事"
|
||||
Project_user.where(:project_id => pid).each do |tuid|
|
||||
note = Note.new
|
||||
note.user_id = tuid
|
||||
note.project_id = pid
|
||||
note.type = 1
|
||||
note.content = content
|
||||
note.save!
|
||||
end
|
||||
render :json => {:code => 0}
|
||||
end
|
||||
|
||||
|
|
|
@ -4,11 +4,14 @@ class Note < ActiveRecord:: Base
|
|||
|
||||
validates :content, presence: true
|
||||
validates :user_id, presence: true
|
||||
validates :project_id, presence: true
|
||||
validates :category, presence: true
|
||||
|
||||
validate :note_has_atleast_one_character
|
||||
validate :note_category_should_among_valid_values
|
||||
validate :user_exist, on: :create
|
||||
validate :project_exist, on: :create
|
||||
|
||||
|
||||
private
|
||||
def note_has_atleast_one_character
|
||||
|
@ -34,6 +37,14 @@ class Note < ActiveRecord:: Base
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def project_exist
|
||||
|
||||
project = Project.find_by(id: project_id)
|
||||
if project == nil
|
||||
errors[:project] = "project should be exist"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -62,4 +62,17 @@ Rails.application.routes.draw do
|
|||
post 'sessions' => 'sessions#create'
|
||||
delete 'session' => 'sessions#destroy'
|
||||
get 'session' => 'sessions#show'
|
||||
|
||||
post 'shares' => 'shares#create'
|
||||
get 'shares' => 'share#getShareList'
|
||||
|
||||
get 'projects' => 'projects#index'
|
||||
post 'projects' => 'projects#create'
|
||||
post 'projects/users' => 'projects#addUsers'
|
||||
get 'projects/detail' => 'projects#detail'
|
||||
|
||||
get 'missions/project/status' => 'missions#getlist'
|
||||
get 'missions/detail' => 'missions#detail'
|
||||
patch 'missions/detail' => 'missions#update'
|
||||
post 'missions/comments' => 'missions#commentPublish'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddProjectIdToNotes < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :notes, :project_id, :integer
|
||||
end
|
||||
end
|
|
@ -45,6 +45,7 @@ ActiveRecord::Schema.define(version: 20161229084919) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "category"
|
||||
t.integer "project_id"
|
||||
end
|
||||
|
||||
add_index "notes", ["user_id"], name: "index_notes_on_user_id"
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
||||
# Mayor.create(name: 'Emanuel', city: cities.first)
|
||||
users = [
|
||||
{:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"}
|
||||
{:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"},
|
||||
{:name => '陈翊', :password => '123456', :email => '1085730215@qq.com', :phone => '18269771988', :created_at => "2016/12/28", :updated_at => "2016/12/27"}
|
||||
]
|
||||
|
||||
users.each do |user|
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
<nav class="navbar navbar-static-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a href="../../index2.html" class="navbar-brand"><b>Ambition</a>
|
||||
<a href="index.html" class="navbar-brand"><b>Ambition</a>
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
|
||||
<i class="fa fa-bars"></i>
|
||||
</button>
|
||||
|
|
|
@ -43,42 +43,15 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<!-- /.col -->
|
||||
<div class="col-md-2 col-md-offset-9">
|
||||
<div class="col-md-3 col-md-offset-9">
|
||||
<button id="login" class="btn btn-success">登录</button>
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<!--</form>-->
|
||||
<!-- 忘记密码 -->
|
||||
<a href="#" data-toggle="modal" data-target="#myModal">忘记密码</a>
|
||||
<a href="register.html">注册</a>
|
||||
<br/>
|
||||
<!-- 模态框(Modal) -->
|
||||
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
|
||||
×
|
||||
</button>
|
||||
<h4 class="modal-title" id="myModalLabel">
|
||||
忘记密码
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Please send a mail to lucio.yang@qq.com
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-success" data-dismiss="modal">
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal -->
|
||||
|
||||
</div>
|
||||
<!-- /.modal fade -->
|
||||
</div>
|
||||
<!-- /.login-box-body -->
|
||||
|
||||
|
|
|
@ -77,94 +77,30 @@
|
|||
</div>
|
||||
<!-- col -->
|
||||
<div class="col-lg-8 col-lg-offset-2">
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<div id="cy_container" class="row">
|
||||
<div id="cy_template" class="col-lg-4" style="display:none;">
|
||||
<div class="box box-widget widget-user">
|
||||
<!-- Add the bg color to the header using any of the bg-* classes -->
|
||||
<div class="widget-user-header bg-yellow">
|
||||
<div id="cy_template_bg" class="widget-user-header bg-yellow">
|
||||
<!-- /.widget-user-image -->
|
||||
<h3 class="widget-user-username">网吧五连座</h3>
|
||||
<h5 class="widget-user-desc">Ruby开发项目</h5>
|
||||
<h3 id="cy_template_name" class="widget-user-username">网吧五连座</h3>
|
||||
<h5 id="cy_template_content" class="widget-user-desc">Ruby开发项目</h5>
|
||||
<a class="btn btn-default pull-right project-enter" href="../index.html">
|
||||
<i class="fa fa-sign-in"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="box-footer no-padding">
|
||||
<ul class="nav nav-stacked">
|
||||
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
|
||||
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
|
||||
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
|
||||
<li><a href="#">任务数 <span id="cy_template_mission_count" class="pull-right badge bg-blue">31</span></a></li>
|
||||
<li><a href="#">参与人数 <span id="cy_template_users_count" class="pull-right badge bg-aqua">5</span></a></li>
|
||||
<li><a href="#">通知数 <span id="cy_template_shares_count" class="pull-right badge bg-green">12</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.widget-user -->
|
||||
</div>
|
||||
<!-- col -->
|
||||
<div class="col-lg-4">
|
||||
<div class="box box-widget widget-user">
|
||||
<!-- Add the bg color to the header using any of the bg-* classes -->
|
||||
<div class="widget-user-header bg-aqua">
|
||||
<!-- /.widget-user-image -->
|
||||
<h3 class="widget-user-username">网吧五连座</h3>
|
||||
<h5 class="widget-user-desc">Ruby开发项目</h5>
|
||||
<a class="btn btn-default pull-right project-enter" href="../index.html">
|
||||
<i class="fa fa-sign-in"></i>进入
|
||||
</a>
|
||||
</div>
|
||||
<div class="box-footer no-padding">
|
||||
<ul class="nav nav-stacked">
|
||||
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
|
||||
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
|
||||
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.widget-user -->
|
||||
</div>
|
||||
<!-- col -->
|
||||
<div class="col-lg-4">
|
||||
<div class="box box-widget widget-user">
|
||||
<!-- Add the bg color to the header using any of the bg-* classes -->
|
||||
<div class="widget-user-header bg-blue">
|
||||
<!-- /.widget-user-image -->
|
||||
<h3 class="widget-user-username">网吧五连座</h3>
|
||||
<h5 class="widget-user-desc">Ruby开发项目</h5>
|
||||
<a class="btn btn-default pull-right project-enter">
|
||||
<i class="fa fa-sign-in"></i>进入
|
||||
</a>
|
||||
</div>
|
||||
<div class="box-footer no-padding">
|
||||
<ul class="nav nav-stacked">
|
||||
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
|
||||
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
|
||||
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.widget-user -->
|
||||
</div>
|
||||
<!-- col -->
|
||||
<div class="col-lg-4">
|
||||
<div class="box box-widget widget-user">
|
||||
<!-- Add the bg color to the header using any of the bg-* classes -->
|
||||
<div class="widget-user-header bg-purple">
|
||||
<!-- /.widget-user-image -->
|
||||
<h3 class="widget-user-username">网吧五连座</h3>
|
||||
<h5 class="widget-user-desc">Ruby开发项目</h5>
|
||||
<a class="btn btn-default pull-right project-enter">
|
||||
<i class="fa fa-sign-in"></i>进入
|
||||
</a>
|
||||
</div>
|
||||
<div class="box-footer no-padding">
|
||||
<ul class="nav nav-stacked">
|
||||
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
|
||||
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
|
||||
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.widget-user -->
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4" style="height:242px;width:252px;margin-left:15px;background-color:white">
|
||||
|
||||
<!-- Add the bg color to the header using any of the bg-* classes -->
|
||||
|
@ -205,7 +141,7 @@
|
|||
</div><!-- /.box-body -->
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div id="creat_project" class="modal-footer">
|
||||
<button type="button" class="btn btn-primary">
|
||||
创建
|
||||
</button>
|
||||
|
@ -238,6 +174,58 @@
|
|||
<script src="../dist/js/app.min.js"></script>
|
||||
<!-- AdminLTE for demo purposes -->
|
||||
<script src="../dist/js/demo.js"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
htmlobj=$.ajax(
|
||||
{
|
||||
type:"GET",
|
||||
dataType:"json",
|
||||
url:"/projects.json",
|
||||
statusCode: {
|
||||
200: function() {// 请求成功
|
||||
var bg_color = ["bg-yellow","bg-blue","bg-purple","bg-red"];
|
||||
var jstr = htmlobj.responseText;
|
||||
var robj = eval('('+jstr+')');
|
||||
|
||||
if(robj["code"]==0){
|
||||
var data = robj["data"];
|
||||
for(var i=data.length-1;i>=0;--i){
|
||||
var template = $("#cy_template");
|
||||
var tp = template.clone("true");
|
||||
tp.find("#cy_template_name").html(data[i]["name"]);
|
||||
tp.find("#cy_template_content").html(data[i]["content"]);
|
||||
tp.find("#cy_template_mission_count").html(data[i]["mission_count"]);
|
||||
tp.find("#cy_template_users_count").html(data[i]["users_count"]);
|
||||
tp.find("#cy_template_shares_count").html(data[i]["shares_count"]);
|
||||
|
||||
tp.find("#cy_template_name").attr("id","cy_name_"+i);
|
||||
tp.find("#cy_template_content").attr("id","cy_content_"+i);
|
||||
tp.find("#cy_template_mission_count").attr("id","cy_mission_count_"+i);
|
||||
tp.find("#cy_template_users_count").attr("id","cy_users_count_"+i);
|
||||
tp.find("#cy_template_shares_count").attr("id","cy_shares_count_"+i);
|
||||
|
||||
tp.find("#cy_template_bg").attr("class","widget-user-header "+bg_color[Math.floor(Math.random()*4)]);
|
||||
tp.find("#cy_template_bg").attr("id","cy_bg_"+i);
|
||||
|
||||
|
||||
tp.attr("id","cy_project_"+i);
|
||||
|
||||
tp.css("display","block");
|
||||
|
||||
$("#cy_container").prepend(tp);
|
||||
}
|
||||
}
|
||||
else{
|
||||
//todo
|
||||
}
|
||||
},
|
||||
401:function(){// 未授权
|
||||
alert("用户名或密码错误!");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,116 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Ambition-敏捷开发项目管理工具</title>
|
||||
<!-- Tell the browser to be responsive to screen width -->
|
||||
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
|
||||
<!-- Bootstrap 3.3.5 -->
|
||||
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
|
||||
<!-- Theme style -->
|
||||
<link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
|
||||
|
||||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body class="hold-transition login-page">
|
||||
<div class="login-box">
|
||||
<div class="row"> </div>
|
||||
<div class="login-logo">
|
||||
<span class="logo-lg"><b>Ambition</b></span>
|
||||
</div>
|
||||
<!-- /.logo -->
|
||||
<div class="register-box-body">
|
||||
<p class="login-box-msg">请注册</p>
|
||||
<!--<form action="../../index.html" method="post">-->
|
||||
<div class="form-group has-feedback">
|
||||
<input id="name" type="text" class="form-control" placeholder="昵称">
|
||||
<span class="glyphicon glyphicon-user form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<input id="email" type="email" class="form-control" placeholder="邮箱">
|
||||
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<input id="phone" type="phone" class="form-control" placeholder="手机">
|
||||
<span class="glyphicon glyphicon glyphicon-phone form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<input id="pwd1" type="password" class="form-control" placeholder="密码">
|
||||
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<input id="pwd2" type="password" class="form-control" placeholder="重复密码">
|
||||
<span class="glyphicon glyphicon-log-in form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-md-offset-9">
|
||||
<button id="register" class="btn btn-info">注册</button>
|
||||
</div>
|
||||
</div>
|
||||
<!--</form>-->
|
||||
</div><!-- /.form-box -->
|
||||
</div><!-- /.register-box -->
|
||||
|
||||
</div>
|
||||
<!-- /.register-box -->
|
||||
|
||||
<!-- jQuery 2.1.4 -->
|
||||
<script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
|
||||
<!-- Bootstrap 3.3.5 -->
|
||||
<script src="../bootstrap/js/bootstrap.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("#register").click(function(){
|
||||
var name=$("#name").val();
|
||||
var email=$("#email").val();
|
||||
var phone=$("#phone").val();
|
||||
var pwd1=$("#pwd1").val();
|
||||
var pwd2=$("#pwd2").val();
|
||||
if( name.length>0 && email.length>0 && phone.length>0 && pwd1.length>0 && pwd2.length>0 ){
|
||||
if( pwd1!=pwd2 ){
|
||||
alert("两次密码输入不相同!");
|
||||
}else{
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url:"/users.json",
|
||||
data: {
|
||||
"user[name]":name,
|
||||
"user[email]":email,
|
||||
"user[phone]":phone,
|
||||
"user[password]":pwd1
|
||||
},
|
||||
statusCode: {
|
||||
201: function() {// 请求成功
|
||||
alert("注册成功!");
|
||||
window.location.href="login.html";
|
||||
},
|
||||
422:function(){
|
||||
alert("输入不符合要求,请重新输入!");
|
||||
},
|
||||
401:function(){// 未授权
|
||||
alert("用户名或密码错误!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else{
|
||||
alert("请输入完整!");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -259,6 +259,25 @@
|
|||
<!-- AdminLTE for demo purposes -->
|
||||
<script src="../dist/js/demo.js"></script>
|
||||
<!-- date select and query -->
|
||||
<script>
|
||||
//alert("111");
|
||||
$(document).ready(function(){
|
||||
$.ajax({
|
||||
type: "get",
|
||||
dataType: "json",
|
||||
url:"/shares.json",
|
||||
statusCode: {
|
||||
200: function(data) {// 请求成功
|
||||
alert(data);
|
||||
},
|
||||
401:function(){// 未授权
|
||||
alert("未登录!");
|
||||
window.location.href="pages/login.html";
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -8,7 +8,13 @@ RSpec.describe Note , type: :model do
|
|||
user = User.new(params)
|
||||
user.save
|
||||
|
||||
params = {content: "note content",user_id: user.id,category: 1}
|
||||
params = {name: "project_1",content: "project content"}
|
||||
project = Project.new(params)
|
||||
project.users << user
|
||||
project.save
|
||||
expect(project).to be_valid
|
||||
|
||||
params = {content: "note content",user_id: user.id,project_id: project.id,category: 1}
|
||||
note = Note.new(params)
|
||||
note.save
|
||||
expect(note).to be_valid
|
||||
|
@ -40,5 +46,45 @@ RSpec.describe Note , type: :model do
|
|||
expect(note).to_not be_valid
|
||||
|
||||
end
|
||||
|
||||
it "notes user should be exist" do
|
||||
|
||||
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
|
||||
user = User.new(params)
|
||||
user.save
|
||||
|
||||
params = {name: "project_1",content: "project content"}
|
||||
project = Project.new(params)
|
||||
project.users << user
|
||||
project.save
|
||||
expect(project).to be_valid
|
||||
|
||||
params = {content: "note content",user_id: user.id,project_id: 5,category: 1}
|
||||
note = Note.new(params)
|
||||
note.save
|
||||
expect(note).to_not be_valid
|
||||
expect(note.errors[:project].size).to eq(1)
|
||||
expect(Note.find_by(project_id: 5)).to eq(nil)
|
||||
end
|
||||
|
||||
it "notes project should be exist" do
|
||||
|
||||
params = {name: "jaxon",email: "370403444@qq.com",password_digest: "123456",phone: "15652336366"}
|
||||
user = User.new(params)
|
||||
user.save
|
||||
|
||||
params = {name: "project_1",content: "project content"}
|
||||
project = Project.new(params)
|
||||
project.users << user
|
||||
project.save
|
||||
expect(project).to be_valid
|
||||
|
||||
params = {content: "note content",user_id: 5,project_id: project.id,category: 1}
|
||||
note = Note.new(params)
|
||||
note.save
|
||||
expect(note).to_not be_valid
|
||||
expect(note.errors[:user].size).to eq(1)
|
||||
expect(Note.find_by(user_id: 5)).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue