From 544a521c7867566345031853adbe4cff28912faf Mon Sep 17 00:00:00 2001 From: Drew Butler Date: Sun, 19 Jan 2014 08:50:39 -0600 Subject: [PATCH] Create user model tests for is_active, unban, is_banned and is_new --- spec/models/user_spec.rb | 27 +++++++++++++++++++++++++++ spec/support/blueprints.rb | 8 ++++++++ 2 files changed, 35 insertions(+) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 82113a4..96a09bd 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -32,4 +32,31 @@ describe User do it "gets an error message after registering banned name" do expect { User.make!(:username => "admin") }.to raise_error("Validation failed: Username is not permitted") end + + it "shows a user is banned or not" do + u = User.make!(:banned) + user = User.make! + u.is_banned?.should == true + user.is_banned?.should == false + end + + it "shows a user is active or not" do + u = User.make!(:banned) + user = User.make! + u.is_active?.should == false + user.is_active?.should == true + end + + it "shows a user is recent or not" do + user = User.make!(:created_at => Time.now) + u = User.make!(:created_at => Time.now - 8.days) + user.is_new?.should == true + u.is_new?.should == false + end + + it "unbans a user" do + u = User.make!(:banned) + u.unban!.should be_true + end + end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb index 8d862ff..6b65736 100644 --- a/spec/support/blueprints.rb +++ b/spec/support/blueprints.rb @@ -7,6 +7,14 @@ User.blueprint do username { "username#{sn}" } end +User.blueprint(:banned) do + email { "banned-#{sn}@example.com" } + password { "blah blah" } + password_confirmation { object.password } + username { "username#{sn}" } + banned_at { Time.now } +end + Tag.blueprint do tag { "tag-#{sn}" } description { "tag #{sn}" }