Last active
October 28, 2020 23:58
-
-
Save minhquang4334/fd52f09e1fb49c305dcebb82248b0d57 to your computer and use it in GitHub Desktop.
EveryDay-Rails 第7章 - Request Spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe "Event", type: :request do | |
include_context "when login required" | |
describe "GET Event Request" do | |
it "works! with show request" do | |
event = create(:event) | |
get event_path(event.id) | |
expect(response).to have_http_status(200) | |
end | |
it "works! with edit request" do | |
event = create(:event, owner: user) | |
get edit_event_path(event.id) | |
expect(response).to have_http_status(200) | |
end | |
end | |
describe "POST Event Request" do | |
it "works! delete own event" do | |
event = create(:event, owner: user) | |
expect { | |
delete event_url(event) | |
}.to change{user.created_events.count}.by(-1) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe "Status", type: :request do | |
describe "GET /status" do | |
it "works! with get status" do | |
get "/status" | |
expect(response).to have_http_status(200) | |
status = JSON.parse(response.body) | |
expect(status).to eq({ "status" => "ok" }) | |
expect(response.media_type).to eq("application/json") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe "Welcome", type: :request do | |
describe "GET / : Welcome Page" do | |
it "works! with Welcome Page" do | |
get root_path | |
expect(response).to have_http_status(200) | |
end | |
end | |
describe "GET / search event" do | |
before do | |
@event_search_form = { | |
keyword: "", | |
start_at: Time.zone.now | |
} | |
end | |
it "search OK with results" do | |
event = create(:event, name: "Classi Fan Meeting") | |
get root_path, params: { | |
@event_search_form["keyword"] => "Classi", | |
@event_search_form["start_at"] => Time.zone.now | |
} | |
expect(response).to have_http_status(200) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment