Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2015 09:56
Show Gist options
  • Save anonymous/797e5c79acdc33f510ad to your computer and use it in GitHub Desktop.
Save anonymous/797e5c79acdc33f510ad to your computer and use it in GitHub Desktop.
require "rails_helper"
RSpec.describe "Lessons", type: :request do
before { create_user }
it "renders index" do
get api_lessons_path
end
it "returns all lessons" do
FactoryGirl.create(:lesson)
FactoryGirl.create(:lesson)
get api_lessons_path
expect(response.status).to eq 200
body = JSON.parse(response.body)
lesson_titles = body.map {|l| l["title"] }
expect(lesson_titles).to match_array(["foo1", "foo2"])
end
it "returns a lesson" do
lesson = FactoryGirl.create(:lesson)
get api_lesson_path(lesson)
body = JSON.parse(response.body)
expect(body["title"]).to eq "foo3"
end
it "creates a lesson" do
post "/api/lessons", title: "this is a test"
expect(response.status).to eq 201
expect(Lesson.first.title).to eq "this is a test"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment