Adds organization rejection & tests

This commit is contained in:
kikito
2015-08-12 13:47:47 +02:00
parent 523e69fb02
commit 5cef152c37
4 changed files with 53 additions and 2 deletions

View File

@@ -35,7 +35,13 @@ class User < ActiveRecord::Base
end
def verified_organization?
organization_verified_at.present?
organization_verified_at.present? &&
(organization_rejected_at.blank? || organization_rejected_at < organization_verified_at)
end
def rejected_organization?
organization_rejected_at.present? &&
(organization_verified_at.blank? || organization_verified_at < organization_rejected_at)
end
private

View File

@@ -0,0 +1,5 @@
class AddOrganizationRejectedAtToUsers < ActiveRecord::Migration
def change
add_column :users, :organization_rejected_at, :datetime
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150810155304) do
ActiveRecord::Schema.define(version: 20150812104712) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -53,6 +53,15 @@ ActiveRecord::Schema.define(version: 20150810155304) do
add_index "moderators", ["user_id"], name: "index_moderators_on_user_id", using: :btree
create_table "simple_captcha_data", force: :cascade do |t|
t.string "key", limit: 40
t.string "value", limit: 6
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "simple_captcha_data", ["key"], name: "idx_key", using: :btree
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
@@ -99,6 +108,7 @@ ActiveRecord::Schema.define(version: 20150810155304) do
t.string "organization_name", limit: 80
t.datetime "organization_verified_at"
t.string "phone_number", limit: 30
t.datetime "organization_rejected_at"
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

@@ -141,6 +141,36 @@ describe User do
subject.organization_verified_at = Time.now
expect(subject.verified_organization?).to be true
end
it "is false when the organization was verified and then rejected" do
subject.organization_verified_at = Time.now
subject.organization_rejected_at = Time.now + 1
expect(subject.verified_organization?).to be false
end
it "is true when the organization was rejected and then verified" do
subject.organization_rejected_at = Time.now
subject.organization_verified_at = Time.now + 1
expect(subject.verified_organization?).to be true
end
end
describe "rejected_organization?" do
it "is false when organization_rejected_at? is blank" do
expect(subject.rejected_organization?).to be false
end
it "is true when organization_rejected_at? exists" do
subject.organization_rejected_at = Time.now
expect(subject.rejected_organization?).to be true
end
it "is true when the organization was verified and then rejected" do
subject.organization_verified_at = Time.now
subject.organization_rejected_at = Time.now + 1
expect(subject.rejected_organization?).to be true
end
it "is false when the organization was rejected and then verified" do
subject.organization_rejected_at = Time.now
subject.organization_verified_at = Time.now + 1
expect(subject.rejected_organization?).to be false
end
end
end