Skip to content

Commit

Permalink
Added topic to nags
Browse files Browse the repository at this point in the history
  • Loading branch information
Omer Rauchwerger committed Aug 13, 2011
1 parent 59c57db commit 29d9ffc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/noodnik/nags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module Noodnik
class NagsController < ApplicationController
def postpone
next_nag = params[:period].to_i.from_now
topic = params[:topic]

if user_id.present?
Nag.create! next_nag: next_nag, user_id: user_id
Nag.create! user_id: user_id, topic: topic, next_nag: next_nag
end

render :nothing => true
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20110813072011_add_topic_to_nags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTopicToNags < ActiveRecord::Migration
def change
add_column :noodnik_nags, :topic, :string
end
end
5 changes: 5 additions & 0 deletions test/dummy/db/migrate/20110813072040_add_topic_to_nags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTopicToNags < ActiveRecord::Migration
def change
add_column :noodnik_nags, :topic, :string
end
end
3 changes: 2 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110813070109) do
ActiveRecord::Schema.define(:version => 20110813072040) do

create_table "noodnik_nags", :force => true do |t|
t.datetime "next_nag"
t.boolean "completed"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.string "topic"
end

end
17 changes: 14 additions & 3 deletions test/dummy/spec/controllers/noodnik_nags_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe Noodnik::NagsController do
before :each do
@attr = {use_route: :noodnik}
Noodnik.setup do |config|
config.current_user_id = lambda { nil }
end
Expand All @@ -16,23 +17,33 @@
end

describe "GET 'postpone'" do
before :each do
@topic = :complete_your_registration
@attr.merge! period: 2.weeks, topic: @topic
end

describe "for the first time" do
it "should create a nag" do
lambda do
get :postpone, use_route: :noodnik, period: 2.weeks
get :postpone, @attr
end.should change(Noodnik::Nag, :count).by(1)
end

it "should associate it with the correct user id" do
get :postpone, use_route: :noodnik, period: 2.weeks
get :postpone, @attr
Noodnik::Nag.last.user_id.should == @user_id
end

it "should set the provided topic" do
get :postpone, @attr
Noodnik::Nag.last.topic.should == @topic.to_s
end

it "should set the next nag time correctly" do
t = Time.parse("01/01/2010 10:00")
Time.stub!(:now).and_return(t)

get :postpone, use_route: :noodnik, period: 2.weeks
get :postpone, @attr
Noodnik::Nag.last.next_nag.should == 2.weeks.from_now
end
end
Expand Down

0 comments on commit 29d9ffc

Please sign in to comment.