From 9c099399395cf5f78785a294440c4baca3f7d7d7 Mon Sep 17 00:00:00 2001 From: HuJiaxuan Date: Mon, 26 Dec 2016 02:19:56 +0000 Subject: [PATCH] base version --- app/models/comment.rb | 3 -- app/models/mission.rb | 4 --- app/models/note.rb | 3 -- spec/controllers/comments_controller_spec.rb | 0 spec/controllers/missions_controller_spec.rb | 0 spec/factories/comments.rb | 19 ++++++++++++ spec/factories/missions.rb | 17 +++++++++++ spec/models/comment_spec.rb | 15 +++++++++ spec/models/mission_spec.rb | 32 ++++++++++++++++++++ 9 files changed, 83 insertions(+), 10 deletions(-) delete mode 100644 app/models/comment.rb delete mode 100644 app/models/mission.rb delete mode 100644 app/models/note.rb create mode 100644 spec/controllers/comments_controller_spec.rb create mode 100644 spec/controllers/missions_controller_spec.rb create mode 100644 spec/factories/comments.rb create mode 100644 spec/factories/missions.rb create mode 100644 spec/models/comment_spec.rb create mode 100644 spec/models/mission_spec.rb diff --git a/app/models/comment.rb b/app/models/comment.rb deleted file mode 100644 index a8c1dc4..0000000 --- a/app/models/comment.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Comment < ActiveRecord::Base - belongs_to :mission -end diff --git a/app/models/mission.rb b/app/models/mission.rb deleted file mode 100644 index c214e82..0000000 --- a/app/models/mission.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Mission < ActiveRecord::Base - has_and_belongs_to_many :users - has_many :comments -end diff --git a/app/models/note.rb b/app/models/note.rb deleted file mode 100644 index daccdaf..0000000 --- a/app/models/note.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Note < ActiveRecord::Base - belongs_to :user -end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/controllers/missions_controller_spec.rb b/spec/controllers/missions_controller_spec.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb new file mode 100644 index 0000000..8328a76 --- /dev/null +++ b/spec/factories/comments.rb @@ -0,0 +1,19 @@ +require 'faker' +FactoryGirl.define do + factory :comment do + + + sequence(:content){ |n| "This is comment content#{n}"} + + + factory :comment_content_null do + content "" + end + + factory :comment_conten_allspace do + content " " + end + + + end +end diff --git a/spec/factories/missions.rb b/spec/factories/missions.rb new file mode 100644 index 0000000..bc1951a --- /dev/null +++ b/spec/factories/missions.rb @@ -0,0 +1,17 @@ +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)} + status "已完成" + + after(:build) do |mission| + 3.times { mission.users << FactoryGirl.create(:user_with_sequence_number) } + end + factory :mission_name_length_gt_20 do + name { Faker::Internet.password(51, 51) } + end + end +end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb new file mode 100644 index 0000000..7b089cb --- /dev/null +++ b/spec/models/comment_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe Comment , type: model do + + it 'has a valid factory' do + expect(build(:comment)).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 + end + +end \ No newline at end of file diff --git a/spec/models/mission_spec.rb b/spec/models/mission_spec.rb new file mode 100644 index 0000000..70efddb --- /dev/null +++ b/spec/models/mission_spec.rb @@ -0,0 +1,32 @@ +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) + 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 + + # it 'does not allow duplicate name' do + # create(:mission, name: 'mission1') + # expect(build(:mission, name: 'mission1')).to_not be_valid + # end + end +end