Commit c61c0ad2

mo khan <mo@mokhan.ca>
2014-07-08 04:13:11
remove old creation actions and views.
1 parent 799d815
app/controllers/creations_controller.rb
@@ -1,6 +1,4 @@
 class CreationsController < ApplicationController
-  before_filter :authenticate_user!, :except => [:show, :index]
-
   def index
     @creations = FindAllCreationsQuery.new.fetch(params)
     expires_in(10.minutes) unless user_signed_in?
@@ -10,54 +8,4 @@ class CreationsController < ApplicationController
     @creation = FindCreationQuery.new.fetch(params[:id])
     expires_in(1.minute) unless user_signed_in?
   end
-
-  def new
-    @creation = Creation.new
-    @user = current_user
-  end
-
-  def edit
-    @creation = current_user.creations.find(params[:id])
-  end
-
-  def create
-    CreateCakeCommand.new(self).run(creation_params, params[:creation_tags])
-  end
-
-  def create_cake_succeeded(cake)
-    @creation = cake
-    redirect_to new_my_cake_photo_path(cake)
-  end
-
-  def create_cake_failed(cake)
-    @creation = cake
-    flash[:error] = @creation.errors.full_messages
-    render :new
-  end
-
-  def update
-    UpdateCakeCommand.new(self).run(params[:id], params[:creation_tags], creation_params)
-  end
-
-  def update_cake_succeeded(cake)
-    @creation = cake
-    redirect_to new_my_cake_photo_path(@creation)
-  end
-
-  def update_cake_failed(cake)
-    @creation = cake
-    flash[:error] = @creation.errors.full_messages
-    render :edit
-  end
-
-  def destroy
-    RemoveCakeCommand.new(self).run(params[:id])
-    redirect_to my_dashboard_path
-  end
-
-  private
-
-  def creation_params
-    params.require(:creation).permit(:name, :story, :category_id)
-  end
 end
app/views/creations/_form.html.erb
@@ -1,53 +0,0 @@
-<% content_for :javascript do %>
-  <script type="text/javascript" charset="utf-8">
-    function loadTags() {
-      var all_tags = [ <% ActsAsTaggableOn::Tag.pluck(:name).sort!.each { |item| %> '<%= item %>', <% } %> ];
-      $('.tooltip-item').tooltip();
-      $('#tags').tagit({ availableTags: all_tags });
-    };
-    $(document).ready(loadTags);
-  </script>
-<% end %>
-<%= form_for(@creation, :html => {:multipart => true, :class => "form-horizontal"}) do |f| %>
-  <fieldset>
-    <div class="control-group">
-      <%= f.label :name, :class => "control-label" %>
-      <div class="controls">
-        <%= f.text_field :name, :class => "input-xxlarge" %>
-      </div>
-    </div>
-    <div class="control-group">
-      <%= f.label :story, "Description", :class=> "control-label" %>
-      <div class="controls">
-        <%= f.text_area :story, :class =>"input-xxlarge", :rows => "3" %>
-      </div>
-    </div>
-    <div class="control-group">
-      <label class="control-label">Category</label>
-      <div class="controls">
-        <%= select_tag 'creation[category_id]', options_from_collection_for_select(@categories, "id", "name") %>
-      </div>
-    </div>
-    <div class="control-group">
-      <label for="tags" class="control-label">Tags</label>
-      <div class="controls">
-      <% if @creation.present? %>
-         <input name="creation_tags" type="text" id="tags" value="<% @creation.tags.map(&:name).each { |item| %><%= item %>,<% } %>" class="input-xxlarge" autocomplete="off" />
-         <p class="help-block">
-           <strong>Note:</strong> Adding tags will help people discover your creation.
-         </p>
-      <% else %>
-        <input name="creation_tags" type="text" id="tags" value="" class="input-xxlarge" autocomplete="off" />
-      <% end %>
-    </div>
-    </div>
-    <div class="form-actions">
-      <button type="submit" class="btn btn-primary">NEXT STEP</button>
-      <% if @creation.new_record? %>
-        <%= link_to "Cancel", my_cakes_path, class: 'btn' %>
-      <% else %>
-        <%= link_to "Cancel", creation_path(@creation), class: 'btn' %>
-      <% end %>
-    </div>
-  </fieldset>
-<% end %>
app/views/creations/edit.html.erb
@@ -1,16 +0,0 @@
-<% provide(:title, "Editing creation #{@creation.name}") %>
-<div class="row">
-  <div class="span3">
-    <div class="thumbnail">
-      <%= avatar_for(current_user) %>
-      <div class="caption">
-        <h5><%= current_user.name %></h5>
-      </div>
-    </div>
-  </div>
-  <div class="span9">
-    <h1><small>Edit</small> <%= @creation.name %> <small>(Step 1 of 2)</small></h1>
-    <hr />
-    <%= render 'form' %>
-  </div>
-</div>
app/views/creations/new.html.erb
@@ -1,8 +0,0 @@
-<% provide(:title, "Share my creation") -%>
-<div class="row">
-  <div class="span12">
-    <h1>Share creation <small>(Step 1 of 2)</small></h1>
-    <hr />
-    <%= render 'form' %>
-  </div>
-</div>
app/views/layouts/_header.html.erb
@@ -11,7 +11,7 @@
             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Creations<b class="caret"></b></a>
             <ul class="dropdown-menu">
               <li>
-              <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_creation_path do %>
+              <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_user_session_path do %>
                 <i class="icon-edit icon-large"></i> Add Creation
               <% end %>
               </li>
@@ -69,7 +69,7 @@
         </ul>
         <ul class="nav pull-right">
           <li>
-            <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_creation_path do %>
+            <%= link_to current_user ? my_root_path(anchor: 'cakes/new') : new_user_session_path do %>
               <i class="icon-edit icon-large"></i> Add Creation
             <% end %>
           </li>
config/routes.rb
@@ -13,7 +13,7 @@ Cake::Application.routes.draw do
     get ':id/page/:page', :action => :show, :on => :collection
   end
 
-  resources :creations do
+  resources :creations, only: [:index, :show] do
     resources :photos, only: [:index, :show]
     resources :favorites, :only => [:index, :create]
     get 'page/:page', :action => :index, :on => :collection
@@ -67,13 +67,11 @@ Cake::Application.routes.draw do
 
   namespace :my do
     get 'dashboard', to: 'dashboard#index'
-    resources :cakes, only: [:index] do
-      resources :photos, only: [:index, :new, :create, :destroy]
-    end
+    resources :cakes, only: [:index]
     resources :favorites, only: [:index]
     resources :settings, only: [:index, :update]
     resources :passwords, only: [:index, :update]
-    resources :avatars, :only => [:edit, :update]
+    resources :avatars, only: [:edit, :update]
     root to: "cakes#index"
   end
 end
spec/controllers/creations_controller_spec.rb
@@ -17,108 +17,10 @@ describe CreationsController do
     end
   end
 
-  context "when logged in" do
-    before { http_login(user) }
-
-    describe "#show" do
-      it "assigns the requested creation" do
-        get :show, :id => creation.id
-        assigns(:creation).should == creation
-      end
-    end
-
-    describe "#new" do
-      it "assigns a new creation" do
-        new_creation = double
-        Creation.stub(:new).and_return(new_creation)
-        get :new
-        assigns(:creation).should be(new_creation)
-      end
-    end
-
-    describe "#edit" do
-      it "assigns the requested creation as @creation" do
-        get :edit, :id => creation.id
-        assigns(:creation).should eq(creation)
-      end
-    end
-
-    describe "#post" do
-      describe "with valid params" do
-        let(:category) { create(:category) }
-
-        before :each do
-          post :create, creation: {
-            name: 'stone',
-            category_id: category.id
-          }, creation_tags: 'cake'
-        end
-
-        it "assigns a newly created creation" do
-          assigns(:creation).should_not be_nil
-          assigns(:creation).name.should == 'stone'
-        end
-
-        it "redirects to the created creation" do
-          response.should redirect_to(new_my_cake_photo_path(assigns(:creation)))
-        end
-      end
-
-      describe "with invalid params" do
-        before { post :create, :creation => {:name => '', category_id: Category.first.id} }
-
-        it "re-renders the 'new' template" do
-          response.should render_template("new")
-        end
-
-        it "should include the errors" do
-          assigns(:creation).errors.count.should > 0
-        end
-      end
-    end
-
-    describe "#patch" do
-      describe "with valid params" do
-        before { patch :update, :id => creation.id, :creation => {:name => 'params'} }
-
-        it "assigns the requested creation as @creation" do
-          assigns(:creation).should == creation
-        end
-
-        it "redirects to the creation" do
-          response.should redirect_to new_my_cake_photo_path(creation.reload)
-        end
-      end
-
-      describe "with invalid params" do
-        before { put :update, :id => creation.id, :creation => {:name=> nil } }
-
-        it "assigns the creation as @creation" do
-          assigns(:creation).should == creation
-        end
-
-        it "re-renders the 'edit' template" do
-          response.should render_template("edit")
-        end
-
-        it "should display an error" do
-          flash[:error].should_not be_nil
-        end
-      end
-    end
-
-    describe "#destroy" do
-      before :each do
-        delete :destroy, :id => creation.id
-      end
-
-      it "destroys the requested creation" do
-        user.creations.count.should == 0
-      end
-
-      it "redirects to the creations list" do
-        response.should redirect_to(my_dashboard_path)
-      end
+  describe "#show" do
+    it "assigns the requested creation" do
+      get :show, :id => creation.id
+      assigns(:creation).should == creation
     end
   end
 end