mirror of
https://github.com/fspc/bike-database.git
synced 2025-03-13 18:03:22 -04:00
lk | adds links to previous and next bikes on bike edit page and removes
bike#show route
This commit is contained in:
parent
a517eefd73
commit
692f12d47d
@ -7,14 +7,16 @@ class BikesController < ApplicationController
|
||||
@unsold_bikes = @bikes.select{|bike| bike.date_sold.nil? && bike.purpose == "Sale"}
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def new
|
||||
@bike = Bike.new
|
||||
@log_number = Bike.order(:log_number).last.log_number + 1
|
||||
@previous_bike = Bike.order(:log_number).last
|
||||
@log_number = @previous_bike.log_number + 1
|
||||
end
|
||||
|
||||
def edit; end
|
||||
def edit
|
||||
@next_bike = Bike.where(log_number: @bike.log_number + 1).first
|
||||
@previous_bike = Bike.where(log_number: @bike.log_number - 1).first
|
||||
end
|
||||
|
||||
def print_select
|
||||
@bikes = Bike.where.not(purpose: "Freecyclery").order(:log_number).reverse_order.paginate(:page => params[:page], :per_page => 30)
|
||||
@ -45,7 +47,6 @@ class BikesController < ApplicationController
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
if @bike.update(bike_params)
|
||||
redirect_to @bike, notice: 'Bike was successfully updated.'
|
||||
else
|
||||
@ -53,11 +54,6 @@ class BikesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@bike.destroy
|
||||
redirect_to bikes_url
|
||||
end
|
||||
|
||||
def mark_as_sold
|
||||
current_date = Time.new.strftime("%Y-%m-%d")
|
||||
@bike = Bike.find(params[:id])
|
||||
|
@ -5,6 +5,12 @@
|
||||
.col-sm-3.col-sm-offset-3
|
||||
=button_to "Mark as sold", {action: "mark_as_sold", id: @bike.id}, method: :patch, class: "btn btn-default"
|
||||
= render 'edit_form'
|
||||
= link_to 'Show', @bike
|
||||
- if @next_bike
|
||||
= link_to 'Next Bike', edit_bike_path(@next_bike)
|
||||
- else
|
||||
= link_to 'New Bike', new_bike_path
|
||||
|
|
||||
= link_to 'Back', bikes_path
|
||||
= link_to 'All Bikes', bikes_path
|
||||
- if @previous_bike
|
||||
|
|
||||
= link_to 'Previous Bike', edit_bike_path(@previous_bike)
|
||||
|
@ -1,4 +1,6 @@
|
||||
.container
|
||||
%h1 New bike
|
||||
= render 'new_form'
|
||||
= link_to 'Back', bikes_path
|
||||
= link_to 'All Bikes', bikes_path
|
||||
|
|
||||
= link_to 'Previous Bike', edit_bike_path(@previous_bike)
|
||||
|
@ -6,7 +6,7 @@ Bikedb::Application.routes.draw do
|
||||
|
||||
mount Sidekiq::Web => '/sidekiq'
|
||||
|
||||
resources :bikes do
|
||||
resources :bikes, except: [:show, :destroy] do
|
||||
get 'search' => 'bikes#search', on: :collection
|
||||
get 'print_select' => 'bikes#print_select', on: :collection
|
||||
get 'print_labels' => 'bikes#print_labels', on: :collection
|
||||
|
@ -2,40 +2,57 @@ require 'spec_helper'
|
||||
|
||||
describe BikesController do
|
||||
|
||||
let(:user){FactoryGirl.create(:user)}
|
||||
let(:bike){FactoryGirl.create(:bike)}
|
||||
let(:user){ create :user }
|
||||
let(:bike){ create :bike }
|
||||
|
||||
before :each do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
describe "#index" do
|
||||
it "assignes unsold bikes" do
|
||||
bike = FactoryGirl.create(:bike, date_sold: nil, purpose: "Sale")
|
||||
bike = create :bike, date_sold: nil, purpose: "Sale"
|
||||
get :index
|
||||
expect(assigns(:unsold_bikes)).to eq([bike])
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
describe "#create" do
|
||||
it "creates a new bike with valid credentials" do
|
||||
expect{
|
||||
post :create, bike: FactoryGirl.attributes_for(:bike)
|
||||
post :create, bike: attributes_for(:bike)
|
||||
}.to change(Bike, :count).by(1)
|
||||
end
|
||||
it "redirects to new bike path" do
|
||||
expect(post :create, bike: FactoryGirl.attributes_for(:bike)).to redirect_to(new_bike_path)
|
||||
expect(post :create, bike: attributes_for(:bike)).to redirect_to(new_bike_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "GET #new" do
|
||||
describe "#new" do
|
||||
it "assigns a log number" do
|
||||
FactoryGirl.create(:bike, log_number: 3)
|
||||
create :bike, log_number: 3
|
||||
get :new
|
||||
expect(assigns(:log_number)).to eq(4)
|
||||
end
|
||||
it "assigns the previous bike" do
|
||||
previous_bike = create :bike, log_number: 3
|
||||
get :new
|
||||
expect(assigns(:previous_bike)).to eq(previous_bike)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "#edit" do
|
||||
before do
|
||||
@previous_bike = create :bike, log_number: 2
|
||||
@current_bike = create :bike, log_number: 3
|
||||
@next_bike = create :bike, log_number: 4
|
||||
end
|
||||
it "assigns the current, previous, and next bikes" do
|
||||
get :edit, id: @current_bike.id
|
||||
expect(assigns(:previous_bike)).to eq(@previous_bike)
|
||||
expect(assigns(:bike)).to eq(@current_bike)
|
||||
expect(assigns(:next_bike)).to eq(@next_bike)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user