-
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.
- Loading branch information
1 parent
12b1231
commit 6af4091
Showing
10 changed files
with
82 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CrankCountsController < ApplicationController | ||
skip_before_action :ensure_admin | ||
|
||
expose(:crank_user, find_by: :code, id: :crank_user_code) | ||
expose(:crank_count, parent: :crank_user) | ||
|
||
def create | ||
if crank_count.save | ||
flash.notice = "Crank Count created" | ||
redirect_to crank_user_crank_count_path(crank_user, crank_count) | ||
else | ||
flash.alert = crank_count.errors.full_messages.to_sentence | ||
redirect_to new_crank_user_crank_count_path(crank_user) | ||
end | ||
end | ||
|
||
private | ||
|
||
def crank_count_params | ||
params.require(:crank_count).permit(:ticks).merge(cranked_on: Date.today) | ||
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,6 @@ | ||
class CrankCount < ApplicationRecord | ||
belongs_to :crank_user | ||
|
||
validates :cranked_on, presence: true | ||
validates :ticks, presence: true | ||
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,7 @@ | ||
%h1 Create Crank Count for Crank User #{crank_user.code} | ||
|
||
%p Had enough for today? Go ahead and click create to log #{params[:ticks]} ticks! | ||
|
||
= form_with model: [crank_user, crank_count] do |f| | ||
= f.hidden_field :ticks, value: params[:ticks] | ||
= f.button "create" |
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,4 @@ | ||
%h1 Crank Count for Crank User #{crank_user.code} | ||
|
||
%p #{crank_count.ticks} ticks | ||
%p cranked on #{crank_count.cranked_on} |
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,10 @@ | ||
class CreateCrankCounts < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :crank_counts do |t| | ||
t.belongs_to :crank_user | ||
t.integer :ticks, null: false | ||
t.date :cranked_on, null: false | ||
t.timestamps | ||
end | ||
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,7 @@ | ||
FactoryBot.define do | ||
factory :crank_count do | ||
crank_user | ||
ticks { 7 } | ||
cranked_on { Date.today } | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
spec/system/crank_counts/visitor_creates_crank_count_spec.rb
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,14 @@ | ||
require "rails_helper" | ||
|
||
describe "visitor creates crank count" do | ||
scenario "create successfully" do | ||
crank_user = FactoryBot.create(:crank_user) | ||
visit "/crank_users/#{crank_user.code}/crank_counts/new?ticks=77" | ||
click_on "create" | ||
expect(page).to have_content "Crank Count created" | ||
crank_count = CrankCount.last | ||
expect(page).to have_content crank_user.code | ||
expect(page.current_path).to eq crank_user_crank_count_path(crank_user, crank_count) | ||
expect(page).to have_content "77 ticks" | ||
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