From e98bec8bc672033d02c34788ff8e791bd9e161d2 Mon Sep 17 00:00:00 2001 From: Giovanne Marcelo <gms15@inf.ufpr.br> Date: Thu, 23 Feb 2017 10:49:42 -0300 Subject: [PATCH] add contacts test --- spec/acceptance/contacts_spec.rb | 69 ++++++++++++++++++++++++++++++++ spec/factories/contacts.rb | 7 ++++ 2 files changed, 76 insertions(+) create mode 100644 spec/acceptance/contacts_spec.rb create mode 100644 spec/factories/contacts.rb diff --git a/spec/acceptance/contacts_spec.rb b/spec/acceptance/contacts_spec.rb new file mode 100644 index 000000000..f4d3d737f --- /dev/null +++ b/spec/acceptance/contacts_spec.rb @@ -0,0 +1,69 @@ +require 'acceptance_helpers' + +resource 'Contacts' do + + before { 12.times { create(:contact) } } + + let(:contacts) { Contact.all } + + get '/v1/contacts' do + + example_request 'Getting all contacts' do + expect(status).to eq(200) + end + end + + get '/v1/contacts/:id' do + + let(:id) { contacts.first.id } + + example_request 'Getting a contact' do + expect(status).to eq(200) + end + end + + + post '/v1/contacts' do + + parameter :name, 'The name of the contact', scope: :contact + parameter :link, 'The email of the contact', scope: :contact + parameter :description, 'The message of the contact', scope: :contact + + let(:id) { contacts.first.id } + let(:name) { Faker::Name.name } + let(:email) { Faker::Internet.email } + let(:message) { Faker::Lorem.sentence } + let(:raw_post) { params.to_json } + + example_request 'Create contacts' do + expect(status).to eq(201) + end + end + + put '/v1/contacts/:id' do + + parameter :name, 'The name of the contact', scope: :contact + parameter :link, 'The email of the contact', scope: :contact + parameter :description, 'The message of the contact', scope: :contact + + let(:id) { contacts.first.id } + let(:name) { Faker::Name.name } + let(:email) { Faker::Internet.email } + let(:message) { Faker::Lorem.sentence } + let(:raw_post) { params.to_json } + + example_request 'Updating contacts' do + expect(status).to eq(200) + end + end + + delete '/v1/contacts/:id' do + + let(:id) { contacts.first.id } + + example_request 'Destroy a contact' do + expect(status).to eq(200) + end + end + +end diff --git a/spec/factories/contacts.rb b/spec/factories/contacts.rb new file mode 100644 index 000000000..040d4ba85 --- /dev/null +++ b/spec/factories/contacts.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :contact do |f| + f.name { Faker::Name.name } + f.email { Faker::Internet.email } + f.message { Faker::Lorem.sentence } + end +end -- GitLab