Commit 802e38c7
Changed files (15)
app
controllers
views
creations
my
cakes
config
db
spec
controllers
support
app/controllers/my/base_controller.rb
@@ -0,0 +1,11 @@
+module My
+ class BaseController < ApplicationController
+ before_filter :restrict_access!
+
+ private
+
+ def restrict_access!
+ redirect_to root_path unless signed_in?
+ end
+ end
+end
app/controllers/my/cakes_controller.rb
@@ -0,0 +1,7 @@
+module My
+ class CakesController < BaseController
+ def index
+ @creations = current_user.creations.includes([:user]).page(params[:page]).per(12)
+ end
+ end
+end
app/controllers/creations_controller.rb
@@ -55,10 +55,6 @@ class CreationsController < ApplicationController
redirect_to(creations_url)
end
- def mine
- @creations = current_user.creations.includes([:user]).page(params[:page]).per(12)
- end
-
private
def creation_params
app/controllers/registrations_controller.rb
@@ -1,6 +1,6 @@
class RegistrationsController < Devise::RegistrationsController
def after_sign_in_path_for(resource)
- mine_creations_path
+ my_cakes_path
end
def sign_up_params
app/views/creations/_form.html.erb
@@ -59,7 +59,7 @@
<div class="form-actions">
<button type="submit" class="btn btn-primary">NEXT STEP</button>
<% if @creation.new_record? %>
- <%= link_to "Cancel", mine_creations_path, class: 'btn' %>
+ <%= link_to "Cancel", my_cakes_path, class: 'btn' %>
<% else %>
<%= link_to "Cancel", creation_path(@creation), class: 'btn' %>
<% end %>
app/views/creations/index.html.erb
@@ -63,6 +63,6 @@
</ul>
</div>
</div>
- <%= render "shared/paging" %>
+ <%= render "shared/paging", items: @creations %>
</div>
</div>
app/views/creations/mine.html.erb → app/views/my/cakes/index.html.erb
File renamed without changes
config/routes.rb
@@ -13,12 +13,10 @@ Cake::Application.routes.draw do
get ':id/page/:page', :action => :show, :on => :collection
end
- # /creations
resources :creations do
resources :photos, :only => [:index, :show, :new, :create, :destroy]
resources :favorites, :only => [:index, :create]
get 'page/:page', :action => :index, :on => :collection
- get 'mine', :action => :mine, :on => :collection
end
# /profiles
@@ -68,4 +66,9 @@ Cake::Application.routes.draw do
resources :subscriptions, only: [:index]
resources :photos, only: [:index, :show]
end
+
+ namespace :my do
+ resources :cakes do
+ end
+ end
end
db/schema.rb
@@ -30,8 +30,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
create_table "avatars", force: true do |t|
t.integer "user_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.string "avatar"
t.boolean "avatar_processing"
t.string "avatar_tmp"
@@ -93,8 +93,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
@@ -111,8 +111,13 @@ ActiveRecord::Schema.define(version: 20140521032101) do
create_table "interests", force: true do |t|
t.string "name"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "page_views", force: true do |t|
+ t.integer "user_id"
+ t.string "url"
end
create_table "photos", force: true do |t|
@@ -151,8 +156,8 @@ ActiveRecord::Schema.define(version: 20140521032101) do
t.text "description"
t.string "url"
t.integer "user_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.string "image_url"
t.string "author"
t.string "author_url"
@@ -161,12 +166,12 @@ ActiveRecord::Schema.define(version: 20140521032101) do
add_index "tutorials", ["user_id"], name: "index_tutorials_on_user_id", using: :btree
create_table "users", force: true do |t|
- t.string "email", default: "", null: false
- t.string "encrypted_password", limit: 128, default: "", null: false
+ t.string "email", default: "", null: false
+ t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", default: 0
+ t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
@@ -185,13 +190,13 @@ ActiveRecord::Schema.define(version: 20140521032101) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
- t.integer "failed_attempts", default: 0
+ t.integer "failed_attempts", default: 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "authentication_token"
t.string "invitation_token"
t.string "full_address"
- t.integer "creations_count", default: 0
+ t.integer "creations_count", default: 0
t.boolean "is_admin"
end
spec/controllers/my/cakes_controller_spec.rb
@@ -0,0 +1,34 @@
+require "spec_helper"
+
+describe My::CakesController do
+ context "when logged in" do
+ let(:user){ create(:user) }
+ before { http_login(user) }
+
+ describe :index do
+ let!(:my_creation) { create(:creation) }
+ let!(:other_creation) { create(:creation) }
+
+ before :each do
+ user.creations << my_creation
+ get :index
+ end
+
+ it "should return all of my creations" do
+ assigns(:creations).should include(my_creation)
+ end
+
+ it "should not return any other creations" do
+ assigns(:creations).should_not include(other_creation)
+ end
+ end
+ end
+
+ context "when not logged in" do
+ it "redirects you to the home page" do
+ get :index
+ response.should redirect_to(root_path)
+ end
+ end
+end
+
spec/controllers/creations_controller_spec.rb
@@ -133,24 +133,5 @@ describe CreationsController do
response.should redirect_to(creations_url)
end
end
-
- describe :mine do
- let!(:my_creation) { create(:creation) }
- let!(:other_creation) { create(:creation) }
-
- before :each do
- user.creations << my_creation
- get :mine
- end
-
- it "should return all of my creations" do
- assigns(:creations).should include(my_creation)
- end
-
- it "should not return any other creations" do
- assigns(:creations).should_not include(other_creation)
- end
- end
end
-
end
spec/support/devise.rb
@@ -4,6 +4,7 @@ module DeviseHelper
gateway = fake
gateway.stub(:authenticate).and_return(user)
gateway.stub(:authenticate!).and_return(user)
+ gateway.stub(:authenticate?).and_return(user)
request.env['warden'] = gateway
end
end