闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

761 lines
24 KiB

8 years ago
8 years ago
  1. require 'rails_helper'
  2. RSpec.describe Account, type: :model do
  3. context do
  4. let(:bob) { Fabricate(:account, username: 'bob') }
  5. subject { Fabricate(:account) }
  6. describe '#follow!' do
  7. it 'creates a follow' do
  8. follow = subject.follow!(bob)
  9. expect(follow).to be_instance_of Follow
  10. expect(follow.account).to eq subject
  11. expect(follow.target_account).to eq bob
  12. end
  13. end
  14. describe '#unfollow!' do
  15. before do
  16. subject.follow!(bob)
  17. end
  18. it 'destroys a follow' do
  19. unfollow = subject.unfollow!(bob)
  20. expect(unfollow).to be_instance_of Follow
  21. expect(unfollow.account).to eq subject
  22. expect(unfollow.target_account).to eq bob
  23. expect(unfollow.destroyed?).to be true
  24. end
  25. end
  26. describe '#following?' do
  27. it 'returns true when the target is followed' do
  28. subject.follow!(bob)
  29. expect(subject.following?(bob)).to be true
  30. end
  31. it 'returns false if the target is not followed' do
  32. expect(subject.following?(bob)).to be false
  33. end
  34. end
  35. end
  36. describe '#local?' do
  37. it 'returns true when the account is local' do
  38. account = Fabricate(:account, domain: nil)
  39. expect(account.local?).to be true
  40. end
  41. it 'returns false when the account is on a different domain' do
  42. account = Fabricate(:account, domain: 'foreign.tld')
  43. expect(account.local?).to be false
  44. end
  45. end
  46. describe 'Local domain user methods' do
  47. around do |example|
  48. before = Rails.configuration.x.local_domain
  49. example.run
  50. Rails.configuration.x.local_domain = before
  51. end
  52. subject { Fabricate(:account, domain: nil, username: 'alice') }
  53. describe '#to_webfinger_s' do
  54. it 'returns a webfinger string for the account' do
  55. Rails.configuration.x.local_domain = 'example.com'
  56. expect(subject.to_webfinger_s).to eq 'acct:alice@example.com'
  57. end
  58. end
  59. describe '#local_username_and_domain' do
  60. it 'returns the username and local domain for the account' do
  61. Rails.configuration.x.local_domain = 'example.com'
  62. expect(subject.local_username_and_domain).to eq 'alice@example.com'
  63. end
  64. end
  65. end
  66. describe '#acct' do
  67. it 'returns username for local users' do
  68. account = Fabricate(:account, domain: nil, username: 'alice')
  69. expect(account.acct).to eql 'alice'
  70. end
  71. it 'returns username@domain for foreign users' do
  72. account = Fabricate(:account, domain: 'foreign.tld', username: 'alice')
  73. expect(account.acct).to eql 'alice@foreign.tld'
  74. end
  75. end
  76. describe '#save_with_optional_media!' do
  77. it 'sets default avatar, header, avatar_remote_url, and header_remote_url if some of them are invalid' do
  78. stub_request(:get, 'https://remote/valid_avatar').to_return(request_fixture('avatar.txt'))
  79. stub_request(:get, 'https://remote/invalid_avatar').to_return(request_fixture('feed.txt'))
  80. account = Fabricate(:account,
  81. avatar_remote_url: 'https://remote/valid_avatar',
  82. header_remote_url: 'https://remote/valid_avatar')
  83. account.avatar_remote_url = 'https://remote/invalid_avatar'
  84. account.save_with_optional_media!
  85. account.reload
  86. expect(account.avatar_remote_url).to eq ''
  87. expect(account.header_remote_url).to eq ''
  88. expect(account.avatar_file_name).to eq nil
  89. expect(account.header_file_name).to eq nil
  90. end
  91. end
  92. describe '#subscribed?' do
  93. it 'returns false when no subscription expiration information is present' do
  94. account = Fabricate(:account, subscription_expires_at: nil)
  95. expect(account.subscribed?).to be false
  96. end
  97. it 'returns true when subscription expiration has been set' do
  98. account = Fabricate(:account, subscription_expires_at: 30.days.from_now)
  99. expect(account.subscribed?).to be true
  100. end
  101. end
  102. describe '#to_param' do
  103. it 'returns username' do
  104. account = Fabricate(:account, username: 'alice')
  105. expect(account.to_param).to eq 'alice'
  106. end
  107. end
  108. describe '#keypair' do
  109. it 'returns an RSA key pair' do
  110. account = Fabricate(:account)
  111. expect(account.keypair).to be_instance_of OpenSSL::PKey::RSA
  112. end
  113. end
  114. describe '#subscription' do
  115. it 'returns an OStatus subscription' do
  116. account = Fabricate(:account)
  117. expect(account.subscription('')).to be_instance_of OStatus2::Subscription
  118. end
  119. end
  120. describe '#object_type' do
  121. it 'is always a person' do
  122. account = Fabricate(:account)
  123. expect(account.object_type).to be :person
  124. end
  125. end
  126. describe '#favourited?' do
  127. let(:original_status) do
  128. author = Fabricate(:account, username: 'original')
  129. Fabricate(:status, account: author)
  130. end
  131. subject { Fabricate(:account) }
  132. context 'when the status is a reblog of another status' do
  133. let(:original_reblog) do
  134. author = Fabricate(:account, username: 'original_reblogger')
  135. Fabricate(:status, reblog: original_status, account: author)
  136. end
  137. it 'is is true when this account has favourited it' do
  138. Fabricate(:favourite, status: original_reblog, account: subject)
  139. expect(subject.favourited?(original_status)).to eq true
  140. end
  141. it 'is false when this account has not favourited it' do
  142. expect(subject.favourited?(original_status)).to eq false
  143. end
  144. end
  145. context 'when the status is an original status' do
  146. it 'is is true when this account has favourited it' do
  147. Fabricate(:favourite, status: original_status, account: subject)
  148. expect(subject.favourited?(original_status)).to eq true
  149. end
  150. it 'is false when this account has not favourited it' do
  151. expect(subject.favourited?(original_status)).to eq false
  152. end
  153. end
  154. end
  155. describe '#reblogged?' do
  156. let(:original_status) do
  157. author = Fabricate(:account, username: 'original')
  158. Fabricate(:status, account: author)
  159. end
  160. subject { Fabricate(:account) }
  161. context 'when the status is a reblog of another status'do
  162. let(:original_reblog) do
  163. author = Fabricate(:account, username: 'original_reblogger')
  164. Fabricate(:status, reblog: original_status, account: author)
  165. end
  166. it 'is true when this account has reblogged it' do
  167. Fabricate(:status, reblog: original_reblog, account: subject)
  168. expect(subject.reblogged?(original_reblog)).to eq true
  169. end
  170. it 'is false when this account has not reblogged it' do
  171. expect(subject.reblogged?(original_reblog)).to eq false
  172. end
  173. end
  174. context 'when the status is an original status' do
  175. it 'is true when this account has reblogged it' do
  176. Fabricate(:status, reblog: original_status, account: subject)
  177. expect(subject.reblogged?(original_status)).to eq true
  178. end
  179. it 'is false when this account has not reblogged it' do
  180. expect(subject.reblogged?(original_status)).to eq false
  181. end
  182. end
  183. end
  184. describe '#excluded_from_timeline_account_ids' do
  185. it 'includes account ids of blockings, blocked_bys and mutes' do
  186. account = Fabricate(:account)
  187. block = Fabricate(:block, account: account)
  188. mute = Fabricate(:mute, account: account)
  189. block_by = Fabricate(:block, target_account: account)
  190. results = account.excluded_from_timeline_account_ids
  191. expect(results.size).to eq 3
  192. expect(results).to include(block.target_account.id)
  193. expect(results).to include(mute.target_account.id)
  194. expect(results).to include(block_by.account.id)
  195. end
  196. end
  197. describe '#excluded_from_timeline_domains' do
  198. it 'returns the domains blocked by the account' do
  199. account = Fabricate(:account)
  200. account.block_domain!('domain')
  201. expect(account.excluded_from_timeline_domains).to match_array ['domain']
  202. end
  203. end
  204. describe '.search_for' do
  205. before do
  206. _missing = Fabricate(
  207. :account,
  208. display_name: "Missing",
  209. username: "missing",
  210. domain: "missing.com"
  211. )
  212. end
  213. it 'accepts ?, \, : and space as delimiter' do
  214. match = Fabricate(
  215. :account,
  216. display_name: 'A & l & i & c & e',
  217. username: 'username',
  218. domain: 'example.com'
  219. )
  220. results = Account.search_for('A?l\i:c e')
  221. expect(results).to eq [match]
  222. end
  223. it 'finds accounts with matching display_name' do
  224. match = Fabricate(
  225. :account,
  226. display_name: "Display Name",
  227. username: "username",
  228. domain: "example.com"
  229. )
  230. results = Account.search_for("display")
  231. expect(results).to eq [match]
  232. end
  233. it 'finds accounts with matching username' do
  234. match = Fabricate(
  235. :account,
  236. display_name: "Display Name",
  237. username: "username",
  238. domain: "example.com"
  239. )
  240. results = Account.search_for("username")
  241. expect(results).to eq [match]
  242. end
  243. it 'finds accounts with matching domain' do
  244. match = Fabricate(
  245. :account,
  246. display_name: "Display Name",
  247. username: "username",
  248. domain: "example.com"
  249. )
  250. results = Account.search_for("example")
  251. expect(results).to eq [match]
  252. end
  253. it 'limits by 10 by default' do
  254. 11.times.each { Fabricate(:account, display_name: "Display Name") }
  255. results = Account.search_for("display")
  256. expect(results.size).to eq 10
  257. end
  258. it 'accepts arbitrary limits' do
  259. 2.times.each { Fabricate(:account, display_name: "Display Name") }
  260. results = Account.search_for("display", 1)
  261. expect(results.size).to eq 1
  262. end
  263. it 'ranks multiple matches higher' do
  264. matches = [
  265. { username: "username", display_name: "username" },
  266. { display_name: "Display Name", username: "username", domain: "example.com" },
  267. ].map(&method(:Fabricate).curry(2).call(:account))
  268. results = Account.search_for("username")
  269. expect(results).to eq matches
  270. end
  271. end
  272. describe '.advanced_search_for' do
  273. it 'accepts ?, \, : and space as delimiter' do
  274. account = Fabricate(:account)
  275. match = Fabricate(
  276. :account,
  277. display_name: 'A & l & i & c & e',
  278. username: 'username',
  279. domain: 'example.com'
  280. )
  281. results = Account.advanced_search_for('A?l\i:c e', account)
  282. expect(results).to eq [match]
  283. end
  284. it 'limits by 10 by default' do
  285. 11.times { Fabricate(:account, display_name: "Display Name") }
  286. results = Account.search_for("display")
  287. expect(results.size).to eq 10
  288. end
  289. it 'accepts arbitrary limits' do
  290. 2.times { Fabricate(:account, display_name: "Display Name") }
  291. results = Account.search_for("display", 1)
  292. expect(results.size).to eq 1
  293. end
  294. it 'ranks followed accounts higher' do
  295. account = Fabricate(:account)
  296. match = Fabricate(:account, username: "Matching")
  297. followed_match = Fabricate(:account, username: "Matcher")
  298. Fabricate(:follow, account: account, target_account: followed_match)
  299. results = Account.advanced_search_for("match", account)
  300. expect(results).to eq [followed_match, match]
  301. expect(results.first.rank).to be > results.last.rank
  302. end
  303. end
  304. describe '.domains' do
  305. it 'returns domains' do
  306. Fabricate(:account, domain: 'domain')
  307. expect(Account.domains).to match_array(['domain'])
  308. end
  309. end
  310. describe '.triadic_closures' do
  311. let!(:me) { Fabricate(:account) }
  312. let!(:friend) { Fabricate(:account) }
  313. let!(:friends_friend) { Fabricate(:account) }
  314. let!(:both_follow) { Fabricate(:account) }
  315. before do
  316. me.follow!(friend)
  317. friend.follow!(friends_friend)
  318. me.follow!(both_follow)
  319. friend.follow!(both_follow)
  320. end
  321. it 'finds accounts you dont follow which are followed by accounts you do follow' do
  322. expect(described_class.triadic_closures(me)).to eq [friends_friend]
  323. end
  324. it 'limits by 5 with offset 0 by defualt' do
  325. first_degree = 6.times.map { Fabricate(:account) }
  326. matches = 5.times.map { Fabricate(:account) }
  327. first_degree.each { |account| me.follow!(account) }
  328. matches.each do |match|
  329. first_degree.each { |account| account.follow!(match) }
  330. first_degree.shift
  331. end
  332. expect(described_class.triadic_closures(me)).to eq matches
  333. end
  334. it 'accepts arbitrary limits' do
  335. another_friend = Fabricate(:account)
  336. higher_friends_friend = Fabricate(:account)
  337. me.follow!(another_friend)
  338. friend.follow!(higher_friends_friend)
  339. another_friend.follow!(higher_friends_friend)
  340. expect(described_class.triadic_closures(me, limit: 1)).to eq [higher_friends_friend]
  341. end
  342. it 'acceps arbitrary offset' do
  343. another_friend = Fabricate(:account)
  344. higher_friends_friend = Fabricate(:account)
  345. me.follow!(another_friend)
  346. friend.follow!(higher_friends_friend)
  347. another_friend.follow!(higher_friends_friend)
  348. expect(described_class.triadic_closures(me, offset: 1)).to eq [friends_friend]
  349. end
  350. context 'when you block account' do
  351. before do
  352. me.block!(friends_friend)
  353. end
  354. it 'rejects blocked accounts' do
  355. expect(described_class.triadic_closures(me)).to be_empty
  356. end
  357. end
  358. context 'when you mute account' do
  359. before do
  360. me.mute!(friends_friend)
  361. end
  362. it 'rejects muted accounts' do
  363. expect(described_class.triadic_closures(me)).to be_empty
  364. end
  365. end
  366. end
  367. describe '.following_map' do
  368. it 'returns an hash' do
  369. expect(Account.following_map([], 1)).to be_a Hash
  370. end
  371. end
  372. describe '.followed_by_map' do
  373. it 'returns an hash' do
  374. expect(Account.followed_by_map([], 1)).to be_a Hash
  375. end
  376. end
  377. describe '.blocking_map' do
  378. it 'returns an hash' do
  379. expect(Account.blocking_map([], 1)).to be_a Hash
  380. end
  381. end
  382. describe '.requested_map' do
  383. it 'returns an hash' do
  384. expect(Account.requested_map([], 1)).to be_a Hash
  385. end
  386. end
  387. describe 'MENTION_RE' do
  388. subject { Account::MENTION_RE }
  389. it 'matches usernames in the middle of a sentence' do
  390. expect(subject.match('Hello to @alice from me')[1]).to eq 'alice'
  391. end
  392. it 'matches usernames in the beginning of status' do
  393. expect(subject.match('@alice Hey how are you?')[1]).to eq 'alice'
  394. end
  395. it 'matches full usernames' do
  396. expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com'
  397. end
  398. it 'matches full usernames with a dot at the end' do
  399. expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com'
  400. end
  401. it 'matches dot-prepended usernames' do
  402. expect(subject.match('.@alice I want everybody to see this')[1]).to eq 'alice'
  403. end
  404. it 'does not match e-mails' do
  405. expect(subject.match('Drop me an e-mail at alice@example.com')).to be_nil
  406. end
  407. it 'does not match URLs' do
  408. expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil
  409. end
  410. xit 'does not match URL querystring' do
  411. expect(subject.match('https://example.com/?x=@alice')).to be_nil
  412. end
  413. end
  414. describe 'validations' do
  415. it 'has a valid fabricator' do
  416. account = Fabricate.build(:account)
  417. account.valid?
  418. expect(account).to be_valid
  419. end
  420. it 'is invalid without a username' do
  421. account = Fabricate.build(:account, username: nil)
  422. account.valid?
  423. expect(account).to model_have_error_on_field(:username)
  424. end
  425. context 'when is local' do
  426. it 'is invalid if the username is not unique in case-insensitive comparsion among local accounts' do
  427. account_1 = Fabricate(:account, username: 'the_doctor')
  428. account_2 = Fabricate.build(:account, username: 'the_Doctor')
  429. account_2.valid?
  430. expect(account_2).to model_have_error_on_field(:username)
  431. end
  432. it 'is invalid if the username is reserved' do
  433. account = Fabricate.build(:account, username: 'support')
  434. account.valid?
  435. expect(account).to model_have_error_on_field(:username)
  436. end
  437. it 'is valid when username is reserved but record has already been created' do
  438. account = Fabricate.build(:account, username: 'support')
  439. account.save(validate: false)
  440. expect(account.valid?).to be true
  441. end
  442. it 'is invalid if the username doesn\'t only contains letters, numbers and underscores' do
  443. account = Fabricate.build(:account, username: 'the-doctor')
  444. account.valid?
  445. expect(account).to model_have_error_on_field(:username)
  446. end
  447. it 'is invalid if the username is longer then 30 characters' do
  448. account = Fabricate.build(:account, username: Faker::Lorem.characters(31))
  449. account.valid?
  450. expect(account).to model_have_error_on_field(:username)
  451. end
  452. it 'is invalid if the display name is longer than 30 characters' do
  453. account = Fabricate.build(:account, display_name: Faker::Lorem.characters(31))
  454. account.valid?
  455. expect(account).to model_have_error_on_field(:display_name)
  456. end
  457. it 'is invalid if the note is longer than 160 characters' do
  458. account = Fabricate.build(:account, note: Faker::Lorem.characters(161))
  459. account.valid?
  460. expect(account).to model_have_error_on_field(:note)
  461. end
  462. end
  463. context 'when is remote' do
  464. it 'is invalid if the username is not unique in case-sensitive comparison among accounts in the same normalized domain' do
  465. Fabricate(:account, domain: 'にゃん', username: 'username')
  466. account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'username')
  467. account.valid?
  468. expect(account).to model_have_error_on_field(:username)
  469. end
  470. it 'is valid even if the username is unique only in case-sensitive comparison among accounts in the same normalized domain' do
  471. Fabricate(:account, domain: 'にゃん', username: 'username')
  472. account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'Username')
  473. account.valid?
  474. expect(account).not_to model_have_error_on_field(:username)
  475. end
  476. it 'is valid even if the username doesn\'t only contains letters, numbers and underscores' do
  477. account = Fabricate.build(:account, domain: 'domain', username: 'the-doctor')
  478. account.valid?
  479. expect(account).not_to model_have_error_on_field(:username)
  480. end
  481. it 'is valid even if the username is longer then 30 characters' do
  482. account = Fabricate.build(:account, domain: 'domain', username: Faker::Lorem.characters(31))
  483. account.valid?
  484. expect(account).not_to model_have_error_on_field(:username)
  485. end
  486. it 'is valid even if the display name is longer than 30 characters' do
  487. account = Fabricate.build(:account, domain: 'domain', display_name: Faker::Lorem.characters(31))
  488. account.valid?
  489. expect(account).not_to model_have_error_on_field(:display_name)
  490. end
  491. it 'is valid even if the note is longer than 160 characters' do
  492. account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(161))
  493. account.valid?
  494. expect(account).not_to model_have_error_on_field(:note)
  495. end
  496. end
  497. end
  498. describe 'scopes' do
  499. describe 'alphabetic' do
  500. it 'sorts by alphabetic order of domain and username' do
  501. matches = [
  502. { username: 'a', domain: 'a' },
  503. { username: 'b', domain: 'a' },
  504. { username: 'a', domain: 'b' },
  505. { username: 'b', domain: 'b' },
  506. ].map(&method(:Fabricate).curry(2).call(:account))
  507. expect(Account.alphabetic).to eq matches
  508. end
  509. end
  510. describe 'matches_display_name' do
  511. it 'matches display name which starts with the given string' do
  512. match = Fabricate(:account, display_name: 'pattern and suffix')
  513. Fabricate(:account, display_name: 'prefix and pattern')
  514. expect(Account.matches_display_name('pattern')).to eq [match]
  515. end
  516. end
  517. describe 'matches_username' do
  518. it 'matches display name which starts with the given string' do
  519. match = Fabricate(:account, username: 'pattern_and_suffix')
  520. Fabricate(:account, username: 'prefix_and_pattern')
  521. expect(Account.matches_username('pattern')).to eq [match]
  522. end
  523. end
  524. describe 'expiring' do
  525. it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
  526. local = Fabricate(:account, domain: nil)
  527. matches = [
  528. { domain: 'remote', subscription_expires_at: nil },
  529. { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' },
  530. ].map(&method(:Fabricate).curry(2).call(:account))
  531. matches.each(&local.method(:follow!))
  532. Fabricate(:account, domain: 'remote', subscription_expires_at: nil)
  533. local.follow!(Fabricate(:account, domain: 'remote', subscription_expires_at: '2000-01-03T00:00:00Z'))
  534. local.follow!(Fabricate(:account, domain: nil, subscription_expires_at: nil))
  535. expect(Account.expiring('2000-01-02T00:00:00Z').recent).to eq matches.reverse
  536. end
  537. end
  538. describe 'remote' do
  539. it 'returns an array of accounts who have a domain' do
  540. account_1 = Fabricate(:account, domain: nil)
  541. account_2 = Fabricate(:account, domain: 'example.com')
  542. expect(Account.remote).to match_array([account_2])
  543. end
  544. end
  545. describe 'by_domain_accounts' do
  546. it 'returns accounts grouped by domain sorted by accounts' do
  547. 2.times { Fabricate(:account, domain: 'example.com') }
  548. Fabricate(:account, domain: 'example2.com')
  549. results = Account.by_domain_accounts
  550. expect(results.length).to eq 2
  551. expect(results.first.domain).to eq 'example.com'
  552. expect(results.first.accounts_count).to eq 2
  553. expect(results.last.domain).to eq 'example2.com'
  554. expect(results.last.accounts_count).to eq 1
  555. end
  556. end
  557. describe 'local' do
  558. it 'returns an array of accounts who do not have a domain' do
  559. account_1 = Fabricate(:account, domain: nil)
  560. account_2 = Fabricate(:account, domain: 'example.com')
  561. expect(Account.local).to match_array([account_1])
  562. end
  563. end
  564. describe 'partitioned' do
  565. it 'returns a relation of accounts partitioned by domain' do
  566. matches = ['a', 'b', 'a', 'b']
  567. matches.size.times.to_a.shuffle.each do |index|
  568. matches[index] = Fabricate(:account, domain: matches[index])
  569. end
  570. expect(Account.partitioned).to match_array(matches)
  571. end
  572. end
  573. describe 'recent' do
  574. it 'returns a relation of accounts sorted by recent creation' do
  575. matches = 2.times.map { Fabricate(:account) }
  576. expect(Account.recent).to match_array(matches)
  577. end
  578. end
  579. describe 'silenced' do
  580. it 'returns an array of accounts who are silenced' do
  581. account_1 = Fabricate(:account, silenced: true)
  582. account_2 = Fabricate(:account, silenced: false)
  583. expect(Account.silenced).to match_array([account_1])
  584. end
  585. end
  586. describe 'suspended' do
  587. it 'returns an array of accounts who are suspended' do
  588. account_1 = Fabricate(:account, suspended: true)
  589. account_2 = Fabricate(:account, suspended: false)
  590. expect(Account.suspended).to match_array([account_1])
  591. end
  592. end
  593. describe 'without_followers' do
  594. it 'returns a relation of accounts without followers' do
  595. account_1 = Fabricate(:account)
  596. account_2 = Fabricate(:account)
  597. Fabricate(:follow, account: account_1, target_account: account_2)
  598. expect(Account.without_followers).to match_array([account_1])
  599. end
  600. end
  601. describe 'with_followers' do
  602. it 'returns a relation of accounts with followers' do
  603. account_1 = Fabricate(:account)
  604. account_2 = Fabricate(:account)
  605. Fabricate(:follow, account: account_1, target_account: account_2)
  606. expect(Account.with_followers).to match_array([account_2])
  607. end
  608. end
  609. end
  610. context 'when is local' do
  611. it 'generates keys' do
  612. account = Account.create!(domain: nil, username: Faker::Internet.user_name(nil, ['_']))
  613. expect(account.keypair.private?).to eq true
  614. end
  615. end
  616. context 'when is remote' do
  617. it 'does not generate keys' do
  618. key = OpenSSL::PKey::RSA.new(1024).public_key
  619. account = Account.create!(domain: 'remote', username: Faker::Internet.user_name(nil, ['_']), public_key: key.to_pem)
  620. expect(account.keypair.params).to eq key.params
  621. end
  622. it 'normalizes domain' do
  623. account = Account.create!(domain: 'にゃん', username: Faker::Internet.user_name(nil, ['_']))
  624. expect(account.domain).to eq 'xn--r9j5b5b'
  625. end
  626. end
  627. include_examples 'AccountAvatar', :account
  628. end