diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/account_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/import_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/status_pin_spec.rb | 41 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 20 |
4 files changed, 80 insertions, 1 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 17e2d8499..361577eff 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -642,7 +642,6 @@ RSpec.describe Account, type: :model do it 'returns remote accounts with followers whose subscription expiration date is past or not given' do local = Fabricate(:account, domain: nil) matches = [ - { domain: 'remote', subscription_expires_at: nil }, { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' }, ].map(&method(:Fabricate).curry(2).call(:account)) matches.each(&local.method(:follow!)) diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index fa52077cd..321761166 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -1,5 +1,24 @@ require 'rails_helper' RSpec.describe Import, type: :model do + let (:account) { Fabricate(:account) } + let (:type) { 'following' } + let (:data) { attachment_fixture('imports.txt') } + describe 'validations' do + it 'has a valid parameters' do + import = Import.create(account: account, type: type, data: data) + expect(import).to be_valid + end + + it 'is invalid without an type' do + import = Import.create(account: account, data: data) + expect(import).to model_have_error_on_field(:type) + end + + it 'is invalid without a data' do + import = Import.create(account: account, type: type) + expect(import).to model_have_error_on_field(:data) + end + end end diff --git a/spec/models/status_pin_spec.rb b/spec/models/status_pin_spec.rb new file mode 100644 index 000000000..6f54f80f9 --- /dev/null +++ b/spec/models/status_pin_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +RSpec.describe StatusPin, type: :model do + describe 'validations' do + it 'allows pins of own statuses' do + account = Fabricate(:account) + status = Fabricate(:status, account: account) + + expect(StatusPin.new(account: account, status: status).save).to be true + end + + it 'does not allow pins of statuses by someone else' do + account = Fabricate(:account) + status = Fabricate(:status) + + expect(StatusPin.new(account: account, status: status).save).to be false + end + + it 'does not allow pins of reblogs' do + account = Fabricate(:account) + status = Fabricate(:status, account: account) + reblog = Fabricate(:status, reblog: status) + + expect(StatusPin.new(account: account, status: reblog).save).to be false + end + + it 'does not allow pins of private statuses' do + account = Fabricate(:account) + status = Fabricate(:status, account: account, visibility: :private) + + expect(StatusPin.new(account: account, status: status).save).to be false + end + + it 'does not allow pins of direct statuses' do + account = Fabricate(:account) + status = Fabricate(:status, account: account, visibility: :direct) + + expect(StatusPin.new(account: account, status: status).save).to be false + end + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ef45818b9..99aeca01b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -286,4 +286,24 @@ RSpec.describe User, type: :model do Fabricate(:user) end end + + describe 'token_for_app' do + let(:user) { Fabricate(:user) } + let(:app) { Fabricate(:application, owner: user) } + + it 'returns a token' do + expect(user.token_for_app(app)).to be_a(Doorkeeper::AccessToken) + end + + it 'persists a token' do + t = user.token_for_app(app) + expect(user.token_for_app(app)).to eql(t) + end + + it 'is nil if user does not own app' do + app.update!(owner: nil) + + expect(user.token_for_app(app)).to be_nil + end + end end |