diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb new file mode 100644 index 000000000..de8c5c6f9 --- /dev/null +++ b/app/controllers/status_messages_controller.rb @@ -0,0 +1,32 @@ +class StatusMessagesController < ApplicationController + before_filter :authenticate_user! + + def index + @status_messages = StatusMessage.all + end + + def create + @status_message = StatusMessage.new(params[:status_message]) + if @status_message.save + flash[:notice] = "Successfully created status message." + redirect_to @status_message + else + render :action => 'new' + end + end + + def new + @status_message = StatusMessage.new + end + + def destroy + @status_message = StatusMessage.find(params[:id]) + @status_message.destroy + flash[:notice] = "Successfully destroyed status message." + redirect_to status_messages_url + end + + def show + @status_message = StatusMessage.find(params[:id]) + end +end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb new file mode 100644 index 000000000..4c764595f --- /dev/null +++ b/app/helpers/status_messages_helper.rb @@ -0,0 +1,2 @@ +module StatusMessagesHelper +end diff --git a/app/models/status_message.rb b/app/models/status_message.rb new file mode 100644 index 000000000..aae0e58d6 --- /dev/null +++ b/app/models/status_message.rb @@ -0,0 +1,9 @@ +class StatusMessage + include Mongoid::Document + include Mongoid::Timestamps + + field :message + + + validates_presence_of :message +end \ No newline at end of file diff --git a/app/views/status_messages/index.html.haml b/app/views/status_messages/index.html.haml new file mode 100644 index 000000000..516316e5e --- /dev/null +++ b/app/views/status_messages/index.html.haml @@ -0,0 +1,12 @@ +- title "Status Messages" + +%table + %tr + %th Message + - for status_message in @status_messages + %tr + %td= status_message.message + %td= link_to 'Show', status_message + %td= link_to 'Destroy', status_message, :confirm => 'Are you sure?', :method => :delete + +%p= link_to "New Status Message", new_status_message_path diff --git a/app/views/status_messages/new.html.haml b/app/views/status_messages/new.html.haml new file mode 100644 index 000000000..1736639e7 --- /dev/null +++ b/app/views/status_messages/new.html.haml @@ -0,0 +1,13 @@ +- title "New Status Message" + +- form_for @status_message do |f| + = f.error_messages + %p + = f.label :message + %br + = f.text_field :message + %p + = f.submit + + +%p= link_to "Back to List", status_messages_path diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml new file mode 100644 index 000000000..d06bf2f55 --- /dev/null +++ b/app/views/status_messages/show.html.haml @@ -0,0 +1,10 @@ +- title "Status Message" + +%p + %strong Message: + = @status_message.message + +%p + = link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete + | + = link_to "View All", status_messages_path diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb new file mode 100644 index 000000000..c53d5a631 --- /dev/null +++ b/spec/controllers/status_messages_controller_spec.rb @@ -0,0 +1,40 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe StatusMessagesController do + fixtures :all + render_views + + it "index action should render index template" do + get :index + response.should render_template(:index) + end + + it "create action should render new template when model is invalid" do + StatusMessage.any_instance.stubs(:valid?).returns(false) + post :create + response.should render_template(:new) + end + + 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])) + end + + it "new action should render new template" do + get :new + response.should render_template(:new) + end + + it "destroy action should destroy model and redirect to index action" do + status_message = StatusMessage.first + delete :destroy, :id => status_message + response.should redirect_to(status_messages_url) + StatusMessage.exists?(status_message.id).should be_false + end + + it "show action should render show template" do + get :show, :id => StatusMessage.first + response.should render_template(:show) + end +end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb new file mode 100644 index 000000000..544778bfc --- /dev/null +++ b/spec/misc_spec.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe 'making sure the spec runner works' do + + it 'should not delete the database mid-spec' do + User.count.should == 0 + billy = User.create(:email => "billy@aol.com", :password => "foobar") + User.count.should == 1 + end + + it 'should make sure the last user no longer exsists' do + User.count.should == 0 + end + + describe 'testing a before do block' do + before do + @bill = User.create(:email => "billy@aol.com", :password => "foobar") + + end + + it 'should have cleaned before the before do block runs' do + User.count.should == 1 + end + + end +end \ No newline at end of file diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb new file mode 100644 index 000000000..621f49d27 --- /dev/null +++ b/spec/models/status_message_spec.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe StatusMessage do + it "should have a message and an owner" do + n = StatusMessage.new + n.valid?.should be false + n.message = "wales" + n.valid?.should be true + end +end \ No newline at end of file