Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request spec #92

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/controllers/subscriptions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe SubscriptionsController, :type => :controller do
RSpec.describe SubscriptionsController, type: :controller do

context "GET new" do

Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'rails_helper'

RSpec.describe ApplicationHelper, :type => :helper do
RSpec.describe ApplicationHelper, type: :helper do

context "page_title attribute" do

it "has getter and setter" do
helper.page_title = "About Page Title"
expect(helper.page_title).to eq("About Page Title")
Expand Down
12 changes: 6 additions & 6 deletions spec/jobs/headline_scraper_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'rails_helper'

RSpec.describe HeadlineScraperJob, :type => :job do
RSpec.describe HeadlineScraperJob, type: :job do

it "emails headlines scraped from given URL" do

url_to_scrape = "https://eliotsykes.github.io/rspec-rails-examples/"
recipient_email = "[email protected]"

assert_performed_with(
job: HeadlineScraperJob,
args: [{url: url_to_scrape, recipient: recipient_email}],
args: [{url: url_to_scrape, recipient: recipient_email}],
queue: 'default'
) do

Expand All @@ -20,7 +20,7 @@
end

open_email recipient_email, with_subject: "Today's Headlines"


expected_headlines = [
# Original headline edited to prove VCR is serving scraped page.
Expand All @@ -32,7 +32,7 @@
expected_headlines.each do |expected_headline|
expect(current_email).to have_body_text expected_headline
end

end

end
10 changes: 5 additions & 5 deletions spec/mailers/news_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "rails_helper"

RSpec.describe NewsMailer, :type => :mailer do
RSpec.describe NewsMailer, type: :mailer do

describe ".send_headlines(headlines:, to:)" do

it "has expected subject when there are headlines" do
mail = NewsMailer.send_headlines(
headlines: ["Scaremongering Headline: Be Fearful!"],
Expand All @@ -13,7 +13,7 @@
end

[nil, []].each do |no_headlines|

it "has expected subject when there are no headlines '#{no_headlines.inspect}'" do
NewsMailer.send_headlines(headlines: no_headlines, to: "[email protected]")
expect(open_last_email).to have_subject "No Headlines Today :-("
Expand All @@ -32,7 +32,7 @@
end

it "calls the error-sensitive deliver_now!" do

delivery = double
expect(delivery).to receive(:deliver_now!).with(no_args)

Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/subscription_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe SubscriptionMailer, :type => :mailer do
RSpec.describe SubscriptionMailer, type: :mailer do

describe ".send_confirmation_request!(subscription)" do

Expand Down
2 changes: 1 addition & 1 deletion spec/models/subscription_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe Subscription, :type => :model do
RSpec.describe Subscription, type: :model do

context "db" do
context "indexes" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe User, :type => :model do
RSpec.describe User, type: :model do

it { should validate_presence_of :email }
it { should validate_presence_of :password }
Expand Down
29 changes: 29 additions & 0 deletions spec/requests/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "rails_helper"

RSpec.describe "Pages Controller", type: :request do

context "Index request" do

it "redirects to index page" do
get "/"
expect(response).to have_http_status(:success)

expect(response).to render_template(:index)
expect(response.body).to include("Welcome to RSpec Rails Examples")
end

end

context "Share request" do

it "redirect to share page" do
get "/share"
expect(response).to have_http_status(:success)

expect(response).to render_template(:share)
expect(response.body).to include("Share Our Stuff!")
end

end

end
40 changes: 40 additions & 0 deletions spec/requests/subscriptions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "rails_helper"

RSpec.describe "Subscription Controller", type: :request do

context "New request" do

it "returns new subscription page" do
get "/subscriptions/new"
expect(response).to have_http_status(:success)

expect(response).to render_template(:new)
end

end

context "Create request" do
it "returns to pending subscription page" do
params = { subscription: { email: "[email protected]", start_on: "2014-12-31" } }
post "/subscriptions", params

expect(response).to have_http_status(:found)
expect(response).to redirect_to(pending_subscriptions_path)
end
end

context "Confirm request" do

let(:token) { SecureRandom.hex(32) }
let!(:subscription) { create(:subscription, confirmation_token: token) }
let(:today) { Date.today.to_formatted_s(:long_ordinal) }

it "returns to subscription confirmation page" do
get "/subscriptions/#{token}/confirm"

expect(response).to have_http_status(:success)
expect(response.body).to include("Your subscription will start on #{today}, thank you!")
end
end

end
2 changes: 1 addition & 1 deletion spec/routing/subscriptions_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe "routes for Subscriptions", :type => :routing do
RSpec.describe "routes for Subscriptions", type: :routing do

context "confirm_subscription route" do

Expand Down
4 changes: 2 additions & 2 deletions spec/tasks/subscription_tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe "Subscription tasks", :type => :task do
RSpec.describe "Subscription tasks", type: :task do

context "subscription:confirmation_overdue:delete" do

Expand Down Expand Up @@ -34,7 +34,7 @@

def invoke_task
task = Rake::Task["subscription:confirmation_overdue:delete"]
# Ensure task is re-enabled, as rake tasks by default are disabled
# Ensure task is re-enabled, as rake tasks by default are disabled
# after running once within a process http://pivotallabs.com/how-i-test-rake-tasks/
task.reenable
task.invoke
Expand Down