Commit c6324be5

mo khan <mo@mokhan.ca>
2014-08-28 02:41:25
remove old tutorial actions.
1 parent 227882b
app/controllers/tutorials_controller.rb
@@ -1,6 +1,4 @@
 class TutorialsController < ApplicationController
-  before_filter :authenticate!, :except => [:show, :index]
-
   def index
     @tutorials = Tutorial.includes(:tags).page(params[:page]).per(15)
   end
@@ -8,44 +6,4 @@ class TutorialsController < ApplicationController
   def show
     @tutorial = Tutorial.find(params[:id])
   end
-
-  def new
-    @tutorial = Tutorial.new
-    @user = current_user
-  end
-
-  def edit
-    @tutorial = current_user.tutorials.find(params[:id])
-  end
-
-  def create
-    @tutorial = current_user.tutorials.create(tutorial_params)
-    current_user.tag(@tutorial, :with => params[:tutorial_tags], :on => :tags)
-    if @tutorial.save
-      redirect_to my_dashboard_path, :notice => t(:tutorial_saved)
-    else
-      flash[:error] = @tutorial.errors.full_messages
-      render :new
-    end
-  end
-
-  def update
-    @tutorial = current_user.tutorials.find(params[:id])
-    current_user.tag(@tutorial, :with => params[:tutorial_tags], :on => :tags)
-    if @tutorial.update_attributes(tutorial_params)
-      redirect_to @tutorial
-    else
-      render :edit
-    end
-  end
-
-  def destroy
-    @tutorial = current_user.tutorials.find(params[:id])
-    @tutorial.destroy
-    redirect_to my_dashboard_path
-  end
-
-  def tutorial_params
-    params.require(:tutorial).permit(:url, :heading)
-  end
 end
app/views/tutorials/_form.html.erb
@@ -1,55 +0,0 @@
-<% content_for :javascript do %>
-<script type="text/javascript" charset="utf-8">
-$(function(){
-  var ready = function(){ 
-    new TutorialForm().initialize($);
-    var all_tags = [ <% ActsAsTaggableOn::Tag.all.map(&:name).each { |item| %> '<%= item %>', <% } %> ];
-    $('#tags').tagit({ availableTags: all_tags });
-  };
-  $(document).ready(ready);
-});
-</script>
-<% end %>
-<div class="span12">
-  <%= form_for(@tutorial, :html => {:class => "form-horizontal"}) do |f| %>
-    <fieldset>
-      <div class="control-group">
-        <%= f.label :url, "Tutorial URL", :class => "control-label" %>
-        <div class="controls">
-          <%= f.text_field :url, :class => "input-xxlarge", :placeholder => "Enter the full website link and click outside this box" %>
-        </div>
-      </div>
-      <div class="control-group">
-        <label for="tags" class="control-label">Tags</label>
-          <div class="controls">
-            <input type="text" id="tags" name="tutorial_tags" value="" class="input-xxlarge" autocomplete="off" />
-            <p class="help-block">
-              Note: help people find this tutorial by adding some keyword tags
-            </p>
-          </div>
-      </div>
-      <div class="form-actions">
-        <%= f.hidden_field :heading, :class => "input-xlarge, tutorial-heading" %>
-        <%= f.hidden_field :author, :class => "input-xlarge, tutorial-author" %>
-        <%= f.hidden_field :author_url, :class => "input-xlarge, tutorial-author-url" %>
-        <%= f.hidden_field :description, :class => "input-xlarge, tutorial-description" %>
-        <%= f.hidden_field :image_url %>
-        <button type="submit" class="btn btn-primary">Save</button>
-        <%= link_to "Cancel", tutorials_path, class: 'btn' %>
-      </div>
-    </fieldset>
-  <% end %>
-  <div class="controls">
-            <p class="help-block">
-              A preview will be shown below
-            </p>
-  </div>
-  <div class="thumbnail">
-    <img class="embed-thumb" src="" />
-    <div class="caption">
-      <h3 class="tutorial-heading"></h3>
-      <p id="tag-list"></p>
-      <p class="tutorial-description"></p>
-    </div>
-  </div>
-</div>
app/views/tutorials/edit.html.erb
@@ -1,5 +0,0 @@
-<% provide(:title, "Edit tutorial") -%>
-<div class="row-fluid">
-  <h1>Editing tutorial</h1>
-  <%= render 'form' %>
-</div>
app/views/tutorials/new.html.erb
@@ -1,9 +0,0 @@
-<% provide(:title, "Share a tutorial link") -%>
-<div class="row-fluid">
-  <div class="span12">
-    <h1>Share a tutorial link</h1>
-  </div>
-</div>
-<div class="row-fluid">
-  <%= render 'form' %>
-</div>
config/routes.rb
@@ -6,7 +6,7 @@ Cake::Application.routes.draw do
 
   post 'comments', to: 'comments#create'
 
-  resources :tutorials do
+  resources :tutorials, only: [:index, :show] do
     get 'page/:page', :action => :index, :on => :collection
   end
   resources :tutorial_tags, :only => [:index, :show], :path => :tt do
spec/controllers/tutorials_controller_spec.rb
@@ -1,15 +1,9 @@
 require 'rails_helper'
 
 describe TutorialsController do
-  def valid_attributes
-    {:url => 'http://blah.com', :heading => "hello world"}
-  end
-
   let(:user){ create(:user) }
 
-  before (:each) do
-    http_login(user)
-  end
+  before { http_login(user) }
 
   describe "#index" do
     let(:tutorial) { create(:tutorial) }
@@ -36,118 +30,4 @@ describe TutorialsController do
       assigns(:tutorial).should == tutorial
     end
   end
-
-  describe "#new" do
-    it "assigns a new tutorial as @tutorial" do
-      get :new
-      assigns(:tutorial).should be_a_new(Tutorial)
-    end
-  end
-
-  describe "#edit" do
-    let(:tutorial) { create(:tutorial) }
-
-    it "assigns the requested tutorial as @tutorial" do
-      user.tutorials << tutorial
-      get :edit, {:id => tutorial.to_param}
-      assigns(:tutorial).should eq(tutorial)
-    end
-  end
-
-  describe "#create" do
-    describe "with valid params" do
-      before :each do
-        post :create, {:tutorial => {:url => 'http://blah.com', :heading => "hello world"} }
-      end
-
-      it "creates a new Tutorial" do
-        Tutorial.count.should == 1
-      end
-
-      it "assigns a newly created tutorial as @tutorial" do
-        assigns(:tutorial).should be_a(Tutorial)
-        assigns(:tutorial).should be_persisted
-        assigns(:tutorial).url.should == 'http://blah.com'
-        assigns(:tutorial).heading.should == 'hello world'
-      end
-
-      it "redirects to the created tutorial" do
-        response.should redirect_to(my_dashboard_path)
-      end
-    end
-
-    describe "with invalid params" do
-      before :each do
-        Tutorial.any_instance.stub(:save).and_return(false)
-        post :create, {:tutorial => {:url => '', :heading => ''}}
-      end
-
-      it "assigns a newly created but unsaved tutorial as @tutorial" do
-        assigns(:tutorial).should be_a_new(Tutorial)
-      end
-
-      it "re-renders the 'new' template" do
-        response.should render_template("new")
-      end
-
-      it "should display an error" do
-        flash[:error].should_not be_nil
-      end
-    end
-  end
-
-  describe "#patch" do
-    describe "with valid params" do
-      let(:tutorial) { create(:tutorial) }
-
-      before :each do
-        user.tutorials << tutorial
-        patch :update, :id => tutorial.to_param, :tutorial => { :url => 'http://blah', :heading => 'headless'}
-      end
-
-      it "assigns the requested tutorial" do
-        assigns(:tutorial).should == tutorial
-        assigns(:tutorial).url.should == 'http://blah'
-        assigns(:tutorial).heading.should == 'headless'
-      end
-
-      it "redirects to the tutorial" do
-        response.should redirect_to(tutorial.reload)
-      end
-    end
-
-    describe "with invalid params" do
-      let(:tutorial) { create(:tutorial) }
-      before :each do
-        user.tutorials << tutorial
-        Tutorial.any_instance.stub(:save).and_return(false)
-        patch :update, {:id => tutorial.to_param, :tutorial => {:url => "", :heading => ""}}
-      end
-
-      it "assigns the tutorial as @tutorial" do
-        assigns(:tutorial).should eq(tutorial)
-      end
-
-      it "re-renders the 'edit' template" do
-        response.should render_template("edit")
-      end
-    end
-  end
-
-  describe "#destroy" do
-    let(:tutorial) { create(:tutorial) }
-
-    before :each do
-      user.tutorials << tutorial
-      delete :destroy, {:id => tutorial.to_param}
-    end
-
-    it "destroys the requested tutorial" do
-      Tutorial.count.should == 0
-    end
-
-    it "redirects to the tutorials list" do
-      response.should redirect_to(my_dashboard_path)
-    end
-  end
 end
spec/routing/tutorials_routing_spec.rb
@@ -6,28 +6,8 @@ describe TutorialsController do
       expect(get: "/tutorials").to route_to("tutorials#index")
     end
 
-    it "routes to #new" do
-      expect(get: "/tutorials/new").to route_to("tutorials#new")
-    end
-
     it "routes to #show" do
       expect(get: "/tutorials/1").to route_to("tutorials#show", :id => "1")
     end
-
-    it "routes to #edit" do
-      expect(get: "/tutorials/1/edit").to route_to("tutorials#edit", :id => "1")
-    end
-
-    it "routes to #create" do
-      expect(post: "/tutorials").to route_to("tutorials#create")
-    end
-
-    it "routes to #update" do
-      expect(put: "/tutorials/1").to route_to("tutorials#update", :id => "1")
-    end
-
-    it "routes to #destroy" do
-      expect(delete: "/tutorials/1").to route_to("tutorials#destroy", :id => "1")
-    end
   end
 end