logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

account_interactions_spec.rb (17042B)


  1. require 'rails_helper'
  2. describe AccountInteractions do
  3. let(:account) { Fabricate(:account, username: 'account') }
  4. let(:account_id) { account.id }
  5. let(:account_ids) { [account_id] }
  6. let(:target_account) { Fabricate(:account, username: 'target') }
  7. let(:target_account_id) { target_account.id }
  8. let(:target_account_ids) { [target_account_id] }
  9. describe '.following_map' do
  10. subject { Account.following_map(target_account_ids, account_id) }
  11. context 'account with Follow' do
  12. it 'returns { target_account_id => true }' do
  13. Fabricate(:follow, account: account, target_account: target_account)
  14. is_expected.to eq(target_account_id => { reblogs: true })
  15. end
  16. end
  17. context 'account without Follow' do
  18. it 'returns {}' do
  19. is_expected.to eq({})
  20. end
  21. end
  22. end
  23. describe '.followed_by_map' do
  24. subject { Account.followed_by_map(target_account_ids, account_id) }
  25. context 'account with Follow' do
  26. it 'returns { target_account_id => true }' do
  27. Fabricate(:follow, account: target_account, target_account: account)
  28. is_expected.to eq(target_account_id => true)
  29. end
  30. end
  31. context 'account without Follow' do
  32. it 'returns {}' do
  33. is_expected.to eq({})
  34. end
  35. end
  36. end
  37. describe '.blocking_map' do
  38. subject { Account.blocking_map(target_account_ids, account_id) }
  39. context 'account with Block' do
  40. it 'returns { target_account_id => true }' do
  41. Fabricate(:block, account: account, target_account: target_account)
  42. is_expected.to eq(target_account_id => true)
  43. end
  44. end
  45. context 'account without Block' do
  46. it 'returns {}' do
  47. is_expected.to eq({})
  48. end
  49. end
  50. end
  51. describe '.muting_map' do
  52. subject { Account.muting_map(target_account_ids, account_id) }
  53. context 'account with Mute' do
  54. before do
  55. Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
  56. end
  57. context 'if Mute#hide_notifications?' do
  58. let(:hide) { true }
  59. it 'returns { target_account_id => { notifications: true } }' do
  60. is_expected.to eq(target_account_id => { notifications: true })
  61. end
  62. end
  63. context 'unless Mute#hide_notifications?' do
  64. let(:hide) { false }
  65. it 'returns { target_account_id => { notifications: false } }' do
  66. is_expected.to eq(target_account_id => { notifications: false })
  67. end
  68. end
  69. end
  70. context 'account without Mute' do
  71. it 'returns {}' do
  72. is_expected.to eq({})
  73. end
  74. end
  75. end
  76. describe '#follow!' do
  77. it 'creates and returns Follow' do
  78. expect do
  79. expect(account.follow!(target_account)).to be_kind_of Follow
  80. end.to change { account.following.count }.by 1
  81. end
  82. end
  83. describe '#block' do
  84. it 'creates and returns Block' do
  85. expect do
  86. expect(account.block!(target_account)).to be_kind_of Block
  87. end.to change { account.block_relationships.count }.by 1
  88. end
  89. end
  90. describe '#mute!' do
  91. context 'Mute does not exist yet' do
  92. context 'arg :notifications is nil' do
  93. let(:arg_notifications) { nil }
  94. it 'creates Mute, and returns nil' do
  95. expect do
  96. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  97. end.to change { account.mute_relationships.count }.by 1
  98. end
  99. end
  100. context 'arg :notifications is false' do
  101. let(:arg_notifications) { false }
  102. it 'creates Mute, and returns nil' do
  103. expect do
  104. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  105. end.to change { account.mute_relationships.count }.by 1
  106. end
  107. end
  108. context 'arg :notifications is true' do
  109. let(:arg_notifications) { true }
  110. it 'creates Mute, and returns nil' do
  111. expect do
  112. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  113. end.to change { account.mute_relationships.count }.by 1
  114. end
  115. end
  116. end
  117. context 'Mute already exists' do
  118. before do
  119. account.mute_relationships << mute
  120. end
  121. let(:mute) do
  122. Fabricate(:mute,
  123. account: account,
  124. target_account: target_account,
  125. hide_notifications: hide_notifications)
  126. end
  127. context 'mute.hide_notifications is true' do
  128. let(:hide_notifications) { true }
  129. context 'arg :notifications is nil' do
  130. let(:arg_notifications) { nil }
  131. it 'returns nil without updating mute.hide_notifications' do
  132. expect do
  133. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  134. mute = account.mute_relationships.find_by(target_account: target_account)
  135. expect(mute.hide_notifications?).to be true
  136. end
  137. end
  138. end
  139. context 'arg :notifications is false' do
  140. let(:arg_notifications) { false }
  141. it 'returns true, and updates mute.hide_notifications false' do
  142. expect do
  143. expect(account.mute!(target_account, notifications: arg_notifications)).to be true
  144. mute = account.mute_relationships.find_by(target_account: target_account)
  145. expect(mute.hide_notifications?).to be false
  146. end
  147. end
  148. end
  149. context 'arg :notifications is true' do
  150. let(:arg_notifications) { true }
  151. it 'returns nil without updating mute.hide_notifications' do
  152. expect do
  153. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  154. mute = account.mute_relationships.find_by(target_account: target_account)
  155. expect(mute.hide_notifications?).to be true
  156. end
  157. end
  158. end
  159. end
  160. context 'mute.hide_notifications is false' do
  161. let(:hide_notifications) { false }
  162. context 'arg :notifications is nil' do
  163. let(:arg_notifications) { nil }
  164. it 'returns true, and updates mute.hide_notifications true' do
  165. expect do
  166. expect(account.mute!(target_account, notifications: arg_notifications)).to be true
  167. mute = account.mute_relationships.find_by(target_account: target_account)
  168. expect(mute.hide_notifications?).to be true
  169. end
  170. end
  171. end
  172. context 'arg :notifications is false' do
  173. let(:arg_notifications) { false }
  174. it 'returns nil without updating mute.hide_notifications' do
  175. expect do
  176. expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
  177. mute = account.mute_relationships.find_by(target_account: target_account)
  178. expect(mute.hide_notifications?).to be false
  179. end
  180. end
  181. end
  182. context 'arg :notifications is true' do
  183. let(:arg_notifications) { true }
  184. it 'returns true, and updates mute.hide_notifications true' do
  185. expect do
  186. expect(account.mute!(target_account, notifications: arg_notifications)).to be true
  187. mute = account.mute_relationships.find_by(target_account: target_account)
  188. expect(mute.hide_notifications?).to be true
  189. end
  190. end
  191. end
  192. end
  193. end
  194. end
  195. describe '#mute_conversation!' do
  196. let(:conversation) { Fabricate(:conversation) }
  197. subject { account.mute_conversation!(conversation) }
  198. it 'creates and returns ConversationMute' do
  199. expect do
  200. is_expected.to be_kind_of ConversationMute
  201. end.to change { account.conversation_mutes.count }.by 1
  202. end
  203. end
  204. describe '#block_domain!' do
  205. let(:domain_block) { Fabricate(:domain_block) }
  206. subject { account.block_domain!(domain_block) }
  207. it 'creates and returns AccountDomainBlock' do
  208. expect do
  209. is_expected.to be_kind_of AccountDomainBlock
  210. end.to change { account.domain_blocks.count }.by 1
  211. end
  212. end
  213. describe '#unfollow!' do
  214. subject { account.unfollow!(target_account) }
  215. context 'following target_account' do
  216. it 'returns destroyed Follow' do
  217. account.active_relationships.create(target_account: target_account)
  218. is_expected.to be_kind_of Follow
  219. expect(subject).to be_destroyed
  220. end
  221. end
  222. context 'not following target_account' do
  223. it 'returns nil' do
  224. is_expected.to be_nil
  225. end
  226. end
  227. end
  228. describe '#unblock!' do
  229. subject { account.unblock!(target_account) }
  230. context 'blocking target_account' do
  231. it 'returns destroyed Block' do
  232. account.block_relationships.create(target_account: target_account)
  233. is_expected.to be_kind_of Block
  234. expect(subject).to be_destroyed
  235. end
  236. end
  237. context 'not blocking target_account' do
  238. it 'returns nil' do
  239. is_expected.to be_nil
  240. end
  241. end
  242. end
  243. describe '#unmute!' do
  244. subject { account.unmute!(target_account) }
  245. context 'muting target_account' do
  246. it 'returns destroyed Mute' do
  247. account.mute_relationships.create(target_account: target_account)
  248. is_expected.to be_kind_of Mute
  249. expect(subject).to be_destroyed
  250. end
  251. end
  252. context 'not muting target_account' do
  253. it 'returns nil' do
  254. is_expected.to be_nil
  255. end
  256. end
  257. end
  258. describe '#unmute_conversation!' do
  259. let(:conversation) { Fabricate(:conversation) }
  260. subject { account.unmute_conversation!(conversation) }
  261. context 'muting the conversation' do
  262. it 'returns destroyed ConversationMute' do
  263. account.conversation_mutes.create(conversation: conversation)
  264. is_expected.to be_kind_of ConversationMute
  265. expect(subject).to be_destroyed
  266. end
  267. end
  268. context 'not muting the conversation' do
  269. it 'returns nil' do
  270. is_expected.to be nil
  271. end
  272. end
  273. end
  274. describe '#unblock_domain!' do
  275. let(:domain) { 'example.com' }
  276. subject { account.unblock_domain!(domain) }
  277. context 'blocking the domain' do
  278. it 'returns destroyed AccountDomainBlock' do
  279. account_domain_block = Fabricate(:account_domain_block, domain: domain)
  280. account.domain_blocks << account_domain_block
  281. is_expected.to be_kind_of AccountDomainBlock
  282. expect(subject).to be_destroyed
  283. end
  284. end
  285. context 'unblocking the domain' do
  286. it 'returns nil' do
  287. is_expected.to be_nil
  288. end
  289. end
  290. end
  291. describe '#following?' do
  292. subject { account.following?(target_account) }
  293. context 'following target_account' do
  294. it 'returns true' do
  295. account.active_relationships.create(target_account: target_account)
  296. is_expected.to be true
  297. end
  298. end
  299. context 'not following target_account' do
  300. it 'returns false' do
  301. is_expected.to be false
  302. end
  303. end
  304. end
  305. describe '#blocking?' do
  306. subject { account.blocking?(target_account) }
  307. context 'blocking target_account' do
  308. it 'returns true' do
  309. account.block_relationships.create(target_account: target_account)
  310. is_expected.to be true
  311. end
  312. end
  313. context 'not blocking target_account' do
  314. it 'returns false' do
  315. is_expected.to be false
  316. end
  317. end
  318. end
  319. describe '#domain_blocking?' do
  320. let(:domain) { 'example.com' }
  321. subject { account.domain_blocking?(domain) }
  322. context 'blocking the domain' do
  323. it' returns true' do
  324. account_domain_block = Fabricate(:account_domain_block, domain: domain)
  325. account.domain_blocks << account_domain_block
  326. is_expected.to be true
  327. end
  328. end
  329. context 'not blocking the domain' do
  330. it 'returns false' do
  331. is_expected.to be false
  332. end
  333. end
  334. end
  335. describe '#muting?' do
  336. subject { account.muting?(target_account) }
  337. context 'muting target_account' do
  338. it 'returns true' do
  339. mute = Fabricate(:mute, account: account, target_account: target_account)
  340. account.mute_relationships << mute
  341. is_expected.to be true
  342. end
  343. end
  344. context 'not muting target_account' do
  345. it 'returns false' do
  346. is_expected.to be false
  347. end
  348. end
  349. end
  350. describe '#muting_conversation?' do
  351. let(:conversation) { Fabricate(:conversation) }
  352. subject { account.muting_conversation?(conversation) }
  353. context 'muting the conversation' do
  354. it 'returns true' do
  355. account.conversation_mutes.create(conversation: conversation)
  356. is_expected.to be true
  357. end
  358. end
  359. context 'not muting the conversation' do
  360. it 'returns false' do
  361. is_expected.to be false
  362. end
  363. end
  364. end
  365. describe '#muting_notifications?' do
  366. before do
  367. mute = Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
  368. account.mute_relationships << mute
  369. end
  370. subject { account.muting_notifications?(target_account) }
  371. context 'muting notifications of target_account' do
  372. let(:hide) { true }
  373. it 'returns true' do
  374. is_expected.to be true
  375. end
  376. end
  377. context 'not muting notifications of target_account' do
  378. let(:hide) { false }
  379. it 'returns false' do
  380. is_expected.to be false
  381. end
  382. end
  383. end
  384. describe '#requested?' do
  385. subject { account.requested?(target_account) }
  386. context 'requested by target_account' do
  387. it 'returns true' do
  388. Fabricate(:follow_request, account: account, target_account: target_account)
  389. is_expected.to be true
  390. end
  391. end
  392. context 'not requested by target_account' do
  393. it 'returns false' do
  394. is_expected.to be false
  395. end
  396. end
  397. end
  398. describe '#favourited?' do
  399. let(:status) { Fabricate(:status, account: account, favourites: favourites) }
  400. subject { account.favourited?(status) }
  401. context 'favorited' do
  402. let(:favourites) { [Fabricate(:favourite, account: account)] }
  403. it 'returns true' do
  404. is_expected.to be true
  405. end
  406. end
  407. context 'not favorited' do
  408. let(:favourites) { [] }
  409. it 'returns false' do
  410. is_expected.to be false
  411. end
  412. end
  413. end
  414. describe '#reblogged?' do
  415. let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
  416. subject { account.reblogged?(status) }
  417. context 'reblogged' do
  418. let(:reblogs) { [Fabricate(:status, account: account)] }
  419. it 'returns true' do
  420. is_expected.to be true
  421. end
  422. end
  423. context 'not reblogged' do
  424. let(:reblogs) { [] }
  425. it 'returns false' do
  426. is_expected.to be false
  427. end
  428. end
  429. end
  430. describe '#pinned?' do
  431. let(:status) { Fabricate(:status, account: account) }
  432. subject { account.pinned?(status) }
  433. context 'pinned' do
  434. it 'returns true' do
  435. Fabricate(:status_pin, account: account, status: status)
  436. is_expected.to be true
  437. end
  438. end
  439. context 'not pinned' do
  440. it 'returns false' do
  441. is_expected.to be false
  442. end
  443. end
  444. end
  445. describe 'muting an account' do
  446. let(:me) { Fabricate(:account, username: 'Me') }
  447. let(:you) { Fabricate(:account, username: 'You') }
  448. context 'with the notifications option unspecified' do
  449. before do
  450. me.mute!(you)
  451. end
  452. it 'defaults to muting notifications' do
  453. expect(me.muting_notifications?(you)).to be true
  454. end
  455. end
  456. context 'with the notifications option set to false' do
  457. before do
  458. me.mute!(you, notifications: false)
  459. end
  460. it 'does not mute notifications' do
  461. expect(me.muting_notifications?(you)).to be false
  462. end
  463. end
  464. context 'with the notifications option set to true' do
  465. before do
  466. me.mute!(you, notifications: true)
  467. end
  468. it 'does mute notifications' do
  469. expect(me.muting_notifications?(you)).to be true
  470. end
  471. end
  472. end
  473. describe 'ignoring reblogs from an account' do
  474. before do
  475. @me = Fabricate(:account, username: 'Me')
  476. @you = Fabricate(:account, username: 'You')
  477. end
  478. context 'with the reblogs option unspecified' do
  479. before do
  480. @me.follow!(@you)
  481. end
  482. it 'defaults to showing reblogs' do
  483. expect(@me.muting_reblogs?(@you)).to be(false)
  484. end
  485. end
  486. context 'with the reblogs option set to false' do
  487. before do
  488. @me.follow!(@you, reblogs: false)
  489. end
  490. it 'does mute reblogs' do
  491. expect(@me.muting_reblogs?(@you)).to be(true)
  492. end
  493. end
  494. context 'with the reblogs option set to true' do
  495. before do
  496. @me.follow!(@you, reblogs: true)
  497. end
  498. it 'does not mute reblogs' do
  499. expect(@me.muting_reblogs?(@you)).to be(false)
  500. end
  501. end
  502. end
  503. end