From 1f73c2351ea27cb4bba0cc24c31d592e05233141 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 14 Jun 2010 16:20:57 -0700 Subject: [PATCH] DG MS IZ; Status message renders to and from xml; Friend model in place --- Gemfile | 16 +++++-------- app/controllers/status_messages_controller.rb | 6 +++++ app/models/friend.rb | 1 - app/models/status_message.rb | 6 ++++- spec/controllers/friends_controller_spec.rb | 9 +++++-- .../status_messages_controller_spec.rb | 7 ++++++ spec/controllers/users_controller_spec.rb | 24 ------------------- spec/models/friend_spec.rb | 8 +++---- spec/models/status_message_spec.rb | 15 ++++++++++++ spec/models/user_spec.rb | 1 - 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/Gemfile b/Gemfile index f03bde9f2..e8fa2abef 100644 --- a/Gemfile +++ b/Gemfile @@ -1,22 +1,13 @@ source 'http://rubygems.org' gem 'rails', '3.0.0.beta4' -# gem 'rails', :git => 'git://github.com/rails/rails.git' gem "mongoid", :git => "http://github.com/durran/mongoid.git" gem "bson_ext", "1.0.1" -gem "nifty-generators" gem "haml" gem "devise", :git => "git://github.com/plataformatec/devise.git" +gem 'roxml', :git => "git://github.com/Empact/roxml.git" -# Use unicorn as the web server -# gem 'unicorn' - -# Deploy with Capistrano -# gem 'capistrano' - -# To use debugger -gem 'ruby-debug' group :test do gem 'rspec', '>= 2.0.0.beta.10' @@ -27,3 +18,8 @@ group :test do gem 'autotest' end +group :development do + gem "nifty-generators" + gem 'ruby-debug' +end + diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index e34ee6ce0..19b62ecca 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -29,5 +29,11 @@ class StatusMessagesController < ApplicationController def show @status_message = StatusMessage.first(:conditions => {:id => params[:id]}) + + respond_to do |format| + format.html + format.xml { render :xml => @status_message } + format.json { render :json => @status_message } + end end end diff --git a/app/models/friend.rb b/app/models/friend.rb index 6c71adb08..d6cd9e5e4 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -1,6 +1,5 @@ class Friend include Mongoid::Document - include Mongoid::Timestamps field :username field :url diff --git a/app/models/status_message.rb b/app/models/status_message.rb index ce937c202..fd200e445 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -1,9 +1,13 @@ class StatusMessage include Mongoid::Document include Mongoid::Timestamps + include ROXML + + xml_accessor :message + field :message - validates_presence_of :message + end diff --git a/spec/controllers/friends_controller_spec.rb b/spec/controllers/friends_controller_spec.rb index 8ebffbc8a..4637aa15b 100644 --- a/spec/controllers/friends_controller_spec.rb +++ b/spec/controllers/friends_controller_spec.rb @@ -8,10 +8,8 @@ describe FriendsController do Friend.create(:username => "max", :url => "http://max.com/") end - 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 @@ -47,4 +45,11 @@ describe FriendsController do post :create response.should redirect_to(friend_url(assigns[:friend])) end + + it 'should test that a real creation adds to the database' do + end + + it 'should have test that a delete removes a friend from the database' do + end + end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 126bade2c..b8ea56b37 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -50,4 +50,11 @@ describe StatusMessagesController do get :show, :id => StatusMessage.first.id response.should render_template(:show) end + + it "should return xml on the show type if the meme type exsits" do + request.env["HTTP_ACCEPT"] = "application/xml" + message = StatusMessage.first + get :show, :id => message.id + response.body.include?(message.to_xml.to_s).should be true + end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index c72a3188f..55171ccce 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,28 +1,4 @@ require File.dirname(__FILE__) + '/../spec_helper' describe UsersController do - before do - #TODO(dan) Mocking Warden; this is a temp fix - request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) - end - render_views - #fixtures :all end -describe Devise::SessionsController do - before do - #TODO(dan) Mocking Warden; this is a temp fix - request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) - @user = User.create(:email => "bob@rob.com", :password => "lala") - end - it 'should, after logging in redirect to the dashboard page' do - pending "probs should be in cucumber" - sign_in :user, @user - # request.env['warden'].should_receive(:authenticated?).at_least(:once) - # request.env['warden'].should_receive(:user).at_least(:once) - - #User.any_instance.stubs(:valid?).returns(true) - #post :create - - end - end - diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 602da02c8..1a6345435 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -1,12 +1,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Friend do - it 'should have a diaspora username + diaspora url' do + it 'should have a diaspora username and diaspora url' do n = Friend.new(:username => 'max') - n.valid?.should == false + n.valid?.should be false n.url = "http://max.com/" - n.valid?.should == true + n.valid?.should be true end - - end \ No newline at end of file diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index fc1fb164f..7cf7e308a 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -7,4 +7,19 @@ describe StatusMessage do n.message = "wales" n.valid?.should be true end + + describe "XML" do + before do + @xml = "\n I hate WALRUSES!\n" + end + + it 'should serialize to XML' do + message = StatusMessage.new(:message => "I hate WALRUSES!") + message.to_xml.to_s.should == @xml + end + + it 'should marshal serialized XML to object' do + StatusMessage.from_xml(@xml).message.should == "I hate WALRUSES!" + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a77433c27..0f545327b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -#this is implementation is done by devise describe User do end