Browse Source

Louis | Remove failing autogenerated tests, fix bug where bike type wasn't saving

master
Loos 10 years ago
parent
commit
4d49cf829f
  1. 3
      .gitignore
  2. 1
      Gemfile
  3. 3
      Gemfile.lock
  4. 2
      app/controllers/bikes_controller.rb
  5. 3
      app/controllers/clients_controller.rb
  6. 1
      app/models/bike.rb
  7. 1
      app/models/client.rb
  8. 8
      app/views/clients/_fields.html.haml
  9. 2
      config/environments/development.rb
  10. 2
      config/initializers/devise.rb
  11. 1
      config/routes.rb
  12. 1
      db/migrate/20140118202104_create_bike_table.rb
  13. 5
      db/migrate/20140917020156_add_bike_to_client.rb
  14. 6
      db/schema.rb
  15. 121
      spec/controllers/bikes_controller_spec.rb
  16. 8
      spec/factories/bikes.rb
  17. 4
      spec/factories/users.rb
  18. 10
      spec/requests/bikes_spec.rb

3
.gitignore

@ -21,3 +21,6 @@
.DS_Store .DS_Store
/config/initializers/secret_token.rb /config/initializers/secret_token.rb
/config/secrets.yml
*.swp

1
Gemfile

@ -11,6 +11,7 @@ gem 'sass-rails', '~> 4.0.0'
gem 'haml' gem 'haml'
group :test, :development do group :test, :development do
gem 'faker'
gem 'rspec' gem 'rspec'
gem 'rspec-rails' gem 'rspec-rails'
gem 'factory_girl' gem 'factory_girl'

3
Gemfile.lock

@ -66,6 +66,8 @@ GEM
factory_girl_rails (4.3.0) factory_girl_rails (4.3.0)
factory_girl (~> 4.3.0) factory_girl (~> 4.3.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.4.3)
i18n (~> 0.5)
ffi (1.9.3) ffi (1.9.3)
growl (1.0.3) growl (1.0.3)
haml (4.0.5) haml (4.0.5)
@ -195,6 +197,7 @@ DEPENDENCIES
devise devise
factory_girl factory_girl
factory_girl_rails (~> 4.0) factory_girl_rails (~> 4.0)
faker
growl (= 1.0.3) growl (= 1.0.3)
haml haml
jbuilder (= 1.0.2) jbuilder (= 1.0.2)

2
app/controllers/bikes_controller.rb

@ -54,7 +54,7 @@ class BikesController < ApplicationController
:entry_date, :entry_date,
:brand, :brand,
:model, :model,
:type, :bike_type,
:color, :color,
:frame_size, :frame_size,
:log_number, :log_number,

3
app/controllers/clients_controller.rb

@ -60,6 +60,7 @@ class ClientsController < ApplicationController
:helmet, :helmet,
:lock, :lock,
:agency, :agency,
:completion_date) :completion_date,
:bike_id)
end end
end end

1
app/models/bike.rb

@ -4,6 +4,5 @@ class Bike < ActiveRecord::Base
validates :model, presence: true validates :model, presence: true
validates :bike_type, presence: true validates :bike_type, presence: true
validates :color, presence: true validates :color, presence: true
validates :frame_size, presence: true
validates :serial_number, presence: true validates :serial_number, presence: true
end end

1
app/models/client.rb

@ -1,2 +1,3 @@
class Client < ActiveRecord::Base class Client < ActiveRecord::Base
has_one :bike
end end

8
app/views/clients/_fields.html.haml

@ -43,7 +43,15 @@
= f.label "Agency", class: "col-sm-2 control-label" = f.label "Agency", class: "col-sm-2 control-label"
.col-sm-10 .col-sm-10
= f.text_field :agency, class: "form-control", disabled: disabled = f.text_field :agency, class: "form-control", disabled: disabled
.form-group .form-group
= f.label "Completion Date:", class: "col-sm-2 control-label" = f.label "Completion Date:", class: "col-sm-2 control-label"
.col-sm-10 .col-sm-10
= f.text_field :completion_date, class: "form-control datepicker", disabled: disabled = f.text_field :completion_date, class: "form-control datepicker", disabled: disabled
.form-group
= f.label "Type:", class: "col-sm-2 control-label"
.col-sm-10
= f.select(:bike_id, Bike.all.collect {|b| [ b.model, b.id ] }, {include_blank: 'None'})

2
config/environments/development.rb

@ -6,8 +6,6 @@ Bikedb::Application.configure do
# since you don't have to restart the web server when you make code changes. # since you don't have to restart the web server when you make code changes.
config.cache_classes = false config.cache_classes = false
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# Do not eager load code on boot. # Do not eager load code on boot.
config.eager_load = false config.eager_load = false

2
config/initializers/devise.rb

@ -4,7 +4,7 @@ Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate # The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing # random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database. # confirmation, reset password and unlock tokens in the database.
# config.secret_key = '0d38d9284bf78335f388721b777096313201c1cfcc3c21166b0072a68255e8c12470cde620602db967463b703a9207b0344fb64d48f9e595335567a906098e2f' config.secret_key = 'ff407f8658cb72582329ddad18c24cd0f4e1f40ee58b70952a329c205c7db4a4c3aab68aa4d7c6110708e570c20c07a145d3bf9c1b67f27c0a3289f490d55076'
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,

1
config/routes.rb

@ -1,6 +1,7 @@
Bikedb::Application.routes.draw do Bikedb::Application.routes.draw do
devise_for :users devise_for :users
root to: "static_pages#home" root to: "static_pages#home"
resources :bikes resources :bikes
resources :volunteers resources :volunteers
resources :clients resources :clients

1
db/migrate/20140118202104_create_bike_table.rb

@ -6,7 +6,6 @@ class CreateBikeTable < ActiveRecord::Migration
t.string :model t.string :model
t.string :type t.string :type
t.string :color t.string :color
t.string :frame_size
t.boolean :freecyclery t.boolean :freecyclery
t.boolean :sale t.boolean :sale
t.string :serial_number t.string :serial_number

5
db/migrate/20140917020156_add_bike_to_client.rb

@ -0,0 +1,5 @@
class AddBikeToClient < ActiveRecord::Migration
def change
add_reference :clients, :bike, index: true
end
end

6
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140917003003) do ActiveRecord::Schema.define(version: 20140917020156) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -22,7 +22,6 @@ ActiveRecord::Schema.define(version: 20140917003003) do
t.string "model" t.string "model"
t.string "bike_type" t.string "bike_type"
t.string "color" t.string "color"
t.string "frame_size"
t.string "serial_number" t.string "serial_number"
t.text "notes" t.text "notes"
t.text "tag_info" t.text "tag_info"
@ -50,8 +49,11 @@ ActiveRecord::Schema.define(version: 20140917003003) do
t.date "completion_date" t.date "completion_date"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "bike_id"
end end
add_index "clients", ["bike_id"], name: "index_clients_on_bike_id", using: :btree
create_table "users", force: true do |t| create_table "users", force: true do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false

121
spec/controllers/bikes_controller_spec.rb

@ -1,122 +1,17 @@
require 'spec_helper' require 'spec_helper'
describe BikesController do describe BikesController do
describe "GET index" do let(:user){FactoryGirl.create(:user)}
it "assigns all bikes as @bikes" do let(:bike){FactoryGirl.create(:bike)}
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 before :each do
it "assigns the requested bike as @bike" do controller.stub(:current_user).and_return(user)
bike = Bike.create! valid_attributes controller.stub(:authenticate_user!).and_return true
get :edit, {:id => bike.to_param}, valid_session
assigns(:bike).should eq(bike)
end
end end
describe "POST create" do describe "POST #create" do
describe "with valid params" do it "creates a new bike with valid credentials" do
it "creates a new Bike" do expect{post :create, bike: FactoryGirl.attributes_for(:bike)}.to change(Bike, :count).by(1)
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
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
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
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
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
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 end

8
spec/factories/bikes.rb

@ -1,6 +1,10 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :bike do factory :bike do
log_number "1234"
brand "Windsor"
model "Clockwork"
bike_type "Fixed Gear"
color "Black"
serial_number "12345678"
end end
end end

4
spec/factories/users.rb

@ -1,6 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
email "user@example.com"
password "password"
end end
end end

10
spec/requests/bikes_spec.rb

@ -1,11 +1 @@
require 'spec_helper' 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

Loading…
Cancel
Save