-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert to i18n and add page objects
- Loading branch information
1 parent
ca1bb69
commit 2fa4a82
Showing
10 changed files
with
81 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<%= link_to "Create todo", new_todo_path %> | ||
<%= link_to t(".create_todo"), new_todo_path %> | ||
|
||
<ul class="todos"> | ||
<% @todos.each do |todo| %> | ||
<li class="<%= todo.complete? ? "completed" : "" %>"> | ||
<%= todo.title %> | ||
<%= button_to "Mark complete", todo_completion_path(todo) %> | ||
<%= button_to t(".mark_complete"), todo_completion_path(todo) %> | ||
</li> | ||
<% end %> | ||
</ul> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<%= form_for @todo do |form| %> | ||
<%= form.label :title %> | ||
<%= form.text_field :title %> | ||
<%= form.submit "Submit" %> | ||
<%= form.submit %> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,9 @@ | ||
# Files in the config/locales directory are used for internationalization | ||
# and are automatically loaded by Rails. If you want to use locales other | ||
# than English, add the necessary files in this directory. | ||
# | ||
# To use the locales, use `I18n.t`: | ||
# | ||
# I18n.t 'hello' | ||
# | ||
# In views, this is aliased to just `t`: | ||
# | ||
# <%= t('hello') %> | ||
# | ||
# To use a different locale, set it with `I18n.locale`: | ||
# | ||
# I18n.locale = :es | ||
# | ||
# This would use the information in config/locales/es.yml. | ||
# | ||
# To learn more, please read the Rails Internationalization guide | ||
# available at http://guides.rubyonrails.org/i18n.html. | ||
|
||
en: | ||
hello: "Hello world" | ||
todos: | ||
index: | ||
create_todo: "Create a todo" | ||
mark_complete: "Mark complete" | ||
helpers: | ||
submit: | ||
todo: | ||
create: "Create todo" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
require "rails_helper" | ||
|
||
feature "User creates todo", js: true do | ||
feature "User creates todo" do | ||
scenario "successfully" do | ||
sign_in | ||
create_todo_titled title: "Buy eggs" | ||
|
||
expect(page).to have_css "ul.todos", text: "Buy eggs" | ||
end | ||
todos_page = Pages::Todos.new | ||
todos_page.create_todo title: "Buy eggs" | ||
|
||
def create_todo_titled(title:) | ||
click_on "Create todo" | ||
fill_in "Title", with: title | ||
click_on "Submit" | ||
expect(todos_page).to have_todo_titled "Buy eggs" | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Pages | ||
class NewTodo | ||
include Capybara::DSL | ||
include Formulaic::Dsl | ||
|
||
def initialize(attributes) | ||
@attributes = attributes | ||
end | ||
|
||
def create | ||
fill_form_and_submit :todo, attributes | ||
end | ||
|
||
private | ||
|
||
attr_reader :attributes | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Pages | ||
class Todos | ||
include Capybara::DSL | ||
|
||
def create_todo(attributes) | ||
create_todo_link.click | ||
|
||
Pages::NewTodo.new(attributes).create | ||
end | ||
|
||
def has_todo_titled?(title) | ||
todos_list.has_css? "li", text: title | ||
end | ||
|
||
def has_completed_todo_titled?(title) | ||
todos_list.has_css? "li.completed", text: title | ||
end | ||
|
||
def mark_complete(title) | ||
within "li:contains('#{title}')" do | ||
click_on I18n.t("todos.index.mark_complete") | ||
end | ||
end | ||
|
||
private | ||
|
||
def todos_list | ||
find("ul.todos") | ||
end | ||
|
||
def create_todo_link | ||
find_link I18n.t("todos.index.create_todo") | ||
end | ||
end | ||
end |