Skip to content
Extraits de code Groupes Projets
Valider 1a1887f7 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

DG MS completed bookmark story

parent 58dfefc3
Branches
Étiquettes
Aucune requête de fusion associée trouvée
Affichage de
avec 232 ajouts et 8 suppressions
class BookmarksController < ApplicationController
before_filter :authenticate_user!
def index
@bookmarks = Bookmark.all
end
def edit
@bookmark = Bookmark.first(:conditions => {:id => params[:id]})
end
def update
@bookmark = Bookmark.first(:conditions => {:id => params[:id]})
if @bookmark.update_attributes(params[:bookmark])
flash[:notice] = "Successfully updated bookmark."
redirect_to @bookmark
else
render :action => 'edit'
end
end
def show
@bookmark = Bookmark.first(:conditions => {:id => params[:id]})
end
def create
@bookmark = Bookmark.new(params[:bookmark])
if @bookmark.save
flash[:notice] = "Successfully created bookmark."
redirect_to @bookmark
else
render :action => 'new'
end
end
def new
@bookmark = Bookmark.new
end
def destroy
@bookmark = Bookmark.first(:conditions => {:id => params[:id]})
@bookmark.destroy
flash[:notice] = "Successfully destroyed bookmark."
redirect_to bookmarks_url
end
end
......@@ -10,7 +10,7 @@ class StatusMessagesController < ApplicationController
@status_message = StatusMessage.new(params[:status_message])
if @status_message.save
flash[:notice] = "Successfully created status message."
redirect_to @status_message
redirect_to status_messages_url
else
render :action => 'new'
end
......
module BookmarksHelper
end
class Bookmark
include Mongoid::Document
include Mongoid::Timestamps
field :owner
field :link
field :title
validates_presence_of :link
before_create :set_default_owner
protected
def set_default_owner
self.owner ||= User.first.email
end
end
\ No newline at end of file
......@@ -12,9 +12,9 @@ class StatusMessage
validates_presence_of :message
before_create :add_owner
before_create :set_default_owner
def self.newest(owner_email)
def self.newest(owner_email)
StatusMessage.last(:conditions => {:owner => owner_email})
end
......@@ -24,8 +24,7 @@ class StatusMessage
protected
def add_owner
def set_default_owner
self.owner ||= User.first.email
end
end
= form_for @bookmark do |f|
= f.error_messages
%p
= f.label :title
%br
= f.text_field :title
%p
= f.label :link
%br
= f.text_field :link
%p
= f.submit
- title "Edit Bookmark"
= render 'form'
%p
= link_to "Show", bookmark_path(@bookmark)
|
= link_to "View All", bookmarks_path
- title "Bookmarks"
%table
%tr
%th Title
%th Link
%th Owner
- for bookmark in @bookmarks
%tr
%td= bookmark.title
%td= link_to bookmark.link, bookmark.link
%td= bookmark.owner
%td= link_to 'Show', bookmark
%td= link_to 'Edit', edit_bookmark_path(bookmark)
%td= link_to 'Destroy', bookmark, :confirm => 'Are you sure?', :method => :delete
%p= link_to "New Bookmark", new_bookmark_path
- title "New Bookmark"
= render 'form'
%p= link_to "Back to List", bookmarks_path
- title "Bookmark"
%p
%strong Title:
= @bookmark.title
%p
%strong Link:
= link_to @bookmark.link
%p
%strong Owner:
= @bookmark.owner
%p
= link_to "Edit", edit_bookmark_path(@bookmark)
|
= link_to "Destroy", @bookmark, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", bookmarks_path
......@@ -30,6 +30,7 @@
%li= link_to "Users", users_path
%li= link_to "Status Messages", status_messages_path
%li= link_to "Friends", friends_path
%li= link_to "Bookmarks", bookmarks_path
.container
- if show_title?
......
Diaspora::Application.routes.draw do |map|
resources :bookmarks
resources :friends
resources :status_messages
......
require File.dirname(__FILE__) + '/../spec_helper'
describe BookmarksController do
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
User.create(:email => "bob@aol.com", :password => "secret")
Bookmark.create(:link => "http://www.yahooligans.com/")
end
render_views
it "index action should render index template" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
get :index
response.should render_template(:index)
end
it "edit action should render edit template" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
get :edit, :id => Bookmark.first.id
response.should render_template(:edit)
end
it "update action should render edit template when model is invalid" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
Bookmark.any_instance.stubs(:valid?).returns(false)
put :update, :id => Bookmark.first.id
response.should render_template(:edit)
end
it "update action should redirect when model is valid" do
#TODO(dan) look into why we need to create a new bookmark object here
Bookmark.any_instance.stubs(:valid?).returns(true)
n = Bookmark.create(:link => "http://hotub.com")
puts n.inspect
put :update, :id => n.id
response.should redirect_to(bookmark_url(assigns[:bookmark]))
end
it "show action should render show template" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
get :show, :id => Bookmark.first.id
response.should render_template(:show)
end
it "create action should render new template when model is invalid" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
Bookmark.any_instance.stubs(:valid?).returns(false)
post :create
response.should render_template(:new)
end
it "create action should redirect when model is valid" do
Bookmark.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(bookmark_url(assigns[:bookmark]))
end
it "new action should render new template" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
get :new
response.should render_template(:new)
end
it "destroy action should destroy model and redirect to index action" do
bookmark = Bookmark.first
delete :destroy, :id => bookmark.id
response.should redirect_to(bookmarks_url)
Bookmark.first(:conditions => {:id => bookmark.id }).nil?.should be true
end
end
......@@ -8,7 +8,6 @@ describe StatusMessagesController do
StatusMessage.create(:message => "yodels.")
end
#fixtures :all
render_views
it "index action should render index template" do
......@@ -28,7 +27,7 @@ describe StatusMessagesController do
it "create action should redirect when model is valid" do
StatusMessage.any_instance.stubs(:valid?).returns(true)
post :create
response.should redirect_to(status_message_url(assigns[:status_message]))
response.should redirect_to(status_messages_url)
end
it "new action should render new template" do
......@@ -47,7 +46,6 @@ describe StatusMessagesController do
it "show action should render show template" do
request.env['warden'].should_receive(:authenticate?).at_least(:once)
get :show, :id => StatusMessage.first.id
response.should render_template(:show)
end
......
require File.dirname(__FILE__) + '/../spec_helper'
describe Bookmark do
it "should have a link" do
bookmark = Bookmark.new
bookmark.valid?.should be false
bookmark.link = "http://angjoo.com/"
bookmark.valid?.should be true
end
it "should add an owner if none is present" do
User.create(:email => "bob@aol.com", :password => "big bux")
n = Bookmark.create(:link => "http://www.validurl.com/")
n.owner.should == "bob@aol.com"
end
end
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter