Skip to content

Instantly share code, notes, and snippets.

test “Successful login” do
user = User.create!(name: "name", password: "password")
visit root_path
click_on "Get started"
fill_in :name, with: "name"
fill_in :password, with: "password"
click_on "Log in"
assert_text "Welcome back!"
<!-- layouts/application.html.erb -->
<div data-controller="modal">
<%= link_to "Get Started", new_authentication_path, data-action="modal#show" %>
<div data-target="modal.dialog"></div>
</div>
class AuthenticationsController < ApplicationController
def new
@authentication = Authentication.new
track_login_start
end
end
<!-- layouts/application.html.erb -->
<%= link_to "Get Started", new_authentication_path %>
<!-- layouts/application.html.erb -->
<div data-controller="modal">
<%= link_to "Get Started", "#", data-action="modal#show" %>
<div data-target="modal.dialog" style="display: none;">
<% form_for authentications_path do |f| %>
<!-- Form markup -->
<% end %>
</div>
</div>
scenario "Viewing events" do
visitor = User.create!(name: "Visitor Name")
visitor.recipes.create!(title: "Featured Visitor Recipe")
- Recipe.create!(title: "Visited Recipe")
+ visited_recipe = Recipe.create!(title: "Visited Recipe")
+ Event.create!(visitor: visitor, recipe: visited_recipe, action: :liked)
@@ Model @@
-class Event
- def visitor
- User.last
- end
-
- def action
- "liked"
- end
-
class CreateEvents < ActiveRecord::Migration[5.2]
def change
create_table :events do |t|
t.references :visitor, null: false
t.references :recipe, null: false
t.integer :action, null: false
t.timestamps
end
end
end
scenario "Viewing events" do
+ visitor = User.create!(name: "Visitor Name")
+ visitor.recipes.create!(title: "Featured Visitor Recipe")
+ Recipe.create!(title: "Visited Recipe")
+
visit events_path
- expect(page).to have_text "Grilled aubergines"
+ expect(page).to have_text "Visitor Name"
+ expect(page).to have_text "Featured Visitor Recipe"
scenario "Viewing events" do
+ visitor = User.create!(name: "Visitor Name")
+ visitor.recipes.create!(title: "Featured Visitor Recipe")
+ Recipe.create!(title: "Visited Recipe")
+
visit events_path
- expect(page).to have_text "Grilled aubergines"
+ expect(page).to have_text "Visitor Name"
+ expect(page).to have_text "Featured Visitor Recipe"