Commit 56716ff5
Changed files (17)
app
models
views
categories
layouts
spec
controllers
factories
requests
routing
app/controllers/authentications_controller.rb
@@ -1,4 +1,5 @@
class AuthenticationsController < ApplicationController
+ before_filter :authenticate_user!, :except => [:create]
# GET /authentications
# GET /authentications.xml
def index
app/controllers/categories_controller.rb
@@ -1,84 +1,7 @@
class CategoriesController < ApplicationController
- # GET /categories
- # GET /categories.xml
- def index
- @categories = Category.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @categories }
- end
- end
-
# GET /categories/1
- # GET /categories/1.xml
def show
@category = Category.where(:slug => params[:id]).first
@creations = Creation.joins(:categories).where(:categories => {:slug => params[:id]}).page(params[:page]).per(6)
-
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @category }
- end
- end
-
- # GET /categories/new
- # GET /categories/new.xml
- def new
- @category = Category.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @category }
- end
- end
-
- # GET /categories/1/edit
- def edit
- @category = Category.find(params[:id])
- end
-
- # POST /categories
- # POST /categories.xml
- def create
- @category = Category.new(params[:category])
-
- respond_to do |format|
- if @category.save
- format.html { redirect_to(@category, :notice => 'Category was successfully created.') }
- format.xml { render :xml => @category, :status => :created, :location => @category }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /categories/1
- # PUT /categories/1.xml
- def update
- @category = Category.find(params[:id])
-
- respond_to do |format|
- if @category.update_attributes(params[:category])
- format.html { redirect_to(@category, :notice => 'Category was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /categories/1
- # DELETE /categories/1.xml
- def destroy
- @category = Category.find(params[:id])
- @category.destroy
-
- respond_to do |format|
- format.html { redirect_to(categories_url) }
- format.xml { head :ok }
- end
end
end
app/controllers/creations_controller.rb
@@ -1,36 +1,18 @@
class CreationsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
# GET /creations
- # GET /creations.xml
def index
@creations = Creation.page(params[:page]).per(6)
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @creations }
- end
end
# GET /creations/1
- # GET /creations/1.xml
def show
@creation = Creation.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @creation }
- end
end
# GET /creations/new
- # GET /creations/new.xml
def new
@creation = Creation.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @creation }
- end
end
# GET /creations/1/edit
@@ -39,48 +21,39 @@ class CreationsController < ApplicationController
end
# POST /creations
- # POST /creations.xml
def create
@creation = current_user.creations.create(params[:creation])
@creation.category_ids = params[:creation][:category_ids] ||= []
respond_to do |format|
if @creation.save
format.html { redirect_to(@creation, :notice => 'Creation was successfully created.') }
- format.xml { render :xml => @creation, :status => :created, :location => @creation }
else
format.html { render :action => "new" }
- format.xml { render :xml => @creation.errors, :status => :unprocessable_entity }
end
end
end
# PUT /creations/1
- # PUT /creations/1.xml
def update
@creation = current_user.creations.find(params[:id])
- puts "creation is #{@creation.class}"
@creation.category_ids = params[:creation][:category_ids] ||= []
respond_to do |format|
if @creation.update_attributes(params[:creation])
format.html { redirect_to(@creation, :notice => 'Creation was successfully updated.') }
- format.xml { head :ok }
else
format.html { render :action => "edit" }
- format.xml { render :xml => @creation.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /creations/1
- # DELETE /creations/1.xml
def destroy
@creation = current_user.creations.find(params[:id])
@creation.destroy
respond_to do |format|
format.html { redirect_to(creations_url) }
- format.xml { head :ok }
end
end
@@ -89,7 +62,6 @@ class CreationsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
- format.xml { render :xml => @creations }
end
end
end
app/models/user.rb
@@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :creations, :dependent => :destroy
def apply_omniauth(omniauth)
+ puts omniauth
self.email = omniauth['user_info']['email'] if email.blank?
authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
end
app/views/categories/_form.html.erb
@@ -1,25 +0,0 @@
-<%= form_for(@category) do |f| %>
- <% if @category.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
-
- <ul>
- <% @category.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </div>
- <div class="field">
- <%= f.label :slug %><br />
- <%= f.text_field :slug %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
app/views/categories/edit.html.erb
@@ -1,16 +0,0 @@
-
-<div class="grid_6 alpha">
- <h1>Editing category</h1>
-
- <%= render 'form' %>
-
- <%= link_to 'Show', @category %> |
- <%= link_to 'Back', categories_path %>
-</div>
-<div class="grid_3 omega">
- <div class="helpbox">
- <h4>Did you know?</h4>
- <ul><li>blah</li></ul>
- </div>
-</div>
-<div class="clear"></div>
app/views/categories/index.html.erb
@@ -1,28 +0,0 @@
-
-<div class="grid_9 alpha omega">
- <h1>Listing categories</h1>
-
- <table>
- <tr>
- <th>Name</th>
- <th>Slug</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
- <% @categories.each do |category| %>
- <tr>
- <td><%= category.name %></td>
- <td><%= category.slug %></td>
- <td><%= link_to 'Show', category %></td>
- <td><%= link_to 'Edit', edit_category_path(category) %></td>
- <td><%= link_to 'Destroy', category, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
- <% end %>
- </table>
-
- <br />
-
- <%= link_to 'New category', new_category_path %>
-</div>
app/views/categories/new.html.erb
@@ -1,8 +0,0 @@
-
-<div class="grid_9 alpha omega">
- <h1>New category</h1>
-
- <%= render 'form' %>
-
- <%= link_to 'Back', categories_path %>
-</div>
app/views/layouts/application.html.erb
@@ -73,15 +73,6 @@
<div id="bd">
<div class="container_12">
<div class="grid_3 sidebar">
- <% if user_signed_in? %>
- <div class="summary">
- <div class="shaddow"><img src="assets/arx/shaddow-left.png" /></div>
- <%= image_tag avatar_url(current_user) + '&s=200', :class => ['photo', ''] %>
- <p class="credits"><%= current_user.name %> <%= link_to '(edit)', edit_user_registration_path, :style => 'font-size:small;' %></p>
- <p><span class="fright">0</span>Total Creations</p>
- <p><span class="fright">0</span>Total Likes</p>
- </div><!-- /.summary -->
- <% end %>
<div class="menu">
<ul class="level_1 nojot">
<li class="level_1"><%= link_to "Welcome", home_index_path %></li>
spec/controllers/categories_controller_spec.rb
@@ -2,138 +2,23 @@ require 'spec_helper'
describe CategoriesController do
- def valid_attributes
- {
- :name => 'blah',
- :slug => 'blah'
- }
- end
-
- describe "GET index" do
- it "assigns all categories as @categories" do
- category = Category.create! valid_attributes
- get :index
- assigns(:categories).should eq([category])
- end
+ before(:each) do
+ @creations = []
+ @category = FactoryGirl.create(:category, :creations => @creations)
end
describe "GET show" do
- it "assigns the requested category as @category" do
- category = Category.create! valid_attributes
- get :show, :id => category.slug.to_s
- assigns(:category).should eq(category)
- end
- end
- describe "GET new" do
- it "assigns a new category as @category" do
- get :new
- assigns(:category).should be_a_new(Category)
+ before(:each) do
+ get :show, :id => @category.slug
end
- end
- describe "GET edit" do
it "assigns the requested category as @category" do
- category = Category.create! valid_attributes
- get :edit, :id => category.id.to_s
- assigns(:category).should eq(category)
+ assigns(:category).should eq(@category)
end
- end
-
- describe "POST create" do
- describe "with valid params" do
- it "creates a new Category" do
- expect {
- post :create, :category => valid_attributes
- }.to change(Category, :count).by(1)
- end
- it "assigns a newly created category as @category" do
- post :create, :category => valid_attributes
- assigns(:category).should be_a(Category)
- assigns(:category).should be_persisted
- end
-
- it "redirects to the created category" do
- post :create, :category => valid_attributes
- response.should redirect_to(Category.last)
- end
- end
-
- describe "with invalid params" do
- it "assigns a newly created but unsaved category as @category" do
- # Trigger the behavior that occurs when invalid params are submitted
- Category.any_instance.stub(:save).and_return(false)
- post :create, :category => {}
- assigns(:category).should be_a_new(Category)
- end
-
- it "re-renders the 'new' template" do
- # Trigger the behavior that occurs when invalid params are submitted
- Category.any_instance.stub(:save).and_return(false)
- post :create, :category => {}
- response.should render_template("new")
- end
+ it "should return all creations that are in the category" do
+ assigns(:creations).should eq(@creations)
end
end
-
- describe "PUT update" do
- describe "with valid params" do
- it "updates the requested category" do
- category = Category.create! valid_attributes
- # Assuming there are no other categories in the database, this
- # specifies that the Category created on the previous line
- # receives the :update_attributes message with whatever params are
- # submitted in the request.
- Category.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
- put :update, :id => category.id, :category => {'these' => 'params'}
- end
-
- it "assigns the requested category as @category" do
- category = Category.create! valid_attributes
- put :update, :id => category.id, :category => valid_attributes
- assigns(:category).should eq(category)
- end
-
- it "redirects to the category" do
- category = Category.create! valid_attributes
- put :update, :id => category.id, :category => valid_attributes
- response.should redirect_to(category)
- end
- end
-
- describe "with invalid params" do
- it "assigns the category as @category" do
- category = Category.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Category.any_instance.stub(:save).and_return(false)
- put :update, :id => category.id.to_s, :category => {}
- assigns(:category).should eq(category)
- end
-
- it "re-renders the 'edit' template" do
- category = Category.create! valid_attributes
- # Trigger the behavior that occurs when invalid params are submitted
- Category.any_instance.stub(:save).and_return(false)
- put :update, :id => category.id.to_s, :category => {}
- response.should render_template("edit")
- end
- end
- end
-
- describe "DELETE destroy" do
- it "destroys the requested category" do
- category = Category.create! valid_attributes
- expect {
- delete :destroy, :id => category.id.to_s
- }.to change(Category, :count).by(-1)
- end
-
- it "redirects to the categories list" do
- category = Category.create! valid_attributes
- delete :destroy, :id => category.id.to_s
- response.should redirect_to(categories_url)
- end
- end
-
end
spec/factories/category.rb
@@ -0,0 +1,4 @@
+Factory.define :category, :class => Category do |c|
+ c.name 'blah'
+ c.slug 'blah'
+end
spec/factories/creation.rb
@@ -1,4 +1,4 @@
Factory.define :creation, :class => Creation do |c|
c.name 'cake'
- c.categories ['fondant', 'blah']
+ c.story 'whats the story morning glory?'
end
spec/helpers/categories_helper_spec.rb
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the CategoriesHelper. For example:
-#
-# describe CategoriesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
-describe CategoriesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
spec/helpers/creations_helper_spec.rb
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the CreationsHelper. For example:
-#
-# describe CreationsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
-describe CreationsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
spec/helpers/profiles_helper_spec.rb
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the ProfilesHelper. For example:
-#
-# describe ProfilesHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
-describe ProfilesHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
spec/requests/categories_spec.rb
@@ -1,11 +0,0 @@
-require 'spec_helper'
-
-describe "Categories" do
- describe "GET /categories" 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 categories_path
- response.status.should be(200)
- end
- end
-end
spec/routing/categories_routing_spec.rb
@@ -3,32 +3,8 @@ require "spec_helper"
describe CategoriesController do
describe "routing" do
- it "routes to #index" do
- get("/categories").should route_to("categories#index")
- end
-
- it "routes to #new" do
- get("/categories/new").should route_to("categories#new")
- end
-
it "routes to #show" do
- get("/categories/1").should route_to("categories#show", :id => "1")
- end
-
- it "routes to #edit" do
- get("/categories/1/edit").should route_to("categories#edit", :id => "1")
- end
-
- it "routes to #create" do
- post("/categories").should route_to("categories#create")
- end
-
- it "routes to #update" do
- put("/categories/1").should route_to("categories#update", :id => "1")
- end
-
- it "routes to #destroy" do
- delete("/categories/1").should route_to("categories#destroy", :id => "1")
+ get("/categories/fondant").should route_to("categories#show", :id => "fondant")
end
end