From 71d243333430aa6f7f9da3b12ac98f0029dbe568 Mon Sep 17 00:00:00 2001 From: loos Date: Sat, 18 Jan 2014 15:27:14 -0600 Subject: [PATCH] add scaffold & bike form --- app/assets/javascripts/bikes.js | 2 + app/assets/stylesheets/bikes.css.scss | 3 + app/assets/stylesheets/scaffolds.css.scss | 69 ++++++++ app/controllers/.bikes_controller.rb.swp | Bin 0 -> 12288 bytes app/controllers/bikes_controller.rb | 62 +++++++ app/helpers/bikes_helper.rb | 2 + app/models/bike.rb | 2 + app/views/bikes/_form.html.erb | 51 ++++++ app/views/bikes/edit.html.erb | 6 + app/views/bikes/index.html.erb | 25 +++ app/views/bikes/index.json.jbuilder | 4 + app/views/bikes/new.html.erb | 5 + app/views/bikes/show.html.erb | 4 + app/views/bikes/show.json.jbuilder | 1 + config/routes.rb | 55 +----- db/.schema.rb.swp | Bin 0 -> 12288 bytes .../20140118202104_create_bike_table.rb | 1 - db/migrate/20140118205930_create_bikes.rb | 6 + db/schema.rb | 137 ++------------- spec/controllers/bikes_controller_spec.rb | 160 ++++++++++++++++++ spec/factories/bikes.rb | 6 + spec/helpers/bikes_helper_spec.rb | 15 ++ spec/models/bike_spec.rb | 5 + spec/requests/bikes_spec.rb | 11 ++ spec/routing/bikes_routing_spec.rb | 35 ++++ spec/views/bikes/edit.html.erb_spec.rb | 15 ++ spec/views/bikes/index.html.erb_spec.rb | 15 ++ spec/views/bikes/new.html.erb_spec.rb | 15 ++ spec/views/bikes/show.html.erb_spec.rb | 12 ++ 29 files changed, 546 insertions(+), 178 deletions(-) create mode 100644 app/assets/javascripts/bikes.js create mode 100644 app/assets/stylesheets/bikes.css.scss create mode 100644 app/assets/stylesheets/scaffolds.css.scss create mode 100644 app/controllers/.bikes_controller.rb.swp create mode 100644 app/controllers/bikes_controller.rb create mode 100644 app/helpers/bikes_helper.rb create mode 100644 app/models/bike.rb create mode 100644 app/views/bikes/_form.html.erb create mode 100644 app/views/bikes/edit.html.erb create mode 100644 app/views/bikes/index.html.erb create mode 100644 app/views/bikes/index.json.jbuilder create mode 100644 app/views/bikes/new.html.erb create mode 100644 app/views/bikes/show.html.erb create mode 100644 app/views/bikes/show.json.jbuilder create mode 100644 db/.schema.rb.swp create mode 100644 db/migrate/20140118205930_create_bikes.rb create mode 100644 spec/controllers/bikes_controller_spec.rb create mode 100644 spec/factories/bikes.rb create mode 100644 spec/helpers/bikes_helper_spec.rb create mode 100644 spec/models/bike_spec.rb create mode 100644 spec/requests/bikes_spec.rb create mode 100644 spec/routing/bikes_routing_spec.rb create mode 100644 spec/views/bikes/edit.html.erb_spec.rb create mode 100644 spec/views/bikes/index.html.erb_spec.rb create mode 100644 spec/views/bikes/new.html.erb_spec.rb create mode 100644 spec/views/bikes/show.html.erb_spec.rb diff --git a/app/assets/javascripts/bikes.js b/app/assets/javascripts/bikes.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/bikes.js @@ -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. diff --git a/app/assets/stylesheets/bikes.css.scss b/app/assets/stylesheets/bikes.css.scss new file mode 100644 index 0000000..c95effe --- /dev/null +++ b/app/assets/stylesheets/bikes.css.scss @@ -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/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -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; + } +} diff --git a/app/controllers/.bikes_controller.rb.swp b/app/controllers/.bikes_controller.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..975965d314eb60310c0e29e7e485f70952205705 GIT binary patch literal 12288 zcmeI2zi;G36vrnBiQ|6pQ$i;w9+x5sN}M}#65I+9KdLK^0ul;NCu?j!pG|C!nHlfi zLI8nipg1~OB&cbqk)WglQ6O{_6m|VUMbv}^R1{K={ zPB6dumjySYe3v&8X=Nl0Z_2vfj8$c|Dhk%79W~+H66k30%6`Nv;1xJhfySmAkDn4- zkDfp0{Fcu?O!wWpbL131=oRn^cm=!yUIDLwSHLUa74QoDzZ9_bl6VVSx~<>VQ+>O% zukE|O@d|hayaHYUuYgy;E8rFI3U~#)0$u^HfLGu@sDMm_7#|bj{W}pne*d5S|Nkw1 z|Nj8o0PlbTq=3Q8U>m#$E`bXm02|;ecnCZQPJ>@h3-Js127C@O@BlaoemsTs!Mk7& zj6nl3a2Y%TzB?(zr{H5?!7?}l?g1yjaq!0pA$|s5gHOO7u%H4Zh`||f4E%Ilh#$aB z@HQyHhuHfK;54{^K7rf8Z|Hvyz5<_tkHCB2I!M3{*arUb3U~#)0$u^HfLFjPAh=2d z;py9bT@2LnfQ=7W;H7100?n^Bx#rc8yD+&H)U3lpc^Eg1uL$Yu9K>YDaoQxlXiHL<(8?)G23R^-C7OsXB?iH zs6Mvr zVtS*EWN^!DS-=fxKq_JzA|w~C2^(GXzM4&~s>BT?iuSto_u6Gz5rTvfteV2&c0B7H z8r(e0A%Z?ojUlAW^+uhz0c))^ipE%J8#6-kt6Hm=jge8oA$F77>9C<;!C_17f}Lz5 zTEPzO%HYj~>2gAN{-$Ju6;P_cB?-&e+v z#ebfW{uPI1#K>`1A`4Q00^fHGVBh-_=(5zkW1b~vbJaMv99##BJ2$L2_i_d&(cIF{ zGqZCDCrdvO2NGX*juE4}IqWoc=W=%*bw}Qau8iD@I9Odk!}*F2{nz-ahzn^ + <% if @bike.errors.any? %> +
+

<%= pluralize(@bike.errors.count, "error") %> prohibited this bike from being saved:

+ +
    + <% @bike.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + + <%= f.label "Bike Entry Date:" %> + <%= f.text_field :entry_date %> +
+ <%= f.label "Brand:" %> + <%= f.text_field :brand %> +
+ <%= f.label "Type:" %> + <%= f.text_field :type %> +
+ <%= f.label "Freecyclery?" %> + <%= f.check_box :freecyclery %> +
+ <%= f.label "Sale?" %> + <%= f.check_box :sale %> +
+ <%= f.label "Serial Number" %> + <%= f.text_field :serial_number %> +
+ <%= f.label "Notes" %> + <%= f.text_area :notes %> +
+ <%= f.label "Tag Info" %> + <%= f.text_area :tag_info %> +
+ <%= f.label "Repaired by:" %> + <%= f.text_field :repaired_by %> +
+ <%= f.label "Completion Date:" %> + <%= f.text_field :completion_date %> +
+ <%= f.label "Price" %> + <%= f.text_field :price %> +
+ +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/bikes/edit.html.erb b/app/views/bikes/edit.html.erb new file mode 100644 index 0000000..3d9c87e --- /dev/null +++ b/app/views/bikes/edit.html.erb @@ -0,0 +1,6 @@ +

Editing bike

+ +<%= render 'form' %> + +<%= link_to 'Show', @bike %> | +<%= link_to 'Back', bikes_path %> diff --git a/app/views/bikes/index.html.erb b/app/views/bikes/index.html.erb new file mode 100644 index 0000000..d72c010 --- /dev/null +++ b/app/views/bikes/index.html.erb @@ -0,0 +1,25 @@ +

Listing bikes

+ + + + + + + + + + + + <% @bikes.each do |bike| %> + + + + + + <% end %> + +
<%= link_to 'Show', bike %><%= link_to 'Edit', edit_bike_path(bike) %><%= link_to 'Destroy', bike, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Bike', new_bike_path %> diff --git a/app/views/bikes/index.json.jbuilder b/app/views/bikes/index.json.jbuilder new file mode 100644 index 0000000..29a7ea7 --- /dev/null +++ b/app/views/bikes/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@bikes) do |bike| + json.extract! bike, + json.url bike_url(bike, format: :json) +end \ No newline at end of file diff --git a/app/views/bikes/new.html.erb b/app/views/bikes/new.html.erb new file mode 100644 index 0000000..d1d0eab --- /dev/null +++ b/app/views/bikes/new.html.erb @@ -0,0 +1,5 @@ +

New bike

+ +<%= render 'form' %> + +<%= link_to 'Back', bikes_path %> diff --git a/app/views/bikes/show.html.erb b/app/views/bikes/show.html.erb new file mode 100644 index 0000000..e61b349 --- /dev/null +++ b/app/views/bikes/show.html.erb @@ -0,0 +1,4 @@ +

<%= notice %>

+ +<%= link_to 'Edit', edit_bike_path(@bike) %> | +<%= link_to 'Back', bikes_path %> diff --git a/app/views/bikes/show.json.jbuilder b/app/views/bikes/show.json.jbuilder new file mode 100644 index 0000000..4cd5644 --- /dev/null +++ b/app/views/bikes/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @bike, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index eb21ebc..922de62 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,3 @@ Bikedb::Application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # 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 + resources :bikes end diff --git a/db/.schema.rb.swp b/db/.schema.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..b965cbd5070c55778a1000e969e465cda0e1f1dc GIT binary patch literal 12288 zcmeI2y>28$6ot!V{45|qDs?05o5I}%PAR+}$b-QQG8WU`0saiT}xqj|F{oUImkEXKm2M71) z?a{8l^`a1;{qf`Bt*?uXS6&d}XknZABAi-x%r4Gfap~jz{oTn(hA=W5u2_WOPyQ8f zJ5$HJRmdPS>3O@zwtc?fN{(E1b%->R2qXeeLZAud*4_=VyE7Tb?VE$w>E)O1KS`vt zClN>l5`jb@5l93QfkYq?NCd7aflzOVPvQNkbN_Fg-!~q+pZ}R|i9jNd2qXfDKq8O` zBm#**B9I6q0*OE(a19B_LWp0V7UHXCU>?8!_uv12$M63Sp+iVOe?2e6cTfqv3O%|Z zL<4!~7W5kQ%X32f41EDLP=F4gE$Aln_p?I$2K@ki4}A%J4i(TnXcxK({RuBWL64ws zp@+~nQ1tjQbOxm>5l93QfkYq?NCXmrMBo|{V1xfYiQY>Uf{Tv${}I4>?Z?%7@}z!1Ua86 zQ`*Zj#s>EN@H(Amr=*^lrpnm$)0wrJr9nI|^~%C}v~xxuClC$!?OO5#g#2s_m$!i>=H8^E1$!pxm{u!1g@p`MH9k;=aT5a+qzqYCu%lqf zH+5}Yz(VDzKUgfpJ9$tie8@Q#PN(m8hl~p@mEk)l>|**U?TjaHjwh47o$*`yyW_jC ziZhaQ5N>+{25aVeNe&^Z3T=tJt(m252;uVME@i3k;L5-WCLEo|rrZLP)#R5xa5WN} z2#f`{wI*3f?}ymU|=na8x>5kPQrA4~KKRlq zZ*8oqNN5p>Bnuow-=z2OUSTQPp)K|5+&HyWRq+AhvquxM2@C5~K)4e?MqP4l`Na~o zrBDXBQPlw7OJFEex$Fwqdmi?+Fld1}8wR78A1S)j7xKn>*pj$_3$SPx#l9F4K4Eaq z9sJ_fi>Rr@2UY|6*w^(cb@-bT8IEP0-uSRPK6bF0% bBRVi>J$%*Q#CwzD3C(;;_mAG)+7tf(rrH#{ literal 0 HcmV?d00001 diff --git a/db/migrate/20140118202104_create_bike_table.rb b/db/migrate/20140118202104_create_bike_table.rb index b6f0172..65bf820 100644 --- a/db/migrate/20140118202104_create_bike_table.rb +++ b/db/migrate/20140118202104_create_bike_table.rb @@ -13,7 +13,6 @@ class CreateBikeTable < ActiveRecord::Migration t.text :notes t.text :tag_info t.string :repaired_by - t.string :repaired_for t.string :completion_date t.string :price end diff --git a/db/migrate/20140118205930_create_bikes.rb b/db/migrate/20140118205930_create_bikes.rb new file mode 100644 index 0000000..e80a745 --- /dev/null +++ b/db/migrate/20140118205930_create_bikes.rb @@ -0,0 +1,6 @@ +class CreateBikes < ActiveRecord::Migration + def change + add_column(:bikes, :created_at, :datetime) + add_column(:bikes, :updated_at, :datetime) + end +end diff --git a/db/schema.rb b/db/schema.rb index 5f81463..72e773c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,137 +11,28 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140118202104) do +ActiveRecord::Schema.define(version: 20140118205930) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "assignments", force: true do |t| - t.integer "attendee_id" - t.integer "task_id" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "assignments", ["attendee_id", "task_id"], name: "index_assignments_on_attendee_id_and_task_id", unique: true, using: :btree - add_index "assignments", ["attendee_id"], name: "index_assignments_on_attendee_id", using: :btree - add_index "assignments", ["task_id"], name: "index_assignments_on_task_id", using: :btree - - create_table "attendees", force: true do |t| - t.string "email" - t.integer "movement_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "event_id" - t.string "name" - end - - add_index "attendees", ["event_id"], name: "index_attendees_on_event_id", using: :btree - create_table "bikes", force: true do |t| - t.string "entry_date" - t.string "brand" - t.string "model" - t.string "type" - t.string "color" - t.string "frame_size" - t.boolean "freecyclery" - t.boolean "sale" - t.string "serial_number" - t.text "notes" - t.text "tag_info" - t.string "repaired_by" - t.string "repaired_for" - t.string "completion_date" - t.string "price" - end - - create_table "events", force: true do |t| - t.string "name" + t.string "entry_date" + t.string "brand" + t.string "model" + t.string "type" + t.string "color" + t.string "frame_size" + t.boolean "freecyclery" + t.boolean "sale" + t.string "serial_number" t.text "notes" - t.string "address" - t.string "city" - t.string "zip" - t.integer "coordinator_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "movement_id" - t.float "latitude" - t.float "longitude" - t.string "date" - t.string "time" - end - - add_index "events", ["movement_id"], name: "index_events_on_movement_id", using: :btree - - create_table "movements", force: true do |t| - t.string "name" - t.string "category" - t.text "story" - t.datetime "created_at" - t.datetime "updated_at" - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - t.string "video" - t.integer "user_id" - end - - add_index "movements", ["user_id"], name: "index_movements_on_user_id", using: :btree - - create_table "tasks", force: true do |t| - t.string "description" + t.text "tag_info" + t.string "repaired_by" + t.string "completion_date" + t.string "price" t.datetime "created_at" t.datetime "updated_at" - t.integer "movement_id" - t.boolean "small_event" - t.boolean "medium_event" - t.boolean "big_event" - end - - add_index "tasks", ["movement_id"], name: "index_tasks_on_movement_id", using: :btree - - create_table "users", force: true do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "" - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - t.string "provider" - t.string "uid" - t.string "name" - t.string "oauth_token" - t.datetime "oauth_expires_at" - t.string "invitation_token" - t.datetime "invitation_created_at" - t.datetime "invitation_sent_at" - t.datetime "invitation_accepted_at" - t.integer "invitation_limit" - t.integer "invited_by_id" - t.string "invited_by_type" - t.integer "movement_id" - end - - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree - add_index "users", ["invited_by_id"], name: "index_users_on_invited_by_id", using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - - create_table "zipcodes", force: true do |t| - t.string "zip" - t.string "city" - t.string "state" - t.string "state_abbreviation" - t.float "latitude" - t.float "longitude" end end diff --git a/spec/controllers/bikes_controller_spec.rb b/spec/controllers/bikes_controller_spec.rb new file mode 100644 index 0000000..3d1dc4f --- /dev/null +++ b/spec/controllers/bikes_controller_spec.rb @@ -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 diff --git a/spec/factories/bikes.rb b/spec/factories/bikes.rb new file mode 100644 index 0000000..d8d090a --- /dev/null +++ b/spec/factories/bikes.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :bike do + end +end diff --git a/spec/helpers/bikes_helper_spec.rb b/spec/helpers/bikes_helper_spec.rb new file mode 100644 index 0000000..ac66205 --- /dev/null +++ b/spec/helpers/bikes_helper_spec.rb @@ -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 diff --git a/spec/models/bike_spec.rb b/spec/models/bike_spec.rb new file mode 100644 index 0000000..dac1bf5 --- /dev/null +++ b/spec/models/bike_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Bike do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/bikes_spec.rb b/spec/requests/bikes_spec.rb new file mode 100644 index 0000000..c5f81c3 --- /dev/null +++ b/spec/requests/bikes_spec.rb @@ -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 diff --git a/spec/routing/bikes_routing_spec.rb b/spec/routing/bikes_routing_spec.rb new file mode 100644 index 0000000..0d16def --- /dev/null +++ b/spec/routing/bikes_routing_spec.rb @@ -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 diff --git a/spec/views/bikes/edit.html.erb_spec.rb b/spec/views/bikes/edit.html.erb_spec.rb new file mode 100644 index 0000000..12b30d9 --- /dev/null +++ b/spec/views/bikes/edit.html.erb_spec.rb @@ -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 diff --git a/spec/views/bikes/index.html.erb_spec.rb b/spec/views/bikes/index.html.erb_spec.rb new file mode 100644 index 0000000..0333284 --- /dev/null +++ b/spec/views/bikes/index.html.erb_spec.rb @@ -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 diff --git a/spec/views/bikes/new.html.erb_spec.rb b/spec/views/bikes/new.html.erb_spec.rb new file mode 100644 index 0000000..0eb5a77 --- /dev/null +++ b/spec/views/bikes/new.html.erb_spec.rb @@ -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 diff --git a/spec/views/bikes/show.html.erb_spec.rb b/spec/views/bikes/show.html.erb_spec.rb new file mode 100644 index 0000000..94a1bfe --- /dev/null +++ b/spec/views/bikes/show.html.erb_spec.rb @@ -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

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + end +end