Skip to content
This repository was archived by the owner on Mar 19, 2020. It is now read-only.

Commit c8db4b9

Browse files
author
Yuma Soga
committed
#37 #35 Add Spec for new desgin
commit 71d89ca5730810c5aaf793de41ae430aad45942e Author: Yuma Soga <ysoga19@gmail.com> Date: Sat Jul 7 17:15:05 2018 +0900 Add Spec dor new desgin
1 parent c35e5fa commit c8db4b9

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

spec/models/contact_form_spec.rb

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,81 @@
11
require 'rails_helper'
22

33
RSpec.describe ContactForm, type: :model do
4-
pending "add some examples to (or delete) #{__FILE__}"
4+
describe "#Save Forms" do
5+
6+
let(:contact_form) { ContactForm.new(params) }
7+
8+
let(:params) { { name: name, email: email, subject: subject, body: body } }
9+
10+
before :each do
11+
slack_notifer_client_mock = double('Slack Notifer client')
12+
allow(slack_notifer_client_mock).to receive(:post)
13+
allow(contact_form).to receive(:save).and_return(slack_notifer_client_mock)
14+
end
15+
16+
describe "Validation" do
17+
context "Name が空欄の時" do
18+
let(:name) { }
19+
let(:email) { "ABE@TESTMAIL.COM" }
20+
let(:subject) { "Subject" }
21+
let(:body) { "ABCDEF BODY" }
22+
23+
it "エラーを返すこと" do
24+
Rails.logger.info contact_form
25+
contact_form.invalid?
26+
expect(contact_form.errors[:name]).to be_present
27+
end
28+
end
29+
30+
context "E-mail が空欄の時" do
31+
let(:name) { "ABC NAME" }
32+
let(:email) { }
33+
let(:subject) { "Subject" }
34+
let(:body) { "ABCDEF BODY" }
35+
36+
it "エラーを返すこと" do
37+
Rails.logger.info contact_form
38+
contact_form.invalid?
39+
expect(contact_form.errors[:email]).to be_present
40+
end
41+
end
42+
43+
context "Subject が空欄の時" do
44+
let(:name) { "ABC NAME" }
45+
let(:email) { "ABE@TESTMAIL.COM" }
46+
let(:subject) { }
47+
let(:body) { "ABCDEF BODY" }
48+
49+
it "エラーを返すこと" do
50+
Rails.logger.info contact_form
51+
contact_form.invalid?
52+
expect(contact_form.errors[:subject]).to be_present
53+
end
54+
end
55+
56+
context "Body が空欄の時" do
57+
let(:name) { "ABC NAME" }
58+
let(:email) { "ABE@TESTMAIL.COM" }
59+
let(:subject) { "Subject" }
60+
let(:body) { }
61+
62+
it "エラーを返すこと" do
63+
Rails.logger.info contact_form
64+
contact_form.invalid?
65+
expect(contact_form.errors[:body]).to be_present
66+
end
67+
end
68+
end
69+
70+
context "全ての項目が埋まっている時" do
71+
let(:name) { "ABC NAME" }
72+
let(:email) { "ABE@TESTMAIL.COM" }
73+
let(:subject) { "Subject" }
74+
let(:body) { "ABCDEF BODY" }
75+
76+
it "フォームが正しく送信されること" do
77+
expect{ contact_form.save }.not_to raise_error
78+
end
79+
end
80+
end
581
end

spec/rails_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Prevent database truncation if the environment is production
66
abort("The Rails environment is running in production mode!") if Rails.env.production?
77
require 'rspec/rails'
8+
9+
# Rails.logger = Logger.new(STDOUT)
10+
811
# Add additional requires below this line. Rails is not loaded until this point!
912

1013
# Requires supporting ruby files with custom matchers and macros, etc, in

0 commit comments

Comments
 (0)