about summary refs log tree commit diff
path: root/spec/models/account_spec.rb
diff options
context:
space:
mode:
authorSamy KACIMI <samy.kacimi@gmail.com>2017-04-05 00:29:56 +0200
committerSamy KACIMI <samy.kacimi@gmail.com>2017-04-05 00:29:56 +0200
commit81c76fe375d9342e5a436db05c8e25305c650e8d (patch)
tree9d81c36f8745de3d5ab8827a82a14be369f0d23e /spec/models/account_spec.rb
parent6fd865c0004efbf11ee87c06fea9f48af567fabe (diff)
add more tests to models
Diffstat (limited to 'spec/models/account_spec.rb')
-rw-r--r--spec/models/account_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 91c8d75cf..fbc9a7d40 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -209,4 +209,73 @@ RSpec.describe Account, type: :model do
       expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
     end
   end
+
+  describe 'validations' do
+    it 'has a valid fabricator' do
+      account = Fabricate.build(:account)
+      account.valid?
+      expect(account).to be_valid
+    end
+
+    it 'is invalid without a username' do
+      account = Fabricate.build(:account, username: nil)
+      account.valid?
+      expect(account).to model_have_error_on_field(:username)
+    end
+
+    it 'is invalid is the username already exists' do
+      account_1 = Fabricate(:account, username: 'the_doctor')
+      account_2 = Fabricate.build(:account, username: 'the_doctor')
+      account_2.valid?
+      expect(account_2).to model_have_error_on_field(:username)
+    end
+
+    context 'when is local' do
+      it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
+        account = Fabricate.build(:account, username: 'the-doctor')
+        account.valid?
+        expect(account).to model_have_error_on_field(:username)
+      end
+
+      it 'is invalid if the username is longer then 30 characters' do
+        account = Fabricate.build(:account, username: Faker::Lorem.characters(31))
+        account.valid?
+        expect(account).to model_have_error_on_field(:username)
+      end
+    end
+  end
+
+  describe 'scopes' do
+    describe 'remote' do
+      it 'returns an array of accounts who have a domain' do
+        account_1 = Fabricate(:account, domain: nil)
+        account_2 = Fabricate(:account, domain: 'example.com')
+        expect(Account.remote).to match_array([account_2])
+      end
+    end
+
+    describe 'local' do
+      it 'returns an array of accounts who do not have a domain' do
+        account_1 = Fabricate(:account, domain: nil)
+        account_2 = Fabricate(:account, domain: 'example.com')
+        expect(Account.local).to match_array([account_1])
+      end
+    end
+
+    describe 'silenced' do
+      it 'returns an array of accounts who are silenced' do
+        account_1 = Fabricate(:account, silenced: true)
+        account_2 = Fabricate(:account, silenced: false)
+        expect(Account.silenced).to match_array([account_1])
+      end
+    end
+
+    describe 'suspended' do
+      it 'returns an array of accounts who are suspended' do
+        account_1 = Fabricate(:account, suspended: true)
+        account_2 = Fabricate(:account, suspended: false)
+        expect(Account.suspended).to match_array([account_1])
+      end
+    end
+  end
 end