loos
11 years ago
29 changed files with 546 additions and 178 deletions
@ -0,0 +1,2 @@ |
|||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||
|
// All this logic will automatically be available in application.js.
|
@ -0,0 +1,3 @@ |
|||||
|
// Place all the styles related to the Bikes controller here. |
||||
|
// They will automatically be included in application.css. |
||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/ |
@ -0,0 +1,69 @@ |
|||||
|
body { |
||||
|
background-color: #fff; |
||||
|
color: #333; |
||||
|
font-family: verdana, arial, helvetica, sans-serif; |
||||
|
font-size: 13px; |
||||
|
line-height: 18px; |
||||
|
} |
||||
|
|
||||
|
p, ol, ul, td { |
||||
|
font-family: verdana, arial, helvetica, sans-serif; |
||||
|
font-size: 13px; |
||||
|
line-height: 18px; |
||||
|
} |
||||
|
|
||||
|
pre { |
||||
|
background-color: #eee; |
||||
|
padding: 10px; |
||||
|
font-size: 11px; |
||||
|
} |
||||
|
|
||||
|
a { |
||||
|
color: #000; |
||||
|
&:visited { |
||||
|
color: #666; |
||||
|
} |
||||
|
&:hover { |
||||
|
color: #fff; |
||||
|
background-color: #000; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
div { |
||||
|
&.field, &.actions { |
||||
|
margin-bottom: 10px; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#notice { |
||||
|
color: green; |
||||
|
} |
||||
|
|
||||
|
.field_with_errors { |
||||
|
padding: 2px; |
||||
|
background-color: red; |
||||
|
display: table; |
||||
|
} |
||||
|
|
||||
|
#error_explanation { |
||||
|
width: 450px; |
||||
|
border: 2px solid red; |
||||
|
padding: 7px; |
||||
|
padding-bottom: 0; |
||||
|
margin-bottom: 20px; |
||||
|
background-color: #f0f0f0; |
||||
|
h2 { |
||||
|
text-align: left; |
||||
|
font-weight: bold; |
||||
|
padding: 5px 5px 5px 15px; |
||||
|
font-size: 12px; |
||||
|
margin: -7px; |
||||
|
margin-bottom: 0px; |
||||
|
background-color: #c00; |
||||
|
color: #fff; |
||||
|
} |
||||
|
ul li { |
||||
|
font-size: 12px; |
||||
|
list-style: square; |
||||
|
} |
||||
|
} |
Binary file not shown.
@ -0,0 +1,62 @@ |
|||||
|
class BikesController < ApplicationController |
||||
|
before_action :set_bike, only: [:show, :edit, :update, :destroy] |
||||
|
|
||||
|
def index |
||||
|
@bikes = Bike.all |
||||
|
end |
||||
|
|
||||
|
def show |
||||
|
end |
||||
|
|
||||
|
def new |
||||
|
@bike = Bike.new |
||||
|
end |
||||
|
|
||||
|
def edit |
||||
|
end |
||||
|
|
||||
|
def create |
||||
|
@bike = Bike.new(bike_params) |
||||
|
|
||||
|
respond_to do |format| |
||||
|
if @bike.save |
||||
|
format.html { redirect_to @bike, notice: 'Bike was successfully created.' } |
||||
|
format.json { render action: 'show', status: :created, location: @bike } |
||||
|
else |
||||
|
format.html { render action: 'new' } |
||||
|
format.json { render json: @bike.errors, status: :unprocessable_entity } |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def update |
||||
|
respond_to do |format| |
||||
|
if @bike.update(bike_params) |
||||
|
format.html { redirect_to @bike, notice: 'Bike was successfully updated.' } |
||||
|
format.json { head :no_content } |
||||
|
else |
||||
|
format.html { render action: 'edit' } |
||||
|
format.json { render json: @bike.errors, status: :unprocessable_entity } |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def destroy |
||||
|
@bike.destroy |
||||
|
respond_to do |format| |
||||
|
format.html { redirect_to bikes_url } |
||||
|
format.json { head :no_content } |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
private |
||||
|
# Use callbacks to share common setup or constraints between actions. |
||||
|
def set_bike |
||||
|
@bike = Bike.find(params[:id]) |
||||
|
end |
||||
|
|
||||
|
# Never trust parameters from the scary internet, only allow the white list through. |
||||
|
def bike_params |
||||
|
params.require(:bike).permit(:entry_date, :brand, :model, :type, :color, :frame_size, :freecyclery, :sale, :serial_number, :notes, :tag_info, :repaired_by, :completion_date, :price, :created_at, :updated_at) |
||||
|
end |
||||
|
end |
@ -0,0 +1,2 @@ |
|||||
|
module BikesHelper |
||||
|
end |
@ -0,0 +1,2 @@ |
|||||
|
class Bike < ActiveRecord::Base |
||||
|
end |
@ -0,0 +1,51 @@ |
|||||
|
<%= form_for(@bike) do |f| %> |
||||
|
<% if @bike.errors.any? %> |
||||
|
<div id="error_explanation"> |
||||
|
<h2><%= pluralize(@bike.errors.count, "error") %> prohibited this bike from being saved:</h2> |
||||
|
|
||||
|
<ul> |
||||
|
<% @bike.errors.full_messages.each do |msg| %> |
||||
|
<li><%= msg %></li> |
||||
|
<% end %> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<% end %> |
||||
|
|
||||
|
<%= f.label "Bike Entry Date:" %> |
||||
|
<%= f.text_field :entry_date %> |
||||
|
<br> |
||||
|
<%= f.label "Brand:" %> |
||||
|
<%= f.text_field :brand %> |
||||
|
<br> |
||||
|
<%= f.label "Type:" %> |
||||
|
<%= f.text_field :type %> |
||||
|
<br> |
||||
|
<%= f.label "Freecyclery?" %> |
||||
|
<%= f.check_box :freecyclery %> |
||||
|
<br> |
||||
|
<%= f.label "Sale?" %> |
||||
|
<%= f.check_box :sale %> |
||||
|
<br> |
||||
|
<%= f.label "Serial Number" %> |
||||
|
<%= f.text_field :serial_number %> |
||||
|
<br> |
||||
|
<%= f.label "Notes" %> |
||||
|
<%= f.text_area :notes %> |
||||
|
<br> |
||||
|
<%= f.label "Tag Info" %> |
||||
|
<%= f.text_area :tag_info %> |
||||
|
<br> |
||||
|
<%= f.label "Repaired by:" %> |
||||
|
<%= f.text_field :repaired_by %> |
||||
|
<br> |
||||
|
<%= f.label "Completion Date:" %> |
||||
|
<%= f.text_field :completion_date %> |
||||
|
<br> |
||||
|
<%= f.label "Price" %> |
||||
|
<%= f.text_field :price %> |
||||
|
<br> |
||||
|
|
||||
|
<div class="actions"> |
||||
|
<%= f.submit %> |
||||
|
</div> |
||||
|
<% end %> |
@ -0,0 +1,6 @@ |
|||||
|
<h1>Editing bike</h1> |
||||
|
|
||||
|
<%= render 'form' %> |
||||
|
|
||||
|
<%= link_to 'Show', @bike %> | |
||||
|
<%= link_to 'Back', bikes_path %> |
@ -0,0 +1,25 @@ |
|||||
|
<h1>Listing bikes</h1> |
||||
|
|
||||
|
<table> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th></th> |
||||
|
<th></th> |
||||
|
<th></th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
|
||||
|
<tbody> |
||||
|
<% @bikes.each do |bike| %> |
||||
|
<tr> |
||||
|
<td><%= link_to 'Show', bike %></td> |
||||
|
<td><%= link_to 'Edit', edit_bike_path(bike) %></td> |
||||
|
<td><%= link_to 'Destroy', bike, method: :delete, data: { confirm: 'Are you sure?' } %></td> |
||||
|
</tr> |
||||
|
<% end %> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
|
||||
|
<br> |
||||
|
|
||||
|
<%= link_to 'New Bike', new_bike_path %> |
@ -0,0 +1,4 @@ |
|||||
|
json.array!(@bikes) do |bike| |
||||
|
json.extract! bike, |
||||
|
json.url bike_url(bike, format: :json) |
||||
|
end |
@ -0,0 +1,5 @@ |
|||||
|
<h1>New bike</h1> |
||||
|
|
||||
|
<%= render 'form' %> |
||||
|
|
||||
|
<%= link_to 'Back', bikes_path %> |
@ -0,0 +1,4 @@ |
|||||
|
<p id="notice"><%= notice %></p> |
||||
|
|
||||
|
<%= link_to 'Edit', edit_bike_path(@bike) %> | |
||||
|
<%= link_to 'Back', bikes_path %> |
@ -0,0 +1 @@ |
|||||
|
json.extract! @bike, :created_at, :updated_at |
@ -1,56 +1,3 @@ |
|||||
Bikedb::Application.routes.draw do |
Bikedb::Application.routes.draw do |
||||
# The priority is based upon order of creation: first created -> highest priority. |
resources :bikes |
||||
# See how all your routes lay out with "rake routes". |
|
||||
|
|
||||
# You can have the root of your site routed with "root" |
|
||||
# root 'welcome#index' |
|
||||
|
|
||||
# Example of regular route: |
|
||||
# get 'products/:id' => 'catalog#view' |
|
||||
|
|
||||
# Example of named route that can be invoked with purchase_url(id: product.id) |
|
||||
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase |
|
||||
|
|
||||
# Example resource route (maps HTTP verbs to controller actions automatically): |
|
||||
# resources :products |
|
||||
|
|
||||
# Example resource route with options: |
|
||||
# resources :products do |
|
||||
# member do |
|
||||
# get 'short' |
|
||||
# post 'toggle' |
|
||||
# end |
|
||||
# |
|
||||
# collection do |
|
||||
# get 'sold' |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# Example resource route with sub-resources: |
|
||||
# resources :products do |
|
||||
# resources :comments, :sales |
|
||||
# resource :seller |
|
||||
# end |
|
||||
|
|
||||
# Example resource route with more complex sub-resources: |
|
||||
# resources :products do |
|
||||
# resources :comments |
|
||||
# resources :sales do |
|
||||
# get 'recent', on: :collection |
|
||||
# end |
|
||||
# end |
|
||||
|
|
||||
# Example resource route with concerns: |
|
||||
# concern :toggleable do |
|
||||
# post 'toggle' |
|
||||
# end |
|
||||
# resources :posts, concerns: :toggleable |
|
||||
# resources :photos, concerns: :toggleable |
|
||||
|
|
||||
# Example resource route within a namespace: |
|
||||
# namespace :admin do |
|
||||
# # Directs /admin/products/* to Admin::ProductsController |
|
||||
# # (app/controllers/admin/products_controller.rb) |
|
||||
# resources :products |
|
||||
# end |
|
||||
end |
end |
||||
|
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
class CreateBikes < ActiveRecord::Migration |
||||
|
def change |
||||
|
add_column(:bikes, :created_at, :datetime) |
||||
|
add_column(:bikes, :updated_at, :datetime) |
||||
|
end |
||||
|
end |
@ -0,0 +1,160 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
# This spec was generated by rspec-rails when you ran the scaffold generator. |
||||
|
# It demonstrates how one might use RSpec to specify the controller code that |
||||
|
# was generated by Rails when you ran the scaffold generator. |
||||
|
# |
||||
|
# It assumes that the implementation code is generated by the rails scaffold |
||||
|
# generator. If you are using any extension libraries to generate different |
||||
|
# controller code, this generated spec may or may not pass. |
||||
|
# |
||||
|
# It only uses APIs available in rails and/or rspec-rails. There are a number |
||||
|
# of tools you can use to make these specs even more expressive, but we're |
||||
|
# sticking to rails and rspec-rails APIs to keep things simple and stable. |
||||
|
# |
||||
|
# Compared to earlier versions of this generator, there is very limited use of |
||||
|
# stubs and message expectations in this spec. Stubs are only used when there |
||||
|
# is no simpler way to get a handle on the object needed for the example. |
||||
|
# Message expectations are only used when there is no simpler way to specify |
||||
|
# that an instance is receiving a specific message. |
||||
|
|
||||
|
describe BikesController do |
||||
|
|
||||
|
# This should return the minimal set of attributes required to create a valid |
||||
|
# Bike. As you add validations to Bike, be sure to |
||||
|
# adjust the attributes here as well. |
||||
|
let(:valid_attributes) { { } } |
||||
|
|
||||
|
# This should return the minimal set of values that should be in the session |
||||
|
# in order to pass any filters (e.g. authentication) defined in |
||||
|
# BikesController. Be sure to keep this updated too. |
||||
|
let(:valid_session) { {} } |
||||
|
|
||||
|
describe "GET index" do |
||||
|
it "assigns all bikes as @bikes" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
get :index, {}, valid_session |
||||
|
assigns(:bikes).should eq([bike]) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "GET show" do |
||||
|
it "assigns the requested bike as @bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
get :show, {:id => bike.to_param}, valid_session |
||||
|
assigns(:bike).should eq(bike) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "GET new" do |
||||
|
it "assigns a new bike as @bike" do |
||||
|
get :new, {}, valid_session |
||||
|
assigns(:bike).should be_a_new(Bike) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "GET edit" do |
||||
|
it "assigns the requested bike as @bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
get :edit, {:id => bike.to_param}, valid_session |
||||
|
assigns(:bike).should eq(bike) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "POST create" do |
||||
|
describe "with valid params" do |
||||
|
it "creates a new Bike" do |
||||
|
expect { |
||||
|
post :create, {:bike => valid_attributes}, valid_session |
||||
|
}.to change(Bike, :count).by(1) |
||||
|
end |
||||
|
|
||||
|
it "assigns a newly created bike as @bike" do |
||||
|
post :create, {:bike => valid_attributes}, valid_session |
||||
|
assigns(:bike).should be_a(Bike) |
||||
|
assigns(:bike).should be_persisted |
||||
|
end |
||||
|
|
||||
|
it "redirects to the created bike" do |
||||
|
post :create, {:bike => valid_attributes}, valid_session |
||||
|
response.should redirect_to(Bike.last) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "with invalid params" do |
||||
|
it "assigns a newly created but unsaved bike as @bike" do |
||||
|
# Trigger the behavior that occurs when invalid params are submitted |
||||
|
Bike.any_instance.stub(:save).and_return(false) |
||||
|
post :create, {:bike => { }}, valid_session |
||||
|
assigns(:bike).should be_a_new(Bike) |
||||
|
end |
||||
|
|
||||
|
it "re-renders the 'new' template" do |
||||
|
# Trigger the behavior that occurs when invalid params are submitted |
||||
|
Bike.any_instance.stub(:save).and_return(false) |
||||
|
post :create, {:bike => { }}, valid_session |
||||
|
response.should render_template("new") |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "PUT update" do |
||||
|
describe "with valid params" do |
||||
|
it "updates the requested bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
# Assuming there are no other bikes in the database, this |
||||
|
# specifies that the Bike created on the previous line |
||||
|
# receives the :update_attributes message with whatever params are |
||||
|
# submitted in the request. |
||||
|
Bike.any_instance.should_receive(:update).with({ "these" => "params" }) |
||||
|
put :update, {:id => bike.to_param, :bike => { "these" => "params" }}, valid_session |
||||
|
end |
||||
|
|
||||
|
it "assigns the requested bike as @bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
put :update, {:id => bike.to_param, :bike => valid_attributes}, valid_session |
||||
|
assigns(:bike).should eq(bike) |
||||
|
end |
||||
|
|
||||
|
it "redirects to the bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
put :update, {:id => bike.to_param, :bike => valid_attributes}, valid_session |
||||
|
response.should redirect_to(bike) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "with invalid params" do |
||||
|
it "assigns the bike as @bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
# Trigger the behavior that occurs when invalid params are submitted |
||||
|
Bike.any_instance.stub(:save).and_return(false) |
||||
|
put :update, {:id => bike.to_param, :bike => { }}, valid_session |
||||
|
assigns(:bike).should eq(bike) |
||||
|
end |
||||
|
|
||||
|
it "re-renders the 'edit' template" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
# Trigger the behavior that occurs when invalid params are submitted |
||||
|
Bike.any_instance.stub(:save).and_return(false) |
||||
|
put :update, {:id => bike.to_param, :bike => { }}, valid_session |
||||
|
response.should render_template("edit") |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
describe "DELETE destroy" do |
||||
|
it "destroys the requested bike" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
expect { |
||||
|
delete :destroy, {:id => bike.to_param}, valid_session |
||||
|
}.to change(Bike, :count).by(-1) |
||||
|
end |
||||
|
|
||||
|
it "redirects to the bikes list" do |
||||
|
bike = Bike.create! valid_attributes |
||||
|
delete :destroy, {:id => bike.to_param}, valid_session |
||||
|
response.should redirect_to(bikes_url) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,6 @@ |
|||||
|
# Read about factories at https://github.com/thoughtbot/factory_girl |
||||
|
|
||||
|
FactoryGirl.define do |
||||
|
factory :bike do |
||||
|
end |
||||
|
end |
@ -0,0 +1,15 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
# Specs in this file have access to a helper object that includes |
||||
|
# the BikesHelper. For example: |
||||
|
# |
||||
|
# describe BikesHelper do |
||||
|
# describe "string concat" do |
||||
|
# it "concats two strings with spaces" do |
||||
|
# expect(helper.concat_strings("this","that")).to eq("this that") |
||||
|
# end |
||||
|
# end |
||||
|
# end |
||||
|
describe BikesHelper do |
||||
|
pending "add some examples to (or delete) #{__FILE__}" |
||||
|
end |
@ -0,0 +1,5 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe Bike do |
||||
|
pending "add some examples to (or delete) #{__FILE__}" |
||||
|
end |
@ -0,0 +1,11 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe "Bikes" do |
||||
|
describe "GET /bikes" do |
||||
|
it "works! (now write some real specs)" do |
||||
|
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers |
||||
|
get bikes_path |
||||
|
response.status.should be(200) |
||||
|
end |
||||
|
end |
||||
|
end |
@ -0,0 +1,35 @@ |
|||||
|
require "spec_helper" |
||||
|
|
||||
|
describe BikesController do |
||||
|
describe "routing" do |
||||
|
|
||||
|
it "routes to #index" do |
||||
|
get("/bikes").should route_to("bikes#index") |
||||
|
end |
||||
|
|
||||
|
it "routes to #new" do |
||||
|
get("/bikes/new").should route_to("bikes#new") |
||||
|
end |
||||
|
|
||||
|
it "routes to #show" do |
||||
|
get("/bikes/1").should route_to("bikes#show", :id => "1") |
||||
|
end |
||||
|
|
||||
|
it "routes to #edit" do |
||||
|
get("/bikes/1/edit").should route_to("bikes#edit", :id => "1") |
||||
|
end |
||||
|
|
||||
|
it "routes to #create" do |
||||
|
post("/bikes").should route_to("bikes#create") |
||||
|
end |
||||
|
|
||||
|
it "routes to #update" do |
||||
|
put("/bikes/1").should route_to("bikes#update", :id => "1") |
||||
|
end |
||||
|
|
||||
|
it "routes to #destroy" do |
||||
|
delete("/bikes/1").should route_to("bikes#destroy", :id => "1") |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
end |
@ -0,0 +1,15 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe "bikes/edit" do |
||||
|
before(:each) do |
||||
|
@bike = assign(:bike, stub_model(Bike)) |
||||
|
end |
||||
|
|
||||
|
it "renders the edit bike form" do |
||||
|
render |
||||
|
|
||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers |
||||
|
assert_select "form[action=?][method=?]", bike_path(@bike), "post" do |
||||
|
end |
||||
|
end |
||||
|
end |
@ -0,0 +1,15 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe "bikes/index" do |
||||
|
before(:each) do |
||||
|
assign(:bikes, [ |
||||
|
stub_model(Bike), |
||||
|
stub_model(Bike) |
||||
|
]) |
||||
|
end |
||||
|
|
||||
|
it "renders a list of bikes" do |
||||
|
render |
||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers |
||||
|
end |
||||
|
end |
@ -0,0 +1,15 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe "bikes/new" do |
||||
|
before(:each) do |
||||
|
assign(:bike, stub_model(Bike).as_new_record) |
||||
|
end |
||||
|
|
||||
|
it "renders new bike form" do |
||||
|
render |
||||
|
|
||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers |
||||
|
assert_select "form[action=?][method=?]", bikes_path, "post" do |
||||
|
end |
||||
|
end |
||||
|
end |
@ -0,0 +1,12 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe "bikes/show" do |
||||
|
before(:each) do |
||||
|
@bike = assign(:bike, stub_model(Bike)) |
||||
|
end |
||||
|
|
||||
|
it "renders attributes in <p>" do |
||||
|
render |
||||
|
# Run the generator again with the --webrat flag if you want to use webrat matchers |
||||
|
end |
||||
|
end |
Loading…
Reference in new issue