diff --git a/app/models/user.rb b/app/models/user.rb index 6ced65533..0bee83446 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/db/migrate/20150812104712_add_organization_rejected_at_to_users.rb b/db/migrate/20150812104712_add_organization_rejected_at_to_users.rb new file mode 100644 index 000000000..a097c7b34 --- /dev/null +++ b/db/migrate/20150812104712_add_organization_rejected_at_to_users.rb @@ -0,0 +1,5 @@ +class AddOrganizationRejectedAtToUsers < ActiveRecord::Migration + def change + add_column :users, :organization_rejected_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 343294168..79860f41f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 58c2c3cba..c258e2bd1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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