Commit 1f4ea82
Changed files (4)
app
views
items
config
locales
spec
features
support
pages
app/views/items/_form.html.erb
@@ -1,24 +1,24 @@
<%= form_for(@item) do |f| %>
<div class="small-12 columns">
- <%= f.label :name %>
+ <%= f.label :name, t('.name') %>
<%= f.text_field :name %>
</div>
<div class="small-12 columns">
- <%= f.label :description %>
+ <%= f.label :description, t('.description') %>
<%= f.text_area :description %>
</div>
<div class="small-12 columns">
- <%= f.label :serial_number %>
+ <%= f.label :serial_number, t('.serial_number') %>
<%= f.text_field :serial_number %>
</div>
<div class="small-12 columns">
<div class="row">
<div class="small-6 columns">
- <%= f.label :purchase_price %>
+ <%= f.label :purchase_price, t('.purchase_price') %>
<%= f.text_field :purchase_price %>
</div>
<div class="small-6 columns">
- <%= f.label :purchase_date do %>
+ <%= f.label :purchased_at, t('.purchase_date') do %>
<%= t('.purchased_at') %>
<%= f.date_field :purchased_at %>
<% end %>
config/locales/en.yml
@@ -25,6 +25,10 @@ en:
item_name: 'Item name'
new_item_button: 'Create item'
form:
+ name: 'Name'
+ description: 'Description'
+ serial_number: 'Serial Number'
+ purchase_price: 'Purchase Price'
purchased_at: 'Purchase date'
create_button: 'Create item'
registrations:
spec/features/items_spec.rb
@@ -1,7 +1,7 @@
require "rails_helper"
feature "items", type: :feature do
- describe "/items" do
+ describe "GET /items" do
subject { ItemsPage.new }
let(:user) { create(:user) }
let!(:item) { create(:item, user: user) }
@@ -20,4 +20,25 @@ feature "items", type: :feature do
expect(page.find("#item_name")).to have_val("new item")
end
end
+
+ describe "POST /items" do
+ subject { NewItemPage.new }
+ let(:user) { create(:user) }
+
+ before :each do
+ subject.login_with(user.username, "password")
+ subject.visit_page
+ end
+
+ it "creates a new item" do
+ subject.create_item(
+ name: "hammer",
+ description: "for hammering things",
+ serial_number: "123456",
+ purchase_price: "1.99",
+ purchased_at: "2015-01-01",
+ )
+ expect(subject).to have_content("another item")
+ end
+ end
end
spec/support/pages/items_page.rb
@@ -12,3 +12,25 @@ class ItemsPage < PageModel
end
end
end
+
+class NewItemPage < PageModel
+ def initialize
+ super new_item_path
+ end
+
+ def create_item(name:,
+ description: '',
+ serial_number: '',
+ purchase_price: '',
+ purchased_at: ''
+ )
+ within "#new_item" do
+ fill_in I18n.translate("items.form.name"), with: name
+ fill_in I18n.translate("items.form.description"), with: description
+ fill_in I18n.translate("items.form.serial_number"), with: serial_number
+ fill_in I18n.translate("items.form.purchase_price"), with: purchase_price
+ fill_in I18n.translate("items.form.purchased_at"), with: purchased_at
+ click_button I18n.translate("items.form.create_button")
+ end
+ end
+end