Fixup rubocop warnings from factory_bot introduction

This commit is contained in:
Jonne Haß 2021-04-11 00:49:44 +02:00
parent 3e6bb01199
commit cc5fca99be
38 changed files with 996 additions and 968 deletions

View file

@ -22,6 +22,7 @@ Although the chat was never enabled per default and was marked as experimental,
* Enable Content-Security-Policy header by default [#7781](https://github.com/diaspora/diaspora/pull/7781)
* Do not show getting started after account import [#8036](https://github.com/diaspora/diaspora/pull/8036)
* Remove the JSXC/Prosody integration [#8069](https://github.com/diaspora/diaspora/pull/8069)
* Replace factory\_girl with factory\_bot [#8218](https://github.com/diaspora/diaspora/pull/8218)
## Bug fixes
* Fix multiple photos upload progress bar [#7655](https://github.com/diaspora/diaspora/pull/7655)

View file

@ -2,14 +2,14 @@
Then /^I should see the "(.*)" message$/ do |message|
text = case message
when "alice is excited"
@alice ||= FactoryBot.create(:user, :username => "Alice")
I18n.translate('invitation_codes.excited', :name => @alice.name)
when "welcome to diaspora"
I18n.translate('users.getting_started.well_hello_there')
else
raise "muriel, you don't have that message key, add one here"
end
when "alice is excited"
@alice ||= FactoryBot.create(:user, username: "Alice")
I18n.translate("invitation_codes.excited", name: @alice.name)
when "welcome to diaspora"
I18n.translate("users.getting_started.well_hello_there")
else
raise "muriel, you don't have that message key, add one here"
end
page.should have_content(text)
end

View file

@ -1,30 +1,30 @@
# frozen_string_literal: true
Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username, password|
@me ||= FactoryBot.create(:user, :username => username, :password => password,
:password_confirmation => password, :getting_started => false)
@me.aspects.create(:name => "Besties")
@me.aspects.create(:name => "Unicorns")
@me ||= FactoryBot.create(:user, username: username, password: password,
password_confirmation: password, getting_started: false)
@me.aspects.create(name: "Besties")
@me.aspects.create(name: "Unicorns")
@me.reload
end
Given /^a user with email "([^\"]*)"$/ do |email|
create_user(:email => email)
create_user(email: email)
end
Given /^a user with username "([^\"]*)"$/ do |username|
create_user(:email => username + "@" + username + '.' + username, :username => username)
create_user(email: username + "@" + username + "." + username, username: username)
end
Given /^a user named "([^\"]*)" with email "([^\"]*)"$/ do |name, email|
first, last = name.split
user = create_user(:email => email, :username => "#{first}_#{last}")
user.profile.update_attributes!(:first_name => first, :last_name => last) if first
user = create_user(email: email, username: "#{first}_#{last}")
user.profile.update!(first_name: first, last_name: last) if first
end
Given /^a nsfw user with email "([^\"]*)"$/ do |email|
user = create_user(:email => email)
user.profile.update_attributes(:nsfw => true)
user = create_user(email: email)
user.profile.update(nsfw: true)
end
Given /^a moderator with email "([^\"]*)"$/ do |email|
@ -39,12 +39,12 @@ end
Given /^(?:|[tT]hat )?following user[s]?(?: exist[s]?)?:$/ do |table|
table.hashes.each do |hash|
if hash.has_key? "username" and hash.has_key? "email"
step %{a user named "#{hash['username']}" with email "#{hash['email']}"}
if hash.has_key?("username") && hash.has_key?("email")
step %(a user named "#{hash['username']}" with email "#{hash['email']}")
elsif hash.has_key? "username"
step %{a user with username "#{hash['username']}"}
step %(a user with username "#{hash['username']}")
elsif hash.has_key? "email"
step %{a user with email "#{hash['email']}"}
step %(a user with email "#{hash['email']}")
end
end
end
@ -58,14 +58,14 @@ end
Given /^I have been invited by "([^\"]+)"$/ do |email|
AppConfig.settings.enable_registrations = false
@inviter = User.find_by_email(email)
@inviter = User.find_by(email: email)
@inviter_invite_count = @inviter.invitation_code.count
i = EmailInviter.new("new_invitee@example.com", @inviter)
i.send!
end
When /^I should see one less invite$/ do
step "I should see \"#{@inviter_invite_count -1} invites left\""
step "I should see \"#{@inviter_invite_count - 1} invites left\""
end
When /^I click on my name$/ do
@ -73,47 +73,55 @@ When /^I click on my name$/ do
end
When /^I have user with username "([^"]*)" in an aspect called "([^"]*)"$/ do |username, aspect|
user = User.find_by_username(username)
user = User.find_by(username: username)
contact = @me.reload.contact_for(user.person)
contact.aspects << @me.aspects.find_by_name(aspect)
contact.aspects << @me.aspects.find_by(name: aspect)
end
Given /^a user with email "([^"]*)" is connected with "([^"]*)"$/ do |arg1, arg2|
user1 = User.where(:email => arg1).first
user2 = User.where(:email => arg2).first
connect_users(user1, user1.aspects.where(:name => "Besties").first, user2, user2.aspects.where(:name => "Besties").first)
user1 = User.where(email: arg1).first
user2 = User.where(email: arg2).first
connect_users(user1, user1.aspects.where(name: "Besties").first, user2, user2.aspects.where(name: "Besties").first)
end
Given /^a user with username "([^"]*)" is connected with "([^"]*)"$/ do |arg1, arg2|
user1 = User.where(:username => arg1).first
user2 = User.where(:username => arg2).first
connect_users(user1, user1.aspects.where(:name => "Besties").first, user2, user2.aspects.where(:name => "Besties").first)
user1 = User.where(username: arg1).first
user2 = User.where(username: arg2).first
connect_users(user1, user1.aspects.where(name: "Besties").first, user2, user2.aspects.where(name: "Besties").first)
end
Given /^there is a user "([^\"]*)" who's tagged "([^\"]*)"$/ do |full_name, tag|
username = full_name.gsub(/\W/, "").underscore
step "a user named \"#{full_name}\" with email \"#{username}@example.com\""
user = User.find_by_username(username)
user = User.find_by(username: username)
user.profile.tag_string = tag
user.profile.build_tags
user.profile.save!
end
Given /^a user with email "([^\"]*)" is tagged "([^\"]*)"$/ do |email, tags|
user = User.find_by_email(email)
user = User.find_by(email: email)
user.profile.tag_string = tags
user.profile.build_tags
user.profile.save!
end
Given /^many posts from alice for bob$/ do
alice = FactoryBot.create(:user_with_aspect, :username => 'alice', :email => 'alice@alice.alice', :password => 'password', :getting_started => false)
bob = FactoryBot.create(:user_with_aspect, :username => 'bob', :email => 'bob@bob.bob', :password => 'password', :getting_started => false)
alice = FactoryBot.create(
:user_with_aspect,
username: "alice", email: "alice@alice.alice", password: "password", getting_started: false
)
bob = FactoryBot.create(
:user_with_aspect,
username: "bob", email: "bob@bob.bob", password: "password", getting_started: false
)
connect_users_with_aspects(alice, bob)
time_fulcrum = Time.now - 40000
time_fulcrum = Time.zone.now - 40_000
time_interval = 1000
(1..30).each do |n|
post = alice.post :status_message, :text => "#{alice.username} - #{n} - #seeded", :to => alice.aspects.where(:name => "generic").first.id
post = alice.post :status_message,
text: "#{alice.username} - #{n} - #seeded",
to: alice.aspects.where(name: "generic").first.id
post.created_at = time_fulcrum - time_interval
post.updated_at = time_fulcrum + time_interval
post.save
@ -122,21 +130,21 @@ Given /^many posts from alice for bob$/ do
end
Then /^I should have (\d) contacts? in "([^"]*)"$/ do |n_contacts, aspect_name|
@me.aspects.where(:name => aspect_name).first.contacts.count.should == n_contacts.to_i
@me.aspects.where(name: aspect_name).first.contacts.count.should == n_contacts.to_i
end
When /^I (?:add|remove) the person (?:to|from) my "([^\"]*)" aspect(?: within "([^"]*)")?$/ do |aspect_name, within_selector| # rubocop:disable Metrics/LineLength
When /^I (?:add|remove) the person (?:to|from) my "([^\"]*)" aspect(?: within "([^"]*)")?$/ do |aspect_name, within_selector| # rubocop:disable Layout/LineLength
with_scope(within_selector) do
toggle_aspect_via_ui(aspect_name)
end
end
When /^I post a status with the text "([^\"]*)"$/ do |text|
@me.post(:status_message, :text => text, :public => true, :to => 'all')
@me.post(:status_message, text: text, public: true, to: "all")
end
When /^I post a limited status with the text "([^\"]*)"$/ do |text|
@me.post(:status_message, :text => text, :public => false, :to => @me.aspect_ids)
@me.post(:status_message, text: text, public: false, to: @me.aspect_ids)
end
And /^I follow the "([^\"]*)" link from the last sent email$/ do |link_text|
@ -144,11 +152,11 @@ And /^I follow the "([^\"]*)" link from the last sent email$/ do |link_text|
email_text = Devise.mailer.deliveries.first.html_part.body.raw_source if email_text.blank?
doc = Nokogiri("<div>" + email_text + "</div>")
links = doc.css('a')
link = links.detect{ |link| link.text == link_text }
link = links.detect{ |link| link.attributes["href"].value.include?(link_text)} unless link
links = doc.css("a")
link = links.find {|link| link.text == link_text }
link ||= links.find {|link| link.attributes["href"].value.include?(link_text) }
path = link.attributes["href"].value
visit URI::parse(path).request_uri
visit URI.parse(path).request_uri
end
Then /^I should have (\d+) Devise email delivery$/ do |n|
@ -170,7 +178,7 @@ Then /^I should( not)? see "([^\"]*)" in the last sent email$/ do |negate, text|
end
When /^"([^\"]+)" has posted a (public )?status message with a photo$/ do |email, public_status|
user = User.find_for_database_authentication(:username => email)
user = User.find_for_database_authentication(username: email)
post = FactoryBot.create(
:status_message_with_photo,
text: "Look at this dog",
@ -200,26 +208,26 @@ Given /^I have (\d+) contacts$/ do |n|
end
people.each do |person|
contacts << Contact.new(:person_id => person.id, :user_id => @me.id, :sharing => true, :receiving => true)
contacts << Contact.new(person_id: person.id, user_id: @me.id, sharing: true, receiving: true)
end
Contact.import(contacts)
contacts = @me.contacts.limit(n.to_i)
aspect_id = @me.aspects.length == 1 ? @me.aspects.first.id : @me.aspects.where(:name => "Besties").first.id
aspect_id = @me.aspects.length == 1 ? @me.aspects.first.id : @me.aspects.where(name: "Besties").first.id
contacts.each do |contact|
aspect_memberships << AspectMembership.new(:contact_id => contact.id, :aspect_id => aspect_id)
aspect_memberships << AspectMembership.new(contact_id: contact.id, aspect_id: aspect_id)
end
AspectMembership.import(aspect_memberships)
end
When /^I view "([^\"]*)"'s first post$/ do |email|
user = User.find_by_email(email)
user = User.find_by(email: email)
post = user.posts.first
visit post_path(post)
end
And /^I should be able to friend "([^\"]*)"$/ do |email|
user = User.find_by_email(email)
user = User.find_by(email: email)
step 'I should see a ".aspect-dropdown"'
step "I should see \"#{user.name}\""
end

View file

@ -1,15 +1,14 @@
# frozen_string_literal: true
module UserCukeHelpers
# creates a new user object from the factory with some default attributes
# and the given override attributes, adds the standard aspects to it
# and returns it
def create_user(overrides={})
default_attrs = {
:password => 'password',
:password_confirmation => 'password',
:getting_started => false
password: "password",
password_confirmation: "password",
getting_started: false
}
user = FactoryBot.create(:user, default_attrs.merge(overrides))
@ -19,21 +18,21 @@ module UserCukeHelpers
# create the default testing aspects for a given user
def add_standard_aspects(user)
user.aspects.create(:name => "Besties")
user.aspects.create(:name => "Unicorns")
user.aspects.create(name: "Besties")
user.aspects.create(name: "Unicorns")
end
# fill out the fields on the sign_in page and press submit
def login_as(user, pass)
fill_in 'user_username', :with=>user
fill_in 'user_password', :with=>pass
fill_in "user_username", with: user
fill_in "user_password", with: pass
click_button "Sign in"
end
# create a new @me user, if not present, and log in using the
# integration_sessions controller (automatic)
def automatic_login
@me ||= FactoryBot.create(:user_with_aspect, :getting_started => false)
@me ||= FactoryBot.create(:user_with_aspect, getting_started: false)
visit(new_integration_sessions_path(user_id: @me.id))
click_button "Login"
end
@ -71,26 +70,26 @@ module UserCukeHelpers
def fill_in_new_user_form
@username = "ohai"
fill_in('user_email', with: "#{@username}@example.com")
fill_in('user_username', with: @username)
fill_in('user_password', with: 'secret')
fill_in('user_password_confirmation', with: 'secret')
fill_in("user_email", with: "#{@username}@example.com")
fill_in("user_username", with: @username)
fill_in("user_password", with: "secret")
fill_in("user_password_confirmation", with: "secret")
# captcha needs to be filled out, because the field is required (HTML5)
# in test env, the captcha will always pass successfully
fill_in('user_captcha', with: '123456')
fill_in("user_captcha", with: "123456")
end
# fill change password section on the user edit page
def fill_change_password_section(cur_pass, new_pass, confirm_pass)
fill_in 'user_current_password', :with => cur_pass
fill_in 'user_password', :with => new_pass
fill_in 'user_password_confirmation', :with => confirm_pass
fill_in "user_current_password", with: cur_pass
fill_in "user_password", with: new_pass
fill_in "user_password_confirmation", with: confirm_pass
end
# fill forgot password form to get reset password link
def fill_forgot_password_form(email)
fill_in 'user_email', :with => email
fill_in "user_email", with: email
end
# submit forgot password form to get reset password link
@ -100,8 +99,8 @@ module UserCukeHelpers
# fill the password reset form
def fill_password_reset_form(new_pass, confirm_pass)
fill_in 'user_password', :with => new_pass
fill_in 'user_password_confirmation', :with => confirm_pass
fill_in "user_password", with: new_pass
fill_in "user_password_confirmation", with: confirm_pass
end
# submit the password reset form
@ -110,8 +109,8 @@ module UserCukeHelpers
end
def confirm_not_signed_up
confirm_on_page('the new user registration page')
confirm_form_validation_error('form#new_user')
confirm_on_page("the new user registration page")
confirm_form_validation_error("form#new_user")
end
def confirm_getting_started_contents

View file

@ -4,7 +4,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe AdminsController, :type => :controller do
describe AdminsController, type: :controller do
before do
@user = FactoryBot.create :user
sign_in @user, scope: :user
@ -47,77 +47,77 @@ describe AdminsController, :type => :controller do
end
end
describe '#user_search' do
context 'admin not signed in' do
it 'is behind redirect_unless_admin' do
describe "#user_search" do
context "admin not signed in" do
it "is behind redirect_unless_admin" do
get :user_search
expect(response).to redirect_to stream_path
end
end
context 'admin signed in' do
context "admin signed in" do
before do
Role.add_admin(@user.person)
end
it 'succeeds and renders user_search' do
it "succeeds and renders user_search" do
get :user_search
expect(response).to be_successful
expect(response).to render_template(:user_search)
end
it 'assigns users to an empty array if nothing is searched for' do
it "assigns users to an empty array if nothing is searched for" do
get :user_search
expect(assigns[:users]).to eq([])
end
it 'searches on username' do
it "searches on username" do
get :user_search, params: {admins_controller_user_search: {username: @user.username}}
expect(assigns[:users]).to eq([@user])
end
it 'searches on email' do
it "searches on email" do
get :user_search, params: {admins_controller_user_search: {email: @user.email}}
expect(assigns[:users]).to eq([@user])
end
it 'searches on age < 13 (COPPA)' do
u_13 = FactoryBot.create(:user)
u_13.profile.birthday = 10.years.ago.to_date
u_13.profile.save!
it "searches on age < 13 (COPPA)" do
under13 = FactoryBot.create(:user)
under13.profile.birthday = 10.years.ago.to_date
under13.profile.save!
o_13 = FactoryBot.create(:user)
o_13.profile.birthday = 20.years.ago.to_date
o_13.profile.save!
over13 = FactoryBot.create(:user)
over13.profile.birthday = 20.years.ago.to_date
over13.profile.save!
get :user_search, params: {admins_controller_user_search: {under13: "1"}}
expect(assigns[:users]).to include(u_13)
expect(assigns[:users]).not_to include(o_13)
expect(assigns[:users]).to include(under13)
expect(assigns[:users]).not_to include(over13)
end
end
end
describe '#admin_inviter' do
context 'admin not signed in' do
it 'is behind redirect_unless_admin' do
describe "#admin_inviter" do
context "admin not signed in" do
it "is behind redirect_unless_admin" do
get :admin_inviter
expect(response).to redirect_to stream_path
end
end
context 'admin signed in' do
context "admin signed in" do
before do
Role.add_admin(@user.person)
end
it 'does not die if you do it twice' do
it "does not die if you do it twice" do
get :admin_inviter, params: {identifier: "bob@moms.com"}
get :admin_inviter, params: {identifier: "bob@moms.com"}
expect(response).to be_redirect
end
it 'invites a new user' do
it "invites a new user" do
expect(EmailInviter).to receive(:new).and_return(double.as_null_object)
get :admin_inviter, params: {identifier: "bob@moms.com"}
expect(response).to redirect_to user_search_path
@ -132,7 +132,7 @@ describe AdminsController, :type => :controller do
end
end
describe '#stats' do
describe "#stats" do
before do
Role.add_admin(@user.person)
end
@ -149,7 +149,7 @@ describe AdminsController, :type => :controller do
end
it "succeeds and renders stats for different ranges" do
%w(week 2weeks month).each do |range|
%w[week 2weeks month].each do |range|
get :stats, params: {range: range}
expect(response).to be_successful
expect(response).to render_template(:stats)

View file

@ -1,17 +1,17 @@
# frozen_string_literal: true
describe NotificationsController, :type => :controller do
describe '#index' do
describe NotificationsController, type: :controller do
describe "#index" do
before do
sign_in alice, scope: :user
@post = FactoryBot.create(:status_message)
FactoryBot.create(:notification, :recipient => alice, :target => @post)
FactoryBot.create(:notification, recipient: alice, target: @post)
get :read_all
FactoryBot.create(:notification, :recipient => alice, :target => @post)
FactoryBot.create(:notification, recipient: alice, target: @post)
eve.share_with(alice.person, eve.aspects.first)
end
it "generates a jasmine fixture", :fixture => true do
it "generates a jasmine fixture", fixture: true do
get :index
save_fixture(html_for("body"), "notifications")
get :index, format: :json

View file

@ -21,7 +21,7 @@ describe StreamsController, :type => :controller do
Timecop.travel(time += 1.minute)
posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
Timecop.travel(time += 1.minute)
posts << alice.post(:reshare, :root_guid => FactoryBot.create(:status_message, :public => true).guid, :to => 'all')
posts << alice.post(:reshare, root_guid: FactoryBot.create(:status_message, public: true).guid, to: "all")
Timecop.travel(time += 1.minute)
if i == 9
posts << alice.post(:status_message,

View file

@ -4,27 +4,27 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe NotificationsController, :type => :controller do
describe NotificationsController, type: :controller do
before do
sign_in alice, scope: :user
end
describe '#update' do
it 'marks a notification as read if it gets no other information' do
describe "#update" do
it "marks a notification as read if it gets no other information" do
note = FactoryBot.create(:notification)
expect(Notification).to receive(:where).and_return([note])
expect(note).to receive(:set_read_state).with(true)
get :update, params: {id: note.id}, format: :json
end
it 'marks a notification as read if it is told to' do
it "marks a notification as read if it is told to" do
note = FactoryBot.create(:notification)
expect(Notification).to receive(:where).and_return([note])
expect(note).to receive(:set_read_state).with(true)
get :update, params: {id: note.id, set_unread: "false"}, format: :json
end
it 'marks a notification as unread if it is told to' do
it "marks a notification as unread if it is told to" do
note = FactoryBot.create(:notification)
expect(Notification).to receive(:where).and_return([note])
expect(note).to receive(:set_read_state).with(false)
@ -44,11 +44,11 @@ describe NotificationsController, :type => :controller do
expect(updated_note.updated_at.iso8601).to eq(note.updated_at.iso8601)
end
it 'only lets you read your own notifications' do
it "only lets you read your own notifications" do
user2 = bob
FactoryBot.create(:notification, :recipient => alice)
note = FactoryBot.create(:notification, :recipient => user2)
FactoryBot.create(:notification, recipient: alice)
note = FactoryBot.create(:notification, recipient: user2)
get :update, params: {id: note.id, set_unread: "false"}, format: :json
@ -56,13 +56,13 @@ describe NotificationsController, :type => :controller do
end
end
describe '#index' do
describe "#index" do
before do
@post = FactoryBot.create(:status_message)
@notification = FactoryBot.create(:notification, recipient: alice, target: @post)
end
it 'succeeds' do
it "succeeds" do
get :index
expect(response).to be_successful
expect(assigns[:notifications].count).to eq(1)
@ -92,13 +92,13 @@ describe NotificationsController, :type => :controller do
expect(response.body).to match(/note_html/)
end
it 'succeeds on mobile' do
it "succeeds on mobile" do
get :index, format: :mobile
expect(response).to be_successful
end
it 'paginates the notifications' do
25.times { FactoryBot.create(:notification, :recipient => alice, :target => @post) }
it "paginates the notifications" do
25.times { FactoryBot.create(:notification, recipient: alice, target: @post) }
get :index
expect(assigns[:notifications].count).to eq(25)
get :index, params: {page: 2}
@ -106,16 +106,16 @@ describe NotificationsController, :type => :controller do
end
it "supports a limit per_page parameter" do
2.times { FactoryBot.create(:notification, :recipient => alice, :target => @post) }
2.times { FactoryBot.create(:notification, recipient: alice, target: @post) }
get :index, params: {per_page: 2}
expect(assigns[:notifications].count).to eq(2)
end
describe "special case for start sharing notifications" do
it "should not provide a contacts menu for standard notifications" do
FactoryBot.create(:notification, :recipient => alice, :target => @post)
FactoryBot.create(:notification, recipient: alice, target: @post)
get :index, params: {per_page: 5}
expect(Nokogiri(response.body).css('.aspect_membership')).to be_empty
expect(Nokogiri(response.body).css(".aspect_membership")).to be_empty
end
it "should provide a contacts menu for start sharing notifications" do
@ -125,7 +125,7 @@ describe NotificationsController, :type => :controller do
expect(Nokogiri(response.body).css(".aspect-membership-dropdown")).not_to be_empty
end
it 'succeeds on mobile' do
it "succeeds on mobile" do
eve.share_with(alice.person, eve.aspects.first)
get :index, format: :mobile
expect(response).to be_successful
@ -134,15 +134,15 @@ describe NotificationsController, :type => :controller do
describe "filter notifications" do
it "supports filtering by notification type" do
FactoryBot.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing")
FactoryBot.create(:notification, recipient: alice, type: "Notifications::StartedSharing")
get :index, params: {type: "started_sharing"}
expect(assigns[:notifications].count).to eq(1)
end
it "supports filtering by read/unread" do
FactoryBot.create(:notification, :recipient => alice, :target => @post)
FactoryBot.create(:notification, recipient: alice, target: @post)
get :read_all
FactoryBot.create(:notification, :recipient => alice, :target => @post)
FactoryBot.create(:notification, recipient: alice, target: @post)
get :index, params: {show: "unread"}
expect(assigns[:notifications].count).to eq(1)
end

View file

@ -4,7 +4,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe PeopleController, :type => :controller do
describe PeopleController, type: :controller do
include_context :gon
before do
@ -13,7 +13,7 @@ describe PeopleController, :type => :controller do
sign_in @user, scope: :user
end
describe '#index (search)' do
describe "#index (search)" do
before do
@eugene = FactoryBot.create(
:person,
@ -30,18 +30,18 @@ describe PeopleController, :type => :controller do
)
end
describe 'via json' do
it 'succeeds' do
describe "via json" do
it "succeeds" do
get :index, params: {q: "Korth"}, format: :json
expect(response).to be_successful
end
it 'responds with json' do
it "responds with json" do
get :index, params: {q: "Korth"}, format: :json
expect(response.body).to eq([@korth].to_json)
end
it 'does not assign hashes' do
it "does not assign hashes" do
get :index, params: {q: "Korth"}, format: :json
expect(assigns[:hashes]).to be_nil
end
@ -54,29 +54,32 @@ describe PeopleController, :type => :controller do
end
end
describe 'via html' do
context 'query is a diaspora ID' do
describe "via html" do
context "query is a diaspora ID" do
before do
@unsearchable_eugene = FactoryBot.create(:person, :diaspora_handle => "eugene@example.org",
:profile => FactoryBot.build(:profile, :first_name => "Eugene",
:last_name => "w", :searchable => false))
@unsearchable_eugene = FactoryBot.create(
:person,
diaspora_handle: "eugene@example.org",
profile: FactoryBot.build(:profile, first_name: "Eugene", last_name: "w", searchable: false)
)
end
it 'finds people even if they have searchable off' do
it "finds people even if they have searchable off" do
get :index, params: {q: "eugene@example.org"}
expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id)
end
it 'downcases the query term' do
it "downcases the query term" do
get :index, params: {q: "Eugene@Example.ORG"}
expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id)
end
it 'does not the background query task if the user is found' do
it "does not the background query task if the user is found" do
get :index, params: {q: "Eugene@Example.ORG"}
expect(assigns[:background_query]).to eq(nil)
end
it 'sets background query task if the user is not found' do
it "sets background query task if the user is not found" do
get :index, params: {q: "Eugene@Example1.ORG"}
expect(assigns[:background_query]).to eq("eugene@example1.org")
end
@ -87,23 +90,23 @@ describe PeopleController, :type => :controller do
end
end
context 'query is not a tag or a diaspora ID' do
it 'assigns hashes' do
context "query is not a tag or a diaspora ID" do
it "assigns hashes" do
get :index, params: {q: "Korth"}
expect(assigns[:hashes]).not_to be_nil
end
it 'does not set the background query task' do
it "does not set the background query task" do
get :index, params: {q: "Korth"}
expect(assigns[:background_query]).not_to be_present
end
it "assigns people" do
eugene2 = FactoryBot.create(:person,
:profile => FactoryBot.build(:profile, :first_name => "Eugene",
:last_name => "w"))
profile: FactoryBot.build(:profile, first_name: "Eugene",
last_name: "w"))
get :index, params: {q: "Eug"}
expect(assigns[:people].map { |x| x.id }).to match_array([@eugene.id, eugene2.id])
expect(assigns[:people].map(&:id)).to match_array([@eugene.id, eugene2.id])
end
it "succeeds if there is exactly one match" do
@ -118,20 +121,20 @@ describe PeopleController, :type => :controller do
expect(response).to be_successful
end
it 'succeeds if you search for the empty term' do
it "succeeds if you search for the empty term" do
get :index, params: {q: ""}
expect(response).to be_successful
end
it 'succeeds if you search for punctuation' do
it "succeeds if you search for punctuation" do
get :index, params: {q: "+"}
expect(response).to be_successful
end
it "excludes people who have searchable off" do
eugene2 = FactoryBot.create(:person,
:profile => FactoryBot.build(:profile, :first_name => "Eugene",
:last_name => "w", :searchable => false))
profile: FactoryBot.build(:profile, first_name: "Eugene",
last_name: "w", searchable: false))
get :index, params: {q: "Eug"}
expect(assigns[:people]).not_to match_array([eugene2])
end
@ -144,18 +147,18 @@ describe PeopleController, :type => :controller do
end
end
describe "#show performance", :performance => true do
describe "#show performance", performance: true do
before do
require 'benchmark'
require "benchmark"
@posts = []
@users = []
8.times do |n|
user = FactoryBot.create(:user)
@users << user
aspect = user.aspects.create(:name => 'people')
aspect = user.aspects.create(name: "people")
connect_users(@user, @user.aspects.first, user, aspect)
@posts << @user.post(:status_message, :text => "hello#{n}", :to => aspect.id)
@posts << @user.post(:status_message, text: "hello#{n}", to: aspect.id)
end
@posts.each do |post|
@users.each do |user|
@ -164,14 +167,14 @@ describe PeopleController, :type => :controller do
end
end
it 'takes time' do
it "takes time" do
expect(Benchmark.realtime {
get :show, params: {id: @user.person.to_param}
}).to be < 1.0
end
end
describe '#show' do
describe "#show" do
before do
@person = FactoryBot.create(:user).person
@presenter = PersonPresenter.new(@person, @user)
@ -198,7 +201,7 @@ describe PeopleController, :type => :controller do
expect(assigns(:presenter).to_json).to eq(@presenter.to_json)
end
it 'finds a person via username' do
it "finds a person via username" do
get :show, params: {username: @person.username}
expect(assigns(:presenter).to_json).to eq(@presenter.to_json)
end
@ -208,35 +211,35 @@ describe PeopleController, :type => :controller do
expect(response.code).to eq("404")
end
it 'finds a person via diaspora handle' do
it "finds a person via diaspora handle" do
get :show, params: {username: @person.diaspora_handle}
expect(assigns(:presenter).to_json).to eq(@presenter.to_json)
end
it 'redirects home for closed account' do
@person = FactoryBot.create(:person, :closed_account => true)
it "redirects home for closed account" do
@person = FactoryBot.create(:person, closed_account: true)
get :show, params: {id: @person.to_param}
expect(response).to be_redirect
expect(flash[:notice]).not_to be_blank
end
it 'does not allow xss attacks' do
it "does not allow xss attacks" do
user2 = bob
profile = user2.profile
profile.update_attribute(:first_name, "</script><script> alert('xss attack');</script>")
profile.update(first_name: "</script><script> alert('xss attack');</script>")
get :show, params: {id: user2.person.to_param}
expect(response).to be_successful
expect(response.body).not_to include(profile.first_name)
end
it "displays the correct number of photos" do
16.times do |i|
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
16.times do |_i|
eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: true)
end
get :show, params: {id: eve.person.to_param}
expect(response.body).to include ',"photos_count":16'
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: false)
get :show, params: {id: eve.person.to_param}
expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice
end
@ -247,7 +250,7 @@ describe PeopleController, :type => :controller do
expect(response).to be_successful
end
it 'succeeds on the mobile site' do
it "succeeds on the mobile site" do
get :show, params: {id: @user.person.to_param}, format: :mobile
expect(response).to be_successful
end
@ -269,12 +272,12 @@ describe PeopleController, :type => :controller do
expect(response.status).to eq(200)
end
it 'succeeds on the mobile site' do
it "succeeds on the mobile site" do
get :show, params: {id: @person.to_param}, format: :mobile
expect(response).to be_successful
end
it 'forces to sign in if the person is remote' do
it "forces to sign in if the person is remote" do
p = FactoryBot.create(:person)
get :show, params: {id: p.to_param}
@ -319,18 +322,18 @@ describe PeopleController, :type => :controller do
expect(response).to be_successful
end
it 'succeeds on the mobile site' do
it "succeeds on the mobile site" do
get :show, params: {id: @person.to_param}, format: :mobile
expect(response).to be_successful
end
it 'marks a corresponding notifications as read' do
note = FactoryBot.create(:notification, :recipient => @user, :target => @person, :unread => true)
it "marks a corresponding notifications as read" do
note = FactoryBot.create(:notification, recipient: @user, target: @person, unread: true)
expect {
get :show, params: {id: @person.to_param}
note.reload
}.to change(Notification.where(:unread => true), :count).by(-1)
}.to change(Notification.where(unread: true), :count).by(-1)
end
it "includes private profile info" do
@ -354,7 +357,7 @@ describe PeopleController, :type => :controller do
expect(response).to be_successful
end
it 'succeeds on the mobile site' do
it "succeeds on the mobile site" do
get :show, params: {id: @person.to_param}, format: :mobile
expect(response).to be_successful
end
@ -384,7 +387,7 @@ describe PeopleController, :type => :controller do
end
end
describe '#stream' do
describe "#stream" do
it "redirects non-json requests" do
get :stream, params: {person_id: @user.person.to_param}
expect(response).to be_redirect
@ -393,17 +396,17 @@ describe PeopleController, :type => :controller do
context "person is current user" do
it "assigns all the user's posts" do
expect(@user.posts).to be_empty
@user.post(:status_message, :text => "to one aspect", :to => @aspect.id)
@user.post(:status_message, :text => "to all aspects", :to => 'all')
@user.post(:status_message, :text => "public", :to => 'all', :public => true)
@user.post(:status_message, text: "to one aspect", to: @aspect.id)
@user.post(:status_message, text: "to all aspects", to: "all")
@user.post(:status_message, text: "public", to: "all", public: true)
expect(@user.reload.posts.length).to eq(3)
get :stream, params: {person_id: @user.person.to_param}, format: :json
expect(assigns(:stream).posts.map(&:id)).to match_array(@user.posts.map(&:id))
end
it "renders the comments on the user's posts" do
cmmt = 'I mean it'
message = @user.post :status_message, :text => 'test more', :to => @aspect.id
cmmt = "I mean it"
message = @user.post :status_message, text: "test more", to: @aspect.id
@user.comment!(message, cmmt)
get :stream, params: {person_id: @user.person.to_param}, format: :json
expect(response).to be_successful
@ -417,20 +420,21 @@ describe PeopleController, :type => :controller do
end
it "includes reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => FactoryBot.create(:status_message, :public => true).guid, :to => alice.aspect_ids)
reshare = @user.post(:reshare, public: true,
root_guid: FactoryBot.create(:status_message, public: true).guid, to: alice.aspect_ids)
get :stream, params: {person_id: @user.person.to_param}, format: :json
expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id)
expect(assigns[:stream].posts.map(&:id)).to include(reshare.id)
end
it "assigns only the posts the current user can see" do
expect(bob.posts).to be_empty
posts_user_can_see = []
aspect_user_is_in = bob.aspects.where(:name => "generic").first
aspect_user_is_not_in = bob.aspects.where(:name => "empty").first
posts_user_can_see << bob.post(:status_message, :text => "to an aspect @user is in", :to => aspect_user_is_in.id)
bob.post(:status_message, :text => "to an aspect @user is not in", :to => aspect_user_is_not_in.id)
posts_user_can_see << bob.post(:status_message, :text => "to all aspects", :to => 'all')
posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
aspect_user_is_in = bob.aspects.where(name: "generic").first
aspect_user_is_not_in = bob.aspects.where(name: "empty").first
posts_user_can_see << bob.post(:status_message, text: "to an aspect @user is in", to: aspect_user_is_in.id)
bob.post(:status_message, text: "to an aspect @user is not in", to: aspect_user_is_not_in.id)
posts_user_can_see << bob.post(:status_message, text: "to all aspects", to: "all")
posts_user_can_see << bob.post(:status_message, text: "public", to: "all", public: true)
expect(bob.reload.posts.length).to eq(4)
get :stream, params: {person_id: @person.to_param}, format: :json
@ -445,9 +449,9 @@ describe PeopleController, :type => :controller do
it "assigns only public posts" do
expect(eve.posts).to be_empty
eve.post(:status_message, :text => "to an aspect @user is not in", :to => eve.aspects.first.id)
eve.post(:status_message, :text => "to all aspects", :to => 'all')
public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true)
eve.post(:status_message, text: "to an aspect @user is not in", to: eve.aspects.first.id)
eve.post(:status_message, text: "to all aspects", to: "all")
public_post = eve.post(:status_message, text: "public", to: "all", public: true)
expect(eve.reload.posts.length).to eq(3)
get :stream, params: {person_id: @person.to_param}, format: :json
@ -455,9 +459,10 @@ describe PeopleController, :type => :controller do
end
it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => FactoryBot.create(:status_message, :public => true).guid, :to => alice.aspect_ids)
reshare = @user.post(:reshare, public: true,
root_guid: FactoryBot.create(:status_message, public: true).guid, to: alice.aspect_ids)
get :stream, params: {person_id: @user.person.to_param}, format: :json
expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id)
expect(assigns[:stream].posts.map(&:id)).to include(reshare.id)
end
end
@ -467,21 +472,22 @@ describe PeopleController, :type => :controller do
@person = bob.person
end
context 'with posts' do
context "with posts" do
before do
@public_posts = []
@public_posts << bob.post(:status_message, :text => "first public ", :to => bob.aspects[0].id, :public => true)
bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id)
bob.post(:status_message, :text => "to all aspects", :to => 'all')
@public_posts << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
@public_posts << bob.post(:status_message, text: "first public ", to: bob.aspects[0].id, public: true)
bob.post(:status_message, text: "to an aspect @user is not in", to: bob.aspects[1].id)
bob.post(:status_message, text: "to all aspects", to: "all")
@public_posts << bob.post(:status_message, text: "public", to: "all", public: true)
@public_posts.first.created_at -= 1000
@public_posts.first.save
end
it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => FactoryBot.create(:status_message, :public => true).guid, :to => alice.aspect_ids)
reshare = @user.post(:reshare, public: true,
root_guid: FactoryBot.create(:status_message, public: true).guid, to: alice.aspect_ids)
get :stream, params: {person_id: @user.person.to_param}, format: :json
expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id)
expect(assigns[:stream].posts.map(&:id)).to include(reshare.id)
end
it "assigns only public posts" do
@ -489,27 +495,27 @@ describe PeopleController, :type => :controller do
expect(assigns[:stream].posts.map(&:id)).to match_array(@public_posts.map(&:id))
end
it 'is sorted by created_at desc' do
it "is sorted by created_at desc" do
get :stream, params: {person_id: @person.to_param}, format: :json
expect(assigns[:stream].stream_posts).to eq(@public_posts.sort_by { |p| p.created_at }.reverse)
expect(assigns[:stream].stream_posts).to eq(@public_posts.sort_by(&:created_at).reverse)
end
end
end
end
describe '#hovercard' do
describe "#hovercard" do
before do
@hover_test = FactoryBot.create(:person)
@hover_test.profile.tag_string = '#test #tags'
@hover_test.profile.tag_string = "#test #tags"
@hover_test.profile.save!
end
it 'redirects html requests' do
it "redirects html requests" do
get :hovercard, params: {person_id: @hover_test.guid}
expect(response).to redirect_to person_path(:id => @hover_test.guid)
expect(response).to redirect_to person_path(id: @hover_test.guid)
end
it 'returns json with profile stuff' do
it "returns json with profile stuff" do
get :hovercard, params: {person_id: @hover_test.guid}, format: :json
expect(JSON.parse(response.body)["diaspora_id"]).to eq(@hover_test.diaspora_handle)
end
@ -540,8 +546,8 @@ describe PeopleController, :type => :controller do
end
end
describe '#refresh_search ' do
before(:each)do
describe "#refresh_search " do
before(:each) do
@eugene = FactoryBot.create(
:person,
profile: FactoryBot.build(:profile, first_name: "Eugene", last_name: "w")
@ -580,36 +586,36 @@ describe PeopleController, :type => :controller do
end
end
describe '#diaspora_id?' do
it 'returns true for pods on urls' do
describe "#diaspora_id?" do
it "returns true for pods on urls" do
expect(@controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de")).to be true
end
it 'returns true for pods on urls with port' do
it "returns true for pods on urls with port" do
expect(@controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de:12314")).to be true
end
it 'returns true for pods on localhost' do
it "returns true for pods on localhost" do
expect(@controller.send(:diaspora_id?, "ilya_123@localhost")).to be true
end
it 'returns true for pods on localhost and port' do
it "returns true for pods on localhost and port" do
expect(@controller.send(:diaspora_id?, "ilya_123@localhost:1234")).to be true
end
it 'returns true for pods on ip' do
it "returns true for pods on ip" do
expect(@controller.send(:diaspora_id?, "ilya_123@1.1.1.1")).to be true
end
it 'returns true for pods on ip and port' do
it "returns true for pods on ip and port" do
expect(@controller.send(:diaspora_id?, "ilya_123@1.2.3.4:1234")).to be true
end
it 'returns false for pods on with invalid url characters' do
it "returns false for pods on with invalid url characters" do
expect(@controller.send(:diaspora_id?, "ilya_123@join_diaspora.com")).to be false
end
it 'returns false for invalid usernames' do
it "returns false for invalid usernames" do
expect(@controller.send(:diaspora_id?, "ilya_2%3@joindiaspora.com")).to be false
end
end

View file

@ -1,34 +1,34 @@
# frozen_string_literal: true
describe ResharesController, :type => :controller do
describe '#create' do
describe ResharesController, type: :controller do
describe "#create" do
let(:post_request!) {
post :create, params: {root_guid: @post_guid}, format: :json
}
before do
@post = FactoryBot.create(:status_message, :public => true)
@post = FactoryBot.create(:status_message, public: true)
@post_guid = @post.guid
end
it 'requires authentication' do
it "requires authentication" do
post_request!
expect(response).not_to be_successful
end
context 'with an authenticated user' do
context "with an authenticated user" do
before do
sign_in(bob, scope: :user)
allow(@controller).to receive(:current_user).and_return(bob)
end
it 'succeeds' do
it "succeeds" do
expect(response).to be_successful
post_request!
end
it 'creates a reshare' do
expect{
it "creates a reshare" do
expect {
post_request!
}.to change(Reshare, :count).by(1)
end
@ -39,25 +39,25 @@ describe ResharesController, :type => :controller do
post_request!
end
context 'resharing a reshared post' do
context "resharing a reshared post" do
before do
FactoryBot.create(:reshare, :root => @post, :author => bob.person)
FactoryBot.create(:reshare, root: @post, author: bob.person)
end
it 'doesn\'t allow the user to reshare the post again' do
it "doesn't allow the user to reshare the post again" do
post_request!
expect(response.code).to eq('422')
expect(response.code).to eq("422")
expect(response.body).to eq(I18n.t("reshares.create.error"))
end
end
context 'resharing another user\'s reshare' do
context "resharing another user's reshare" do
before do
@root = @post
@post = FactoryBot.create(:reshare, :root => @root, :author => alice.person)
@post = FactoryBot.create(:reshare, root: @root, author: alice.person)
end
it 'reshares the absolute root' do
it "reshares the absolute root" do
post_request!
expect(@post.reshares.count).to eq(0)
expect(@root.reshares.count).to eq(2)

View file

@ -118,7 +118,7 @@ describe ServicesController, :type => :controller do
describe '#destroy' do
before do
@service1 = FactoryBot.create(:service, :user => user)
@service1 = FactoryBot.create(:service, user: user)
end
it 'destroys a service selected by id' do

View file

@ -85,18 +85,22 @@ describe UsersController, :type => :controller do
end
end
it 'includes reshares in the atom feed' do
reshare = FactoryBot.create(:reshare, :author => @user.person)
it "includes reshares in the atom feed" do
reshare = FactoryBot.create(:reshare, author: @user.person)
get :public, params: {username: @user.username}, format: :atom
expect(response.body).to include reshare.root.text
end
it 'do not show reshares in atom feed if origin post is deleted' do
post = FactoryBot.create(:status_message, :public => true);
reshare = FactoryBot.create(:reshare, :root => post, :author => @user.person)
it "do not show reshares in atom feed if origin post is deleted" do
post = FactoryBot.create(:status_message, public: true)
FactoryBot.create(:reshare, root: post, author: @user.person)
post.delete
get :public, params: {username: @user.username}, format: :atom
expect(response.code).to eq('200')
expect(response.code).to eq("200")
end
it 'redirects to a profile page if html is requested' do

View file

@ -4,10 +4,6 @@
# licensed under the Affero General Public License version 3 or late See
# the COPYRIGHT file.
#For Guidance
#http://github.com/thoughtbot/factory_girl
# http://railscasts.com/episodes/158-factories-not-fixtures
def r_str
SecureRandom.hex(3)
end
@ -16,23 +12,23 @@ require "diaspora_federation/test/factories"
FactoryBot.define do
factory :profile do
sequence(:first_name) { |n| "Robert#{n}#{r_str}" }
sequence(:last_name) { |n| "Grimm#{n}#{r_str}" }
sequence(:first_name) {|n| "Robert#{n}#{r_str}" }
sequence(:last_name) {|n| "Grimm#{n}#{r_str}" }
bio { "I am a cat lover and I love to run" }
gender { "robot" }
location { "Earth" }
birthday { Date.today }
birthday { Time.zone.today }
tag_string { "#one #two" }
association :person
end
factory :profile_with_image_url, :parent => :profile do
factory :profile_with_image_url, parent: :profile do
image_url { "http://example.com/image.jpg" }
image_url_medium { "http://example.com/image_mid.jpg" }
image_url_small { "http://example.com/image_small.jpg" }
end
factory(:person, aliases: %i(author)) do
factory(:person, aliases: %i[author]) do
transient do
first_name { nil }
end
@ -41,7 +37,7 @@ FactoryBot.define do
pod { Pod.find_or_create_by(url: "http://example.net") }
serialized_public_key { OpenSSL::PKey::RSA.generate(1024).public_key.export }
after(:build) do |person, evaluator|
unless person.profile.first_name.present?
if person.profile.first_name.blank?
person.profile = FactoryBot.build(:profile, person: person)
person.profile.first_name = evaluator.first_name if evaluator.first_name
end
@ -61,25 +57,25 @@ FactoryBot.define do
end
factory :like do
association :author, :factory => :person
association :target, :factory => :status_message
association :author, factory: :person
association :target, factory: :status_message
end
factory :user do
getting_started { false }
sequence(:username) { |n| "bob#{n}#{r_str}" }
sequence(:email) { |n| "bob#{n}#{r_str}@pivotallabs.com" }
sequence(:username) {|n| "bob#{n}#{r_str}" }
sequence(:email) {|n| "bob#{n}#{r_str}@pivotallabs.com" }
password { "bluepin7" }
password_confirmation { |u| u.password }
serialized_private_key { OpenSSL::PKey::RSA.generate(1024).export }
password_confirmation(&:password)
serialized_private_key { OpenSSL::PKey::RSA.generate(1024).export }
transient do
profile { nil }
end
after(:build) do |u, e|
u.person = FactoryBot.build(:person,
pod: nil,
serialized_public_key: u.encryption_key.public_key.export,
diaspora_handle: "#{u.username}#{User.diaspora_id_host}")
pod: nil,
serialized_public_key: u.encryption_key.public_key.export,
diaspora_handle: "#{u.username}#{User.diaspora_id_host}")
u.person.profile = e.profile if e.profile
end
after(:create) do |u|
@ -106,7 +102,7 @@ FactoryBot.define do
user
end
factory(:status_message, aliases: %i(status_message_without_participation)) do
factory(:status_message, aliases: %i[status_message_without_participation]) do
sequence(:text) {|n| "jimmy's #{n} whales" }
author
@ -136,7 +132,7 @@ FactoryBot.define do
end
factory(:status_message_in_aspect) do
public { false }
public { false } # rubocop:disable Layout/EmptyLinesAroundAccessModifier
author { FactoryBot.create(:user_with_aspect).person }
after(:build) do |sm|
sm.aspects << sm.author.owner.aspects.first
@ -202,51 +198,51 @@ FactoryBot.define do
end
factory(:photo) do
sequence(:random_string) {|n| SecureRandom.hex(10) }
association :author, :factory => :person
sequence(:random_string) { SecureRandom.hex(10) }
association :author, factory: :person
height { 42 }
width { 23 }
after(:build) do |p|
p.unprocessed_image.store! File.open(File.join(File.dirname(__FILE__), 'fixtures', 'button.png'))
p.unprocessed_image.store! File.open(File.join(File.dirname(__FILE__), "fixtures", "button.png"))
p.update_remote_path
end
end
factory(:remote_photo, :parent => :photo) do
remote_photo_path { 'https://photo.com/images/' }
remote_photo_name { 'kittehs.jpg' }
association :author,:factory => :person
factory(:remote_photo, parent: :photo) do
remote_photo_path { "https://photo.com/images/" }
remote_photo_name { "kittehs.jpg" }
association :author, factory: :person
processed_image { nil }
unprocessed_image { nil }
end
factory :reshare do
association(:root, :public => true, :factory => :status_message)
association(:author, :factory => :person)
association(:root, public: true, factory: :status_message)
association(:author, factory: :person)
end
factory :invitation do
service { "email" }
identifier { "bob.smith@smith.com" }
association :sender, :factory => :user_with_aspect
association :sender, factory: :user_with_aspect
after(:build) do |i|
i.aspect = i.sender.aspects.first
end
end
factory :invitation_code do
sequence(:token){|n| "sdfsdsf#{n}"}
sequence(:token) {|n| "sdfsdsf#{n}" }
association :user
count { 0 }
end
factory :service do |service|
factory :service do
nickname { "sirrobertking" }
type { "Services::Twitter" }
sequence(:uid) { |token| "00000#{token}" }
sequence(:access_token) { |token| "12345#{token}" }
sequence(:access_secret) { |token| "98765#{token}" }
sequence(:uid) {|token| "00000#{token}" }
sequence(:access_token) {|token| "12345#{token}" }
sequence(:access_secret) {|token| "98765#{token}" }
user
end
@ -257,7 +253,7 @@ FactoryBot.define do
end
factory(:comment) do
sequence(:text) {|n| "#{n} cats"}
sequence(:text) {|n| "#{n} cats" }
association(:author, factory: :person)
association(:post, factory: :status_message)
end
@ -277,8 +273,8 @@ FactoryBot.define do
end
factory(:notification, class: Notifications::AlsoCommented) do
association :recipient, :factory => :user
association :target, :factory => :comment
association :recipient, factory: :user
association :target, factory: :comment
after(:build) do |note|
note.actors << FactoryBot.build(:person)
@ -295,7 +291,7 @@ FactoryBot.define do
end
end
factory(:tag, :class => ActsAsTaggableOn::Tag) do
factory(:tag, class: ActsAsTaggableOn::Tag) do
name { "partytimeexcellent" }
end
@ -319,13 +315,13 @@ FactoryBot.define do
end
factory(:tag_following) do
association(:tag, :factory => :tag)
association(:user, :factory => :user)
association(:tag, factory: :tag)
association(:user, factory: :user)
end
factory(:contact) do
association(:person, :factory => :person)
association(:user, :factory => :user)
association(:person, factory: :person)
association(:user, factory: :user)
end
factory(:mention) do
@ -389,7 +385,7 @@ FactoryBot.define do
additional_data { {"new_property" => "some text"} }
end
factory(:note, :parent => :status_message) do
factory(:note, parent: :status_message) do
text { SecureRandom.hex(1000) }
end
@ -408,7 +404,7 @@ FactoryBot.define do
factory :o_auth_application, class: Api::OpenidConnect::OAuthApplication do
client_name { "Diaspora Test Client #{r_str}" }
redirect_uris { %w(http://localhost:3000/) }
redirect_uris { %w[http://localhost:3000/] }
end
factory :o_auth_application_with_ppid, parent: :o_auth_application do
@ -418,7 +414,7 @@ FactoryBot.define do
factory :o_auth_application_with_xss, class: Api::OpenidConnect::OAuthApplication do
client_name { "<script>alert(0);</script>" }
redirect_uris { %w(http://localhost:3000/) }
redirect_uris { %w[http://localhost:3000/] }
end
factory :auth_with_default_scopes, class: Api::OpenidConnect::Authorization do
@ -451,9 +447,11 @@ FactoryBot.define do
factory :auth_with_all_scopes_not_private, class: Api::OpenidConnect::Authorization do
o_auth_application
association :user, factory: :user_with_aspect
scopes { %w[openid sub name nickname profile picture gender birthdate locale updated_at contacts:read contacts:modify
conversations email interactions notifications public:read public:modify profile profile:modify tags:read
tags:modify] }
scopes {
%w[openid sub name nickname profile picture gender birthdate locale updated_at contacts:read contacts:modify
conversations email interactions notifications public:read public:modify profile profile:modify tags:read
tags:modify]
}
after(:build) {|m|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
}
@ -462,8 +460,10 @@ FactoryBot.define do
factory :auth_with_read_scopes, class: Api::OpenidConnect::Authorization do
o_auth_application
association :user, factory: :user_with_aspect
scopes { %w[openid sub name nickname profile picture contacts:read conversations
email interactions notifications private:read public:read profile tags:read] }
scopes {
%w[openid sub name nickname profile picture contacts:read conversations
email interactions notifications private:read public:read profile tags:read]
}
after(:build) {|m|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
}
@ -472,8 +472,10 @@ FactoryBot.define do
factory :auth_with_read_scopes_not_private, class: Api::OpenidConnect::Authorization do
o_auth_application
association :user, factory: :user_with_aspect
scopes { %w[openid sub name nickname profile picture gender contacts:read conversations
email interactions notifications public:read profile tags:read] }
scopes {
%w[openid sub name nickname profile picture gender contacts:read conversations
email interactions notifications public:read profile tags:read]
}
after(:build) {|m|
m.redirect_uri = m.o_auth_application.redirect_uris[0]
}
@ -488,7 +490,8 @@ FactoryBot.define do
exported_key { OpenSSL::PKey::RSA.generate(1024).public_key.export }
profile {
DiasporaFederation::Entities::Profile.new(
FactoryBot.attributes_for(:federation_profile_from_hcard, diaspora_id: diaspora_id))
FactoryBot.attributes_for(:federation_profile_from_hcard, diaspora_id: diaspora_id)
)
}
end

View file

@ -25,7 +25,7 @@ describe ApplicationHelper, :type => :helper do
end
it 'returns true if all networks are connected' do
3.times { |t| @current_user.services << FactoryBot.build(:service) }
3.times { @current_user.services << FactoryBot.build(:service) }
expect(all_services_connected?).to be true
end

View file

@ -24,10 +24,10 @@ def create_undiscovered_user(pod)
FactoryBot.build(:user).tap do |user|
allow(user).to receive(:person).and_return(
FactoryBot.build(:person,
profile: FactoryBot.build(:profile),
serialized_public_key: user.encryption_key.public_key.export,
pod: Pod.find_or_create_by(url: "http://#{pod}"),
diaspora_handle: "#{user.username}@#{pod}")
profile: FactoryBot.build(:profile),
serialized_public_key: user.encryption_key.public_key.export,
pod: Pod.find_or_create_by(url: "http://#{pod}"),
diaspora_handle: "#{user.username}@#{pod}")
)
end
end

View file

@ -7,7 +7,7 @@ require "integration/federation/shared_receive_stream_items"
describe "Receive federation messages feature" do
before do
allow_callbacks(%i(queue_public_receive queue_private_receive receive_entity fetch_related_entity))
allow_callbacks(%i[queue_public_receive queue_private_receive receive_entity fetch_related_entity])
end
let(:sender) { remote_user_on_pod_b }
@ -110,7 +110,8 @@ describe "Receive federation messages feature" do
it "reshare of public post passes" do
post = FactoryBot.create(:status_message, author: alice.person, public: true)
reshare = Fabricate(
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id)
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id
)
expect(Participation::Generator).to receive(:new).with(
alice, instance_of(Reshare)
@ -130,7 +131,8 @@ describe "Receive federation messages feature" do
it "reshare of private post fails" do
post = FactoryBot.create(:status_message, author: alice.person, public: false)
reshare = Fabricate(
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id)
:reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id
)
expect {
post_message(generate_payload(reshare, sender))
}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Only posts which are public may be reshared."

View file

@ -63,7 +63,7 @@ shared_examples_for "messages which are indifferent about sharing fact" do
end
end
%w(comment like).each do |entity|
%w[comment like].each do |entity|
context "with #{entity}" do
let(:entity_name) { "#{entity}_entity".to_sym }
let(:klass) { entity.camelize.constantize }

View file

@ -317,9 +317,9 @@ describe MigrationService do
context "old user is a known remote user" do
let(:old_person) {
FactoryBot.create(:person,
profile: FactoryBot.build(:profile),
serialized_public_key: archive_private_key.public_key.export,
diaspora_handle: archive_author)
profile: FactoryBot.build(:profile),
serialized_public_key: archive_private_key.public_key.export,
diaspora_handle: archive_author)
}
# Some existing data for old_person to test data merge/migration
@ -327,8 +327,8 @@ describe MigrationService do
let!(:existing_subscription) {
FactoryBot.create(:participation,
author: old_person,
target: FactoryBot.create(:status_message, guid: existing_subscription_guid))
author: old_person,
target: FactoryBot.create(:status_message, guid: existing_subscription_guid))
}
let!(:existing_status_message) {
FactoryBot.create(:status_message,

View file

@ -10,18 +10,18 @@ describe Diaspora::Fetcher::Public do
# the fixture is taken from an actual json request.
# it contains 10 StatusMessages and 5 Reshares, all of them public
# the guid of the person is "7445f9a0a6c28ebb"
@fixture = File.open(Rails.root.join('spec', 'fixtures', 'public_posts.json')).read
@fixture = File.read(Rails.root.join("spec/fixtures/public_posts.json"))
@fetcher = Diaspora::Fetcher::Public.new
@person = FactoryBot.create(:person, guid: "7445f9a0a6c28ebb",
pod: Pod.find_or_create_by(url: "https://remote-testpod.net"),
diaspora_handle: "testuser@remote-testpod.net")
pod: Pod.find_or_create_by(url: "https://remote-testpod.net"),
diaspora_handle: "testuser@remote-testpod.net")
stub_request(:get, /remote-testpod.net\/people\/.*\/stream/)
stub_request(:get, %r{remote-testpod.net/people/.*/stream})
.with(headers: {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'diaspora-fetcher'
}).to_return(:body => @fixture)
"Accept" => "application/json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"User-Agent" => "diaspora-fetcher"
}).to_return(body: @fixture)
end
describe "#queue_for" do
@ -77,7 +77,7 @@ describe Diaspora::Fetcher::Public do
}
end
it 'creates 10 new posts in the database' do
it "creates 10 new posts in the database" do
before_count = Post.count
@fetcher.instance_eval {
process_posts
@ -86,7 +86,7 @@ describe Diaspora::Fetcher::Public do
expect(after_count).to eql(before_count + 10)
end
it 'sets the operation status on the person' do
it "sets the operation status on the person" do
@fetcher.instance_eval {
process_posts
}
@ -96,13 +96,13 @@ describe Diaspora::Fetcher::Public do
expect(@person.fetch_status).to eql(Diaspora::Fetcher::Public::Status_Processed)
end
context 'created post' do
context "created post" do
before do
Timecop.freeze
@now = DateTime.now.utc
@data = JSON.parse(@fixture).select { |item| item['post_type'] == 'StatusMessage' }
@data = JSON.parse(@fixture).select {|item| item["post_type"] == "StatusMessage" }
#save posts to db
# save posts to db
@fetcher.instance_eval {
process_posts
}
@ -112,27 +112,27 @@ describe Diaspora::Fetcher::Public do
Timecop.return
end
it 'applies the date from JSON to the record' do
it "applies the date from JSON to the record" do
@data.each do |post|
date = ActiveSupport::TimeZone.new('UTC').parse(post['created_at']).to_i
date = ActiveSupport::TimeZone.new("UTC").parse(post["created_at"]).to_i
entry = StatusMessage.find_by_guid(post['guid'])
entry = StatusMessage.find_by(guid: post["guid"])
expect(entry.created_at.to_i).to eql(date)
end
end
it "copied the text correctly" do
@data.each do |post|
entry = StatusMessage.find_by_guid(post["guid"])
entry = StatusMessage.find_by(guid: post["guid"])
expect(entry.text).to eql(post["text"])
end
end
it 'applies now to interacted_at on the record' do
it "applies now to interacted_at on the record" do
@data.each do |post|
date = @now.to_i
entry = StatusMessage.find_by_guid(post['guid'])
entry = StatusMessage.find_by(guid: post["guid"])
expect(entry.interacted_at.to_i).to eql(date)
end
end
@ -142,7 +142,7 @@ describe Diaspora::Fetcher::Public do
context "private methods" do
let(:public_fetcher) { Diaspora::Fetcher::Public.new }
describe '#qualifies_for_fetching?' do
describe "#qualifies_for_fetching?" do
it "raises an error if the person doesn't exist" do
expect {
public_fetcher.instance_eval {
@ -152,14 +152,14 @@ describe Diaspora::Fetcher::Public do
}.to raise_error ActiveRecord::RecordNotFound
end
it 'returns false if the person is unfetchable' do
it "returns false if the person is unfetchable" do
expect(public_fetcher.instance_eval {
@person = FactoryBot.create(:person, {:fetch_status => Diaspora::Fetcher::Public::Status_Unfetchable})
@person = FactoryBot.create(:person, fetch_status: Diaspora::Fetcher::Public::Status_Unfetchable)
qualifies_for_fetching?
}).to be false
end
it 'returns false and sets the person unfetchable for a local account' do
it "returns false and sets the person unfetchable for a local account" do
user = FactoryBot.create(:user)
expect(public_fetcher.instance_eval {
@person = user.person
@ -168,7 +168,7 @@ describe Diaspora::Fetcher::Public do
expect(user.person.fetch_status).to eql Diaspora::Fetcher::Public::Status_Unfetchable
end
it 'returns false if the person is processing already (or has been processed)' do
it "returns false if the person is processing already (or has been processed)" do
person = FactoryBot.create(:person)
person.fetch_status = Diaspora::Fetcher::Public::Status_Fetched
person.save
@ -179,7 +179,7 @@ describe Diaspora::Fetcher::Public do
end
it "returns true, if the user is remote and hasn't been fetched" do
person = FactoryBot.create(:person, {:diaspora_handle => 'neo@theone.net'})
person = FactoryBot.create(:person, {diaspora_handle: "neo@theone.net"})
expect(public_fetcher.instance_eval {
@person = person
qualifies_for_fetching?
@ -187,8 +187,8 @@ describe Diaspora::Fetcher::Public do
end
end
describe '#set_fetch_status' do
it 'sets the current status of fetching on the person' do
describe "#set_fetch_status" do
it "sets the current status of fetching on the person" do
person = @person
public_fetcher.instance_eval {
@person = person
@ -203,7 +203,7 @@ describe Diaspora::Fetcher::Public do
end
end
describe '#validate' do
describe "#validate" do
it "calls all validation helper methods" do
expect(public_fetcher).to receive(:check_existing).and_return(true)
expect(public_fetcher).to receive(:check_author).and_return(true)
@ -214,19 +214,19 @@ describe Diaspora::Fetcher::Public do
end
end
describe '#check_existing' do
it 'returns false if a post with the same guid exists' do
post = {'guid' => FactoryBot.create(:status_message).guid}
describe "#check_existing" do
it "returns false if a post with the same guid exists" do
post = {"guid" => FactoryBot.create(:status_message).guid}
expect(public_fetcher.instance_eval { check_existing post }).to be false
end
it 'returns true if the guid cannot be found' do
post = {'guid' => SecureRandom.hex(8)}
it "returns true if the guid cannot be found" do
post = {"guid" => SecureRandom.hex(8)}
expect(public_fetcher.instance_eval { check_existing post }).to be true
end
end
describe '#check_author' do
describe "#check_author" do
let!(:some_person) { FactoryBot.create(:person) }
before do
@ -235,36 +235,36 @@ describe Diaspora::Fetcher::Public do
end
it "returns false if the person doesn't match" do
post = { 'author' => { 'guid' => SecureRandom.hex(8) } }
post = {"author" => {"guid" => SecureRandom.hex(8)}}
expect(public_fetcher.instance_eval { check_author post }).to be false
end
it "returns true if the persons match" do
post = { 'author' => { 'guid' => some_person.guid } }
post = {"author" => {"guid" => some_person.guid}}
expect(public_fetcher.instance_eval { check_author post }).to be true
end
end
describe '#check_public' do
describe "#check_public" do
it "returns false if the post is not public" do
post = {'public' => false}
post = {"public" => false}
expect(public_fetcher.instance_eval { check_public post }).to be false
end
it "returns true if the post is public" do
post = {'public' => true}
post = {"public" => true}
expect(public_fetcher.instance_eval { check_public post }).to be true
end
end
describe '#check_type' do
describe "#check_type" do
it "returns false if the type is anything other that 'StatusMessage'" do
post = {'post_type'=>'Reshare'}
post = {"post_type"=>"Reshare"}
expect(public_fetcher.instance_eval { check_type post }).to be false
end
it "returns true if the type is 'StatusMessage'" do
post = {'post_type'=>'StatusMessage'}
post = {"post_type"=>"StatusMessage"}
expect(public_fetcher.instance_eval { check_type post }).to be true
end
end

View file

@ -180,7 +180,7 @@ describe Diaspora::MessageRenderer do
end
it "should leave mentions intact for real diaspora handles" do
new_person = FactoryBot.create(:person, diaspora_handle: 'maxwell@joindiaspora.com')
new_person = FactoryBot.create(:person, diaspora_handle: "maxwell@joindiaspora.com")
expect(
message(
"Hey @{maxwell@joindiaspora.com; #{new_person.diaspora_handle}}!",

View file

@ -3,8 +3,8 @@
describe EvilQuery::MultiStream do
let(:evil_query) { EvilQuery::MultiStream.new(alice, "created_at", Time.zone.now, true) }
describe 'community_spotlight_posts!' do
it 'does not raise an error' do
describe "community_spotlight_posts!" do
it "does not raise an error" do
expect { evil_query.community_spotlight_posts! }.to_not raise_error
end
end
@ -47,7 +47,7 @@ end
describe EvilQuery::Participation do
before do
@status_message = FactoryBot.create(:status_message, :author => bob.person)
@status_message = FactoryBot.create(:status_message, author: bob.person)
end
it "includes posts liked by the user" do
@ -66,35 +66,35 @@ describe EvilQuery::Participation do
describe "ordering" do
before do
@status_messageA = FactoryBot.create(:status_message, :author => bob.person)
@status_messageB = FactoryBot.create(:status_message, :author => bob.person)
@status_messageD = FactoryBot.create(:status_message, :author => bob.person)
@status_messageE = FactoryBot.create(:status_message, :author => bob.person)
@status_message_a = FactoryBot.create(:status_message, author: bob.person)
@status_message_b = FactoryBot.create(:status_message, author: bob.person)
@status_message_d = FactoryBot.create(:status_message, author: bob.person)
@status_message_e = FactoryBot.create(:status_message, author: bob.person)
time = Time.now
time = Time.zone.now
Timecop.freeze do
Timecop.travel time += 1.month
alice.comment!(@status_messageB, "party")
alice.comment!(@status_message_b, "party")
Timecop.travel time += 1.month
alice.like!(@status_messageA)
alice.like!(@status_message_a)
Timecop.travel time += 1.month
alice.comment!(@status_messageE, "party")
alice.comment!(@status_message_e, "party")
end
end
let(:posts) {EvilQuery::Participation.new(alice).posts}
let(:posts) { EvilQuery::Participation.new(alice).posts }
it "doesn't include Posts that aren't acted on" do
expect(posts.map(&:id)).not_to include(@status_messageD.id)
expect(posts.map(&:id)).to match_array([@status_messageA.id, @status_messageB.id, @status_messageE.id])
expect(posts.map(&:id)).not_to include(@status_message_d.id)
expect(posts.map(&:id)).to match_array([@status_message_a.id, @status_message_b.id, @status_message_e.id])
end
it "returns the posts that the user has commented on most recently first" do
expect(posts.map(&:id)).to eq([@status_messageE.id, @status_messageB.id, @status_messageA.id])
expect(posts.map(&:id)).to eq([@status_message_e.id, @status_message_b.id, @status_message_a.id])
end
end

View file

@ -1,13 +1,13 @@
# frozen_string_literal: true
require Rails.root.join('spec', 'shared_behaviors', 'stream')
require Rails.root.join("spec/shared_behaviors/stream")
describe Stream::Base do
before do
@stream = Stream::Base.new(alice)
end
describe '#stream_posts' do
describe "#stream_posts" do
it "should returns the posts.for_a_stream" do
posts = double
allow(@stream).to receive(:posts).and_return(posts)
@ -19,9 +19,9 @@ describe Stream::Base do
context "when alice has liked some posts" do
before do
bob.post(:status_message, :text => "sup", :to => bob.aspects.first.id)
bob.post(:status_message, text: "sup", to: bob.aspects.first.id)
@liked_status = bob.posts.last
@like = FactoryBot.create(:like, :target => @liked_status, :author => alice.person)
@like = FactoryBot.create(:like, target: @liked_status, author: alice.person)
end
it "marks the posts as liked" do
@ -30,47 +30,47 @@ describe Stream::Base do
end
end
describe '.can_comment?' do
describe ".can_comment?" do
before do
@person = FactoryBot.create(:person)
allow(@stream).to receive(:people).and_return([bob.person, eve.person, @person])
end
it 'allows me to comment on my local contacts post' do
post = FactoryBot.create(:status_message, :author => bob.person)
it "allows me to comment on my local contacts post" do
post = FactoryBot.create(:status_message, author: bob.person)
expect(@stream.can_comment?(post)).to be true
end
it 'allows me to comment on my own post' do
post = FactoryBot.create(:status_message, :author => alice.person)
it "allows me to comment on my own post" do
post = FactoryBot.create(:status_message, author: alice.person)
expect(@stream.can_comment?(post)).to be true
end
it 'allows me to comment on any local public post' do
post = FactoryBot.create(:status_message, :author => eve.person)
it "allows me to comment on any local public post" do
post = FactoryBot.create(:status_message, author: eve.person)
expect(@stream.can_comment?(post)).to be true
end
it 'allows me to comment on a remote contacts post' do
Contact.create!(:user => @stream.user, :person => @person)
post = FactoryBot.create(:status_message, :author => @person)
it "allows me to comment on a remote contacts post" do
Contact.create!(user: @stream.user, person: @person)
post = FactoryBot.create(:status_message, author: @person)
expect(@stream.can_comment?(post)).to be true
end
it 'returns false if person is remote and not a contact' do
post = FactoryBot.create(:status_message, :author => @person)
it "returns false if person is remote and not a contact" do
post = FactoryBot.create(:status_message, author: @person)
expect(@stream.can_comment?(post)).to be false
end
end
describe '#people' do
it 'excludes blocked people' do
describe "#people" do
it "excludes blocked people" do
expect(@stream).to receive(:stream_posts).and_return(double.as_null_object)
@stream.people
end
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
describe "shared behaviors" do
it_should_behave_like "it is a stream"
end
end

View file

@ -1,37 +1,36 @@
# frozen_string_literal: true
require Rails.root.join('spec', 'shared_behaviors', 'stream')
require Rails.root.join("spec/shared_behaviors/stream")
describe Stream::Multi do
before do
@stream = Stream::Multi.new(alice, :max_time => Time.now, :order => 'updated_at')
@stream = Stream::Multi.new(alice, max_time: Time.zone.now, order: "updated_at")
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
describe "shared behaviors" do
it_should_behave_like "it is a stream"
end
describe "#posts" do
it "calls EvilQuery::MultiStream with correct parameters" do
expect(::EvilQuery::MultiStream).to receive(:new)
.with(alice, 'updated_at', @stream.max_time,
.with(alice, "updated_at", @stream.max_time,
AppConfig.settings.community_spotlight.enable? &&
alice.show_community_spotlight_in_stream?)
.and_return(double.tap { |m| allow(m).to receive(:make_relation!)})
.and_return(double.tap {|m| allow(m).to receive(:make_relation!) })
@stream.posts
end
end
describe '#publisher_opts' do
it 'prefills, sets public, and autoexpands if welcome? is set' do
describe "#publisher_opts" do
it "prefills, sets public, and autoexpands if welcome? is set" do
prefill_text = "sup?"
allow(@stream).to receive(:welcome?).and_return(true)
allow(@stream).to receive(:publisher_prefill).and_return(prefill_text)
expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true)
end
it 'provides no opts if welcome? is not set' do
prefill_text = "sup?"
it "provides no opts if welcome? is not set" do
allow(@stream).to receive(:welcome?).and_return(false)
expect(@stream.send(:publisher_opts)).to eq(public: false)
end
@ -40,28 +39,28 @@ describe Stream::Multi do
describe "#publisher_prefill" do
before do
@tag = ActsAsTaggableOn::Tag.find_or_create_by(name: "cats")
@tag_following = alice.tag_followings.create(:tag_id => @tag.id)
@tag_following = alice.tag_followings.create(tag_id: @tag.id)
@stream = Stream::Multi.new(alice)
end
it 'returns includes new user hashtag' do
it "returns includes new user hashtag" do
expect(@stream.send(:publisher_prefill)).to match(/#NewHere/i)
end
it 'includes followed hashtags' do
it "includes followed hashtags" do
expect(@stream.send(:publisher_prefill)).to include("#cats")
end
context 'when invited by another user' do
context "when invited by another user" do
before do
@user = FactoryBot.create(:user, :invited_by => alice)
@user = FactoryBot.create(:user, invited_by: alice)
@inviter = alice.person
@stream = Stream::Multi.new(@user)
end
it 'includes a mention of the inviter' do
it "includes a mention of the inviter" do
mention = "@{#{@inviter.diaspora_handle}}"
expect(@stream.send(:publisher_prefill)).to include(mention)
end
@ -73,12 +72,12 @@ describe Stream::Multi do
@stream = Stream::Multi.new(alice)
end
it 'returns true if user is getting started' do
it "returns true if user is getting started" do
alice.getting_started = true
expect(@stream.send(:welcome?)).to be true
end
it 'returns false if user is getting started' do
it "returns false if user is getting started" do
alice.getting_started = false
expect(@stream.send(:welcome?)).to be false
end

View file

@ -4,11 +4,11 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe Maintenance, :type => :mailer do
describe 'create warning' do
describe Maintenance, type: :mailer do
describe "create warning" do
before do
@removal_timestamp = Time.now + 3.days
@user = FactoryBot.create(:user_with_aspect, :username => "local", :remove_after => @removal_timestamp)
@removal_timestamp = Time.zone.now + 3.days
@user = FactoryBot.create(:user_with_aspect, username: "local", remove_after: @removal_timestamp)
end
it "#should deliver successfully" do
@ -30,12 +30,14 @@ describe Maintenance, :type => :mailer do
it "#should include after inactivity days from settings" do
Maintenance.account_removal_warning(@user).deliver_now
expect(ActionMailer::Base.deliveries.last.body.parts[0].body.raw_source).to include("for #{AppConfig.settings.maintenance.remove_old_users.after_days} days")
expect(ActionMailer::Base.deliveries.last.body.parts[0].body.raw_source)
.to include("for #{AppConfig.settings.maintenance.remove_old_users.after_days} days")
end
it "#should include timestamp for account removal" do
Maintenance.account_removal_warning(@user).deliver_now
expect(ActionMailer::Base.deliveries.last.body.parts[0].body.raw_source).to include("sign in to your account before #{@removal_timestamp.utc}")
expect(ActionMailer::Base.deliveries.last.body.parts[0].body.raw_source)
.to include("sign in to your account before #{@removal_timestamp.utc}")
end
end
end

View file

@ -5,7 +5,7 @@ describe AspectVisibility, type: :model do
let(:aspect) { FactoryBot.create(:aspect) }
let(:status_message_in_aspect) { FactoryBot.create(:status_message_in_aspect) }
let(:photo_with_same_id) {
Photo.find_by_id(status_message_in_aspect.id) || FactoryBot.create(:photo, id: status_message_in_aspect.id)
Photo.find_by(id: status_message_in_aspect.id) || FactoryBot.create(:photo, id: status_message_in_aspect.id)
}
describe ".create" do

View file

@ -4,73 +4,75 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe Person, :type => :model do
describe Person, type: :model do
before do
@user = bob
@person = FactoryBot.create(:person)
end
it 'always has a profile' do
it "always has a profile" do
expect(Person.new.profile).not_to be_nil
end
it 'does not save automatically' do
it "does not save automatically" do
expect(Person.new.persisted?).to be false
expect(Person.new.profile.persisted?).to be false
end
context 'scopes' do
describe '.for_json' do
it 'does not select public keys' do
context "scopes" do
describe ".for_json" do
it "does not select public keys" do
expect {
Person.for_json.first.serialized_public_key
}.to raise_error ActiveModel::MissingAttributeError
end
end
describe '.local' do
it 'returns only local people' do
describe ".local" do
it "returns only local people" do
Person.local =~ [@person]
end
end
describe '.remote' do
it 'returns only local people' do
describe ".remote" do
it "returns only local people" do
Person.remote =~ [@user.person]
end
end
describe '.find_person_from_guid_or_username' do
it 'searchs for a person if id is passed' do
expect(Person.find_from_guid_or_username(:id => @person.guid).id).to eq(@person.id)
describe ".find_person_from_guid_or_username" do
it "searchs for a person if id is passed" do
expect(Person.find_from_guid_or_username(id: @person.guid).id).to eq(@person.id)
end
it 'searchs a person from a user if username is passed' do
expect(Person.find_from_guid_or_username(:username => @user.username).id).to eq(@user.person.id)
it "searchs a person from a user if username is passed" do
expect(Person.find_from_guid_or_username(username: @user.username).id).to eq(@user.person.id)
end
it 'throws active record not found exceptions if no person is found via id' do
expect{
Person.find_from_guid_or_username(:id => "2d13123")
it "throws active record not found exceptions if no person is found via id" do
expect {
Person.find_from_guid_or_username(id: "2d13123")
}.to raise_error ActiveRecord::RecordNotFound
end
it 'throws active record not found exceptions if no person is found via username' do
expect{
Person.find_from_guid_or_username(:username => 'michael_jackson')
it "throws active record not found exceptions if no person is found via username" do
expect {
Person.find_from_guid_or_username(username: "michael_jackson")
}.to raise_error ActiveRecord::RecordNotFound
end
end
describe '.all_from_aspects' do
describe ".all_from_aspects" do
it "pulls back the right people given all a user's aspects" do
aspect_ids = bob.aspects.map(&:id)
expect(Person.all_from_aspects(aspect_ids, bob).map(&:id)).to match_array(bob.contacts.includes(:person).map{|c| c.person.id})
expect(Person.all_from_aspects(aspect_ids, bob).map(&:id))
.to match_array(bob.contacts.includes(:person).map {|c| c.person.id })
end
it "pulls back the right people given a subset of aspects" do
aspect_ids = bob.aspects.first.id
expect(Person.all_from_aspects(aspect_ids, bob).map(&:id)).to match_array(bob.aspects.first.contacts.includes(:person).map{|c| c.person.id})
expect(Person.all_from_aspects(aspect_ids, bob).map(&:id))
.to match_array(bob.aspects.first.contacts.includes(:person).map {|c| c.person.id })
end
it "respects aspects given a user" do
@ -80,13 +82,14 @@ describe Person, :type => :model do
end
describe ".who_have_reshared a user's posts" do
it 'pulls back users who reshared the status message of a user' do
sm = FactoryBot.create(:status_message, :author => alice.person, :public => true)
reshare = FactoryBot.create(:reshare, :root => sm)
it "pulls back users who reshared the status message of a user" do
sm = FactoryBot.create(:status_message, author: alice.person, public: true)
reshare = FactoryBot.create(:reshare, root: sm)
expect(Person.who_have_reshared_a_users_posts(alice)).to eq([reshare.author])
end
end
# rubocop:disable Rails/DynamicFindBy
describe ".find_by_substring" do
it "returns \"none\" when the substring is less than 1 non-space character" do
expect(Person.find_by_substring("R")).to eq(Person.none)
@ -136,6 +139,7 @@ describe Person, :type => :model do
expect(Person.allowed_to_be_mentioned_in_a_comment_to(status_bob).ids).to match_array(Person.ids)
end
end
# rubocop:enable Rails/DynamicFindBy
describe ".sort_for_mention_suggestion" do
let(:status_message) { FactoryBot.create(:status_message) }
@ -203,7 +207,7 @@ describe Person, :type => :model do
describe "delegating" do
it "delegates last_name to the profile" do
expect(@person.last_name).to eq(@person.profile.last_name)
@person.profile.update_attributes(:last_name => "Heathers")
@person.profile.update(last_name: "Heathers")
expect(@person.reload.last_name).to eq("Heathers")
end
end
@ -262,74 +266,80 @@ describe Person, :type => :model do
end
end
describe '#diaspora_handle' do
context 'local people' do
it 'uses the pod config url to set the diaspora_handle' do
new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person
describe "#diaspora_handle" do
context "local people" do
it "uses the pod config url to set the diaspora_handle" do
new_person = User.build(username: "foo123", email: "foo123@example.com",
password: "password", password_confirmation: "password").person
expect(new_person.diaspora_handle).to eq("foo123#{User.diaspora_id_host}")
end
it 'does not include www if it is set in app config' do
allow(AppConfig).to receive(:pod_uri).and_return(Addressable::URI.parse('https://www.foobar.com/'))
new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person
it "does not include www if it is set in app config" do
allow(AppConfig).to receive(:pod_uri).and_return(Addressable::URI.parse("https://www.foobar.com/"))
new_person = User.build(username: "foo123", email: "foo123@example.com", password: "password",
password_confirmation: "password").person
expect(new_person.diaspora_handle).to eq("foo123@foobar.com")
end
end
context 'remote people' do
it 'stores the diaspora_handle in the database' do
context "remote people" do
it "stores the diaspora_handle in the database" do
expect(@person.diaspora_handle.include?(AppConfig.pod_uri.host)).to be false
end
end
describe 'validation' do
it 'is unique' do
person_two = FactoryBot.build(:person, :diaspora_handle => @person.diaspora_handle)
describe "validation" do
it "is unique" do
person_two = FactoryBot.build(:person, diaspora_handle: @person.diaspora_handle)
expect(person_two).not_to be_valid
end
it 'is case insensitive' do
person_two = FactoryBot.build(:person, :diaspora_handle => @person.diaspora_handle.upcase)
it "is case insensitive" do
person_two = FactoryBot.build(:person, diaspora_handle: @person.diaspora_handle.upcase)
expect(person_two).not_to be_valid
end
end
end
context '.name_from_attrs' do
context ".name_from_attrs" do
before do
@person = alice.person
@profile = @person.profile
end
context 'with only first name' do
it 'should return their first name for name' do
expect(Person.name_from_attrs(@profile.first_name, nil, @profile.diaspora_handle)).to eq(@profile.first_name.strip)
context "with only first name" do
it "should return their first name for name" do
expect(Person.name_from_attrs(@profile.first_name, nil, @profile.diaspora_handle))
.to eq(@profile.first_name.strip)
end
end
context 'with only last name' do
it 'should return their last name for name' do
expect(Person.name_from_attrs(nil, @profile.last_name, @profile.diaspora_handle)).to eq(@profile.last_name.strip)
context "with only last name" do
it "should return their last name for name" do
expect(Person.name_from_attrs(nil, @profile.last_name, @profile.diaspora_handle))
.to eq(@profile.last_name.strip)
end
end
context 'with both first and last name' do
it 'should return their composed name for name' do
expect(Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle)).to eq("#{@profile.first_name.strip} #{@profile.last_name.strip}")
context "with both first and last name" do
it "should return their composed name for name" do
expect(Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle))
.to eq("#{@profile.first_name.strip} #{@profile.last_name.strip}")
end
end
context 'without first nor last name' do
it 'should display their diaspora handle' do
context "without first nor last name" do
it "should display their diaspora handle" do
expect(Person.name_from_attrs(nil, nil, @profile.diaspora_handle)).to eq(@profile.diaspora_handle)
end
end
end
describe '#name' do
it 'calls Person.name_from_attrs' do
describe "#name" do
it "calls Person.name_from_attrs" do
profile = alice.person.profile
expect(Person).to receive(:name_from_attrs).with(profile.first_name, profile.last_name, profile.person.diaspora_handle)
expect(Person).to receive(:name_from_attrs)
.with(profile.first_name, profile.last_name, profile.person.diaspora_handle)
alice.name
end
@ -341,8 +351,8 @@ describe Person, :type => :model do
end
end
it '#owns? posts' do
person_message = FactoryBot.create(:status_message, :author => @person)
it "#owns? posts" do
person_message = FactoryBot.create(:status_message, author: @person)
person_two = FactoryBot.create(:person)
expect(@person.owns?(person_message)).to be true
@ -352,41 +362,41 @@ describe Person, :type => :model do
describe "disconnecting" do
before do
@user2 = FactoryBot.create(:user)
@aspect = @user.aspects.create(:name => "Dudes")
@aspect2 = @user2.aspects.create(:name => "Abscence of Babes")
@aspect = @user.aspects.create(name: "Dudes")
@aspect2 = @user2.aspects.create(name: "Abscence of Babes")
end
it 'should not delete an orphaned contact' do
@user.contacts.create(:person => @person, :aspects => [@aspect])
it "should not delete an orphaned contact" do
@user.contacts.create(person: @person, aspects: [@aspect])
expect { @user.disconnect(@user.contact_for(@person)) }.not_to change(Person, :count)
end
it 'should not delete an un-orphaned contact' do
@user.contacts.create(:person => @person, :aspects => [@aspect])
@user2.contacts.create(:person => @person, :aspects => [@aspect2])
it "should not delete an un-orphaned contact" do
@user.contacts.create(person: @person, aspects: [@aspect])
@user2.contacts.create(person: @person, aspects: [@aspect2])
expect { @user.disconnect(@user.contact_for(@person)) }.not_to change(Person, :count)
end
end
describe "#first_name" do
it 'returns username if first_name is not present in profile' do
alice.person.profile.update_attributes(:first_name => "")
it "returns username if first_name is not present in profile" do
alice.person.profile.update(first_name: "")
expect(alice.person.first_name).to eq(alice.username)
end
it 'returns first words in first_name if first_name is present' do
alice.person.profile.update_attributes(:first_name => "First Mid Last")
it "returns first words in first_name if first_name is present" do
alice.person.profile.update(first_name: "First Mid Last")
expect(alice.person.first_name).to eq("First Mid")
end
it 'returns first word in first_name if first_name is present' do
alice.person.profile.update_attributes(:first_name => "Alice")
it "returns first word in first_name if first_name is present" do
alice.person.profile.update(first_name: "Alice")
expect(alice.person.first_name).to eq("Alice")
end
end
describe '.search' do
describe ".search" do
before do
Person.delete_all
@user = FactoryBot.create(:user_with_aspect)
@ -434,7 +444,7 @@ describe Person, :type => :model do
@closed_account.reload
end
it 'orders results by last name' do
it "orders results by last name" do
@robert_grimm.profile.first_name = "AAA"
@robert_grimm.profile.save!
@ -448,20 +458,20 @@ describe Person, :type => :model do
@casey_grippi.profile.save!
people = Person.search("AAA", @user)
expect(people.map { |p| p.name }).to eq([@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map { |p| p.name })
expect(people.map(&:name)).to eq([@yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map(&:name))
end
it 'returns nothing on an empty query' do
it "returns nothing on an empty query" do
people = Person.search("", @user)
expect(people).to be_empty
end
it 'returns nothing on a one-character query' do
it "returns nothing on a one-character query" do
people = Person.search("i", @user)
expect(people).to be_empty
end
it 'returns results for partial names' do
it "returns results for partial names" do
people = Person.search("Eug", @user)
expect(people.count).to eq(1)
expect(people.first).to eq(@eugene_weinstein)
@ -476,7 +486,7 @@ describe Person, :type => :model do
expect(people.second).to eq(@casey_grippi)
end
it 'returns results for full names' do
it "returns results for full names" do
people = Person.search("Casey Grippi", @user)
expect(people.count).to eq(1)
expect(people.first).to eq(@casey_grippi)
@ -499,7 +509,7 @@ describe Person, :type => :model do
expect(people.first).to eq(@invisible_person)
end
it 'returns results for Diaspora handles' do
it "returns results for Diaspora handles" do
people = Person.search(@robert_grimm.diaspora_handle, @user)
expect(people).to eq([@robert_grimm])
end
@ -517,10 +527,10 @@ describe Person, :type => :model do
@casey_grippi.profile.first_name = "AAA"
@casey_grippi.profile.save!
@user.contacts.create(:person => @casey_grippi, :aspects => [@user.aspects.first])
@user.contacts.create(person: @casey_grippi, aspects: [@user.aspects.first])
people = Person.search("AAA", @user)
expect(people.map { |p| p.name }).to eq([@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map { |p| p.name })
expect(people.map(&:name)).to eq([@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map(&:name))
end
context "only contacts" do
@ -591,39 +601,39 @@ describe Person, :type => :model do
end
it "handles broken keys and returns nil" do
@person.update_attributes(serialized_public_key: "broken")
@person.update(serialized_public_key: "broken")
expect(@person.public_key).to be_nil
end
end
context 'people finders for webfinger' do
context "people finders for webfinger" do
let(:user) { FactoryBot.create(:user) }
let(:person) { FactoryBot.create(:person) }
describe '.by_account_identifier' do
it 'should find a local users person' do
describe ".by_account_identifier" do
it "should find a local users person" do
p = Person.by_account_identifier(user.diaspora_handle)
expect(p).to eq(user.person)
end
it 'should find remote users person' do
it "should find remote users person" do
p = Person.by_account_identifier(person.diaspora_handle)
expect(p).to eq(person)
end
it 'should downcase and strip the diaspora_handle' do
it "should downcase and strip the diaspora_handle" do
dh_upper = " " + user.diaspora_handle.upcase + " "
expect(Person.by_account_identifier(dh_upper)).to eq(user.person)
end
it "finds a local person with a mixed-case username" do
user = FactoryBot.create(:user, :username => "SaMaNtHa")
user = FactoryBot.create(:user, username: "SaMaNtHa")
person = Person.by_account_identifier(user.person.diaspora_handle)
expect(person).to eq(user.person)
end
it "is case insensitive" do
user1 = FactoryBot.create(:user, :username => "SaMaNtHa")
user1 = FactoryBot.create(:user, username: "SaMaNtHa")
person = Person.by_account_identifier(user1.person.diaspora_handle.upcase)
expect(person).to eq(user1.person)
end
@ -643,20 +653,20 @@ describe Person, :type => :model do
end
end
describe '#has_photos?' do
it 'returns false if the user has no photos' do
describe "#has_photos?" do
it "returns false if the user has no photos" do
expect(alice.person.has_photos?).to be false
end
it 'returns true if the user has photos' do
alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
it "returns true if the user has photos" do
alice.post(:photo, user_file: uploaded_photo, to: alice.aspects.first.id)
expect(alice.person.has_photos?).to be true
end
end
describe '#as_json' do
it 'returns a hash representation of a person' do
describe "#as_json" do
it "returns a hash representation of a person" do
expect(@person.as_json).to eq(
id: @person.id,
guid: @person.guid,
@ -666,15 +676,15 @@ describe Person, :type => :model do
url: Rails.application.routes.url_helpers.person_path(@person)
)
end
it 'return tags if asked' do
expect(@person.as_json(:includes => "tags")).
to eq(@person.as_json.merge(:tags => @person.profile.tags.map { |t| "##{t.name}" }))
it "return tags if asked" do
expect(@person.as_json(includes: "tags"))
.to eq(@person.as_json.merge(tags: @person.profile.tags.map {|t| "##{t.name}" }))
end
end
describe '.community_spotlight' do
describe ".community_spotlight" do
describe "when the pod owner hasn't set up any community spotlight members" do
it 'returns people with the community spotlight role' do
it "returns people with the community spotlight role" do
Role.add_spotlight(bob.person)
expect(Person.community_spotlight).to be_present
end
@ -685,8 +695,8 @@ describe Person, :type => :model do
end
end
describe '#lock_access!' do
it 'sets the closed_account flag' do
describe "#lock_access!" do
it "sets the closed_account flag" do
@person.lock_access!
expect(@person.reload.closed_account).to be true
end
@ -697,7 +707,7 @@ describe Person, :type => :model do
@person = FactoryBot.build(:person)
end
it 'calls Profile#tombstone!' do
it "calls Profile#tombstone!" do
expect(@person.profile).to receive(:tombstone!)
@person.clear_profile!
end

View file

@ -4,40 +4,40 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe Post, :type => :model do
describe 'scopes' do
describe '.owned_or_visible_by_user' do
describe Post, type: :model do
describe "scopes" do
describe ".owned_or_visible_by_user" do
before do
@you = bob
@public_post = FactoryBot.create(:status_message, :public => true)
@your_post = FactoryBot.create(:status_message, :author => @you.person)
@post_from_contact = eve.post(:status_message, :text => 'wooo', :to => eve.aspects.where(:name => 'generic').first)
@post_from_stranger = FactoryBot.create(:status_message, :public => false)
@public_post = FactoryBot.create(:status_message, public: true)
@your_post = FactoryBot.create(:status_message, author: @you.person)
@post_from_contact = eve.post(:status_message, text: "wooo", to: eve.aspects.where(name: "generic").first)
@post_from_stranger = FactoryBot.create(:status_message, public: false)
end
it 'returns post from your contacts' do
it "returns post from your contacts" do
expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@post_from_contact)
end
it 'returns your posts' do
it "returns your posts" do
expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@your_post)
end
it 'returns public posts' do
it "returns public posts" do
expect(StatusMessage.owned_or_visible_by_user(@you)).to include(@public_post)
end
it 'returns public post from your contact' do
sm = FactoryBot.create(:status_message, :author => eve.person, :public => true)
it "returns public post from your contact" do
sm = FactoryBot.create(:status_message, author: eve.person, public: true)
expect(StatusMessage.owned_or_visible_by_user(@you)).to include(sm)
end
it 'does not return non contacts, non-public post' do
it "does not return non contacts, non-public post" do
expect(StatusMessage.owned_or_visible_by_user(@you)).not_to include(@post_from_stranger)
end
it 'should return the three visible posts' do
it "should return the three visible posts" do
expect(StatusMessage.owned_or_visible_by_user(@you).count(:all)).to eq(3)
end
end
@ -58,117 +58,116 @@ describe Post, :type => :model do
end
end
describe '.for_a_stream' do
it 'calls #for_visible_shareable_sql' do
time, order = double, double
describe ".for_a_stream" do
it "calls #for_visible_shareable_sql" do
time = double
order = double
expect(Post).to receive(:for_visible_shareable_sql).with(time, order).and_return(Post)
Post.for_a_stream(time, order)
end
it 'calls includes_for_a_stream' do
it "calls includes_for_a_stream" do
expect(Post).to receive(:includes_for_a_stream)
Post.for_a_stream(Time.zone.now, "created_at")
end
it 'calls excluding_blocks if a user is present' do
it "calls excluding_blocks if a user is present" do
expect(Post).to receive(:excluding_blocks).with(alice).and_return(Post)
Post.for_a_stream(Time.zone.now, "created_at", alice)
end
end
describe '.excluding_blocks' do
describe ".excluding_blocks" do
before do
@post = FactoryBot.create(:status_message, :author => alice.person)
@other_post = FactoryBot.create(:status_message, :author => eve.person)
@post = FactoryBot.create(:status_message, author: alice.person)
@other_post = FactoryBot.create(:status_message, author: eve.person)
bob.blocks.create(:person => alice.person)
bob.blocks.create(person: alice.person)
end
it 'does not included blocked users posts' do
it "does not included blocked users posts" do
expect(Post.excluding_blocks(bob)).not_to include(@post)
end
it 'includes not blocked users posts' do
it "includes not blocked users posts" do
expect(Post.excluding_blocks(bob)).to include(@other_post)
end
it 'returns posts if you dont have any blocks' do
it "returns posts if you dont have any blocks" do
expect(Post.excluding_blocks(alice).count).to eq(2)
end
end
describe '.excluding_hidden_shareables' do
describe ".excluding_hidden_shareables" do
before do
@post = FactoryBot.create(:status_message, :author => alice.person)
@other_post = FactoryBot.create(:status_message, :author => eve.person)
@post = FactoryBot.create(:status_message, author: alice.person)
@other_post = FactoryBot.create(:status_message, author: eve.person)
bob.toggle_hidden_shareable(@post)
end
it 'excludes posts the user has hidden' do
it "excludes posts the user has hidden" do
expect(Post.excluding_hidden_shareables(bob)).not_to include(@post)
end
it 'includes posts the user has not hidden' do
it "includes posts the user has not hidden" do
expect(Post.excluding_hidden_shareables(bob)).to include(@other_post)
end
end
describe '.excluding_hidden_content' do
it 'calls excluding_blocks and excluding_hidden_shareables' do
describe ".excluding_hidden_content" do
it "calls excluding_blocks and excluding_hidden_shareables" do
expect(Post).to receive(:excluding_blocks).and_return(Post)
expect(Post).to receive(:excluding_hidden_shareables)
Post.excluding_hidden_content(bob)
end
end
context 'having some posts' do
context "having some posts" do
before do
time_interval = 1000
time_past = 1000000
time_past = 1_000_000
@posts = (1..5).map do |n|
aspect_to_post = alice.aspects.where(:name => "generic").first
post = alice.post :status_message, :text => "#{alice.username} - #{n}", :to => aspect_to_post.id
post.created_at = (post.created_at-time_past) - time_interval
post.updated_at = (post.updated_at-time_past) + time_interval
aspect_to_post = alice.aspects.where(name: "generic").first
post = alice.post :status_message, text: "#{alice.username} - #{n}", to: aspect_to_post.id
post.created_at = (post.created_at - time_past) - time_interval
post.updated_at = (post.updated_at - time_past) + time_interval
post.save
time_interval += 1000
post
end
end
describe '.by_max_time' do
it 'returns the posts ordered and limited by unix time' do
expect(Post.for_a_stream(Time.now + 1, "created_at")).to eq(@posts)
expect(Post.for_a_stream(Time.now + 1, "updated_at")).to eq(@posts.reverse)
describe ".by_max_time" do
it "returns the posts ordered and limited by unix time" do
expect(Post.for_a_stream(Time.zone.now + 1, "created_at")).to eq(@posts)
expect(Post.for_a_stream(Time.zone.now + 1, "updated_at")).to eq(@posts.reverse)
end
end
describe '.for_visible_shareable_sql' do
it 'calls max_time' do
time = Time.now + 1
expect(Post).to receive(:by_max_time).with(time, 'created_at').and_return(Post)
Post.for_visible_shareable_sql(time, 'created_at')
describe ".for_visible_shareable_sql" do
it "calls max_time" do
time = Time.zone.now + 1
expect(Post).to receive(:by_max_time).with(time, "created_at").and_return(Post)
Post.for_visible_shareable_sql(time, "created_at")
end
it 'defaults to 15 posts' do
it "defaults to 15 posts" do
chain = double.as_null_object
allow(Post).to receive(:by_max_time).and_return(chain)
expect(chain).to receive(:limit).with(15).and_return(Post)
Post.for_visible_shareable_sql(Time.now + 1, "created_at")
Post.for_visible_shareable_sql(Time.zone.now + 1, "created_at")
end
context "with two posts with the same timestamp" do
before do
aspect_id = alice.aspects.where(name: "generic").first.id
Timecop.freeze Time.now do
Timecop.freeze Time.zone.now do
alice.post(:status_message, text: "first", to: aspect_id)
alice.post(:status_message, text: "second", to: aspect_id)
end
end
it "returns them in reverse creation order" do
posts = Post.for_visible_shareable_sql(Time.now + 1, "created_at")
posts = Post.for_visible_shareable_sql(Time.zone.now + 1, "created_at")
expect(posts.first.text).to eq("second")
expect(posts.second.text).to eq("first")
expect(posts.last.text).to eq("alice - 5")
@ -222,34 +221,35 @@ describe Post, :type => :model do
end
end
describe 'validations' do
it 'validates uniqueness of guid and does not throw a db error' do
describe "validations" do
it "validates uniqueness of guid and does not throw a db error" do
message = FactoryBot.create(:status_message)
expect(FactoryBot.build(:status_message, :guid => message.guid)).not_to be_valid
expect(FactoryBot.build(:status_message, guid: message.guid)).not_to be_valid
end
end
describe 'post_type' do
it 'returns the class constant' do
describe "post_type" do
it "returns the class constant" do
status_message = FactoryBot.create(:status_message)
expect(status_message.post_type).to eq("StatusMessage")
end
end
describe 'deletion' do
it 'should delete a posts comments on delete' do
describe "deletion" do
it "should delete a posts comments on delete" do
post = FactoryBot.create(:status_message, author: alice.person)
alice.comment!(post, "hey")
post.destroy
expect(Post.where(:id => post.id).empty?).to eq(true)
expect(Comment.where(:text => "hey").empty?).to eq(true)
expect(Post.where(id: post.id).empty?).to eq(true)
expect(Comment.where(text: "hey").empty?).to eq(true)
end
end
describe '.diaspora_initialize' do
it 'takes provider_display_name' do
sm = FactoryBot.create(:status_message, :provider_display_name => 'mobile')
expect(StatusMessage.diaspora_initialize(sm.attributes.merge(:author => bob.person)).provider_display_name).to eq('mobile')
describe ".diaspora_initialize" do
it "takes provider_display_name" do
sm = FactoryBot.create(:status_message, provider_display_name: "mobile")
expect(StatusMessage.diaspora_initialize(sm.attributes.merge(author: bob.person))
.provider_display_name).to eq("mobile")
end
end
@ -314,7 +314,7 @@ describe Post, :type => :model do
it "does not update updated_at" do
old_time = Time.zone.now - 100
Post.where(id: @post.id).update_all(updated_at: old_time)
Post.where(id: @post.id).update_all(updated_at: old_time) # rubocop:disable Rails/SkipsModelValidations
expect(@post.reload.updated_at.to_i).to eq(old_time.to_i)
@post.update_likes_counter
expect(@post.reload.updated_at.to_i).to eq(old_time.to_i)
@ -342,42 +342,42 @@ describe Post, :type => :model do
end
end
describe '#reshares_count' do
describe "#reshares_count" do
before :each do
@post = alice.post(:status_message, text: "hello", public: true)
expect(@post.reshares.size).to eq(0)
end
describe 'when post has not been reshared' do
it 'returns zero' do
describe "when post has not been reshared" do
it "returns zero" do
expect(@post.reshares_count).to eq(0)
end
end
describe 'when post has been reshared exactly 1 time' do
describe "when post has been reshared exactly 1 time" do
before :each do
expect(@post.reshares.size).to eq(0)
@reshare = FactoryBot.create(:reshare, :root => @post)
@reshare = FactoryBot.create(:reshare, root: @post)
@post.reload
expect(@post.reshares.size).to eq(1)
end
it 'returns 1' do
it "returns 1" do
expect(@post.reshares_count).to eq(1)
end
end
describe 'when post has been reshared more than once' do
describe "when post has been reshared more than once" do
before :each do
expect(@post.reshares.size).to eq(0)
FactoryBot.create(:reshare, :root => @post)
FactoryBot.create(:reshare, :root => @post)
FactoryBot.create(:reshare, :root => @post)
FactoryBot.create(:reshare, root: @post)
FactoryBot.create(:reshare, root: @post)
FactoryBot.create(:reshare, root: @post)
@post.reload
expect(@post.reshares.size).to eq(3)
end
it 'returns the number of reshares' do
it "returns the number of reshares" do
expect(@post.reshares_count).to eq(3)
end
end

View file

@ -4,56 +4,67 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe Profile, :type => :model do
describe 'validation' do
describe Profile, type: :model do
describe "validation" do
describe "of first_name" do
it "strips leading and trailing whitespace" do
profile = FactoryBot.build(:profile, :first_name => " Shelly ")
profile = FactoryBot.build(:profile, first_name: " Shelly ")
expect(profile).to be_valid
expect(profile.first_name).to eq("Shelly")
end
it "can be 32 characters long" do
profile = FactoryBot.build(:profile, :first_name => "Hexagoooooooooooooooooooooooooon")
profile = FactoryBot.build(:profile, first_name: "Hexagoooooooooooooooooooooooooon")
expect(profile).to be_valid
end
it "cannot be 33 characters" do
profile = FactoryBot.build(:profile, :first_name => "Hexagooooooooooooooooooooooooooon")
profile = FactoryBot.build(:profile, first_name: "Hexagooooooooooooooooooooooooooon")
expect(profile).not_to be_valid
end
it 'cannot have ;' do
profile = FactoryBot.build(:profile, :first_name => "Hex;agon")
it "cannot have ;" do
profile = FactoryBot.build(:profile, first_name: "Hex;agon")
expect(profile).not_to be_valid
end
end
describe 'from_omniauth_hash' do
describe "from_omniauth_hash" do
before do
@from_omniauth = {'first_name' => 'bob', 'last_name' => 'jones', 'description' => 'this is my bio', 'location' => 'sf', 'image' => 'http://cats.com/gif.gif'}
@from_omniauth = {
"first_name" => "bob",
"last_name" => "jones",
"description" => "this is my bio",
"location" => "sf",
"image" => "http://cats.com/gif.gif"
}
end
it 'outputs a hash that can update a diaspora profile' do
it "outputs a hash that can update a diaspora profile" do
profile = Profile.new
expect(profile.from_omniauth_hash(@from_omniauth)['bio']).to eq('this is my bio')
expect(profile.from_omniauth_hash(@from_omniauth)["bio"]).to eq("this is my bio")
end
it 'does not overwrite any exsisting profile fields' do
profile = Profile.new(:first_name => 'maxwell')
expect(profile.from_omniauth_hash(@from_omniauth)['first_name']).to eq('maxwell')
it "does not overwrite any exsisting profile fields" do
profile = Profile.new(first_name: "maxwell")
expect(profile.from_omniauth_hash(@from_omniauth)["first_name"]).to eq("maxwell")
end
it 'sets full name to first name' do
@from_omniauth = {'name' => 'bob jones', 'description' => 'this is my bio', 'location' => 'sf', 'image' => 'http://cats.com/gif.gif'}
it "sets full name to first name" do
@from_omniauth = {
"name" => "bob jones",
"description" => "this is my bio",
"location" => "sf",
"image" => "http://cats.com/gif.gif"
}
profile = Profile.new
expect(profile.from_omniauth_hash(@from_omniauth)['first_name']).to eq('bob jones')
expect(profile.from_omniauth_hash(@from_omniauth)["first_name"]).to eq("bob jones")
end
end
describe '#contruct_full_name' do
it 'generates a full name given only first name' do
describe "#contruct_full_name" do
it "generates a full name given only first name" do
profile = FactoryBot.build(:person).profile
profile.first_name = "casimiro"
profile.last_name = nil
@ -63,7 +74,7 @@ describe Profile, :type => :model do
expect(profile.full_name).to eq("casimiro")
end
it 'generates a full name given only last name' do
it "generates a full name given only last name" do
profile = FactoryBot.build(:person).profile
profile.first_name = nil
profile.last_name = "grippi"
@ -73,7 +84,7 @@ describe Profile, :type => :model do
expect(profile.full_name).to eq("grippi")
end
it 'generates a full name given first and last names' do
it "generates a full name given first and last names" do
profile = FactoryBot.build(:person).profile
profile.first_name = "casimiro"
profile.last_name = "grippi"
@ -86,27 +97,27 @@ describe Profile, :type => :model do
describe "of last_name" do
it "strips leading and trailing whitespace" do
profile = FactoryBot.build(:profile, :last_name => " Ohba ")
profile = FactoryBot.build(:profile, last_name: " Ohba ")
expect(profile).to be_valid
expect(profile.last_name).to eq("Ohba")
end
it "can be 32 characters long" do
profile = FactoryBot.build(:profile, :last_name => "Hexagoooooooooooooooooooooooooon")
profile = FactoryBot.build(:profile, last_name: "Hexagoooooooooooooooooooooooooon")
expect(profile).to be_valid
end
it "cannot be 33 characters" do
profile = FactoryBot.build(:profile, :last_name => "Hexagooooooooooooooooooooooooooon")
profile = FactoryBot.build(:profile, last_name: "Hexagooooooooooooooooooooooooooon")
expect(profile).not_to be_valid
end
it 'cannot have ;' do
profile = FactoryBot.build(:profile, :last_name => "Hex;agon")
it "cannot have ;" do
profile = FactoryBot.build(:profile, last_name: "Hex;agon")
expect(profile).not_to be_valid
end
it 'disallows ; with a newline in the string' do
profile = FactoryBot.build(:profile, :last_name => "H\nex;agon")
it "disallows ; with a newline in the string" do
profile = FactoryBot.build(:profile, last_name: "H\nex;agon")
expect(profile).not_to be_valid
end
end
@ -114,12 +125,12 @@ describe Profile, :type => :model do
describe "of location" do
it "can be 255 characters long" do
profile = FactoryBot.build(:profile, :location => "a"*255)
profile = FactoryBot.build(:profile, location: "a" * 255)
expect(profile).to be_valid
end
it "cannot be 256 characters" do
profile = FactoryBot.build(:profile, :location => "a"*256)
profile = FactoryBot.build(:profile, location: "a" * 256)
expect(profile).not_to be_valid
end
end
@ -137,7 +148,7 @@ describe Profile, :type => :model do
end
describe "image_url setters" do
%i(image_url image_url_small image_url_medium).each do |method|
%i[image_url image_url_small image_url_medium].each do |method|
describe "##{method}=" do
before do
@profile = FactoryBot.build(:profile)
@ -173,19 +184,19 @@ describe Profile, :type => :model do
end
end
describe '#image_url' do
describe "#image_url" do
before do
@profile = FactoryBot.build(:profile)
end
it 'returns a default rather than nil' do
it "returns a default rather than nil" do
@profile.image_url = nil
expect(@profile.image_url).not_to be_nil
end
it 'falls back to the large thumbnail if the small thumbnail is nil' do
#Backwards compatibility
@profile[:image_url] = 'large'
it "falls back to the large thumbnail if the small thumbnail is nil" do
# Backwards compatibility
@profile[:image_url] = "large"
@profile[:image_url_small] = nil
@profile[:image_url_medium] = nil
expect(@profile.image_url(size: :thumb_small)).to eq("large")
@ -193,8 +204,8 @@ describe Profile, :type => :model do
end
end
describe '#subscribers' do
it 'returns all non-pending contacts for a user' do
describe "#subscribers" do
it "returns all non-pending contacts for a user" do
expect(bob.profile.subscribers.map(&:id)).to match_array([alice.person, eve.person].map(&:id))
end
end
@ -211,46 +222,46 @@ describe Profile, :type => :model do
end
end
describe 'date=' do
describe "date=" do
let(:profile) { FactoryBot.build(:profile) }
it 'accepts form data' do
it "accepts form data" do
profile.birthday = nil
profile.date = { 'year' => '2000', 'month' => '01', 'day' => '01' }
profile.date = {"year" => "2000", "month" => "01", "day" => "01"}
expect(profile.birthday.year).to eq(2000)
expect(profile.birthday.month).to eq(1)
expect(profile.birthday.day).to eq(1)
end
it 'unsets the birthday' do
it "unsets the birthday" do
profile.birthday = Date.new(2000, 1, 1)
profile.date = { 'year' => '', 'month' => '', 'day' => ''}
profile.date = {"year" => "", "month" => "", "day" => ""}
expect(profile.birthday).to eq(nil)
end
it 'does not change with blank month and day values' do
it "does not change with blank month and day values" do
profile.birthday = Date.new(2000, 1, 1)
profile.date = { 'year' => '2001', 'month' => '', 'day' => ''}
profile.date = {"year" => "2001", "month" => "", "day" => ""}
expect(profile.birthday.year).to eq(2000)
expect(profile.birthday.month).to eq(1)
expect(profile.birthday.day).to eq(1)
end
it 'does not accept blank initial values' do
it "does not accept blank initial values" do
profile.birthday = nil
profile.date = { 'year' => '2001', 'month' => '', 'day' => ''}
profile.date = {"year" => "2001", "month" => "", "day" => ""}
expect(profile.birthday).to eq(nil)
end
it 'does not accept invalid dates' do
it "does not accept invalid dates" do
profile.birthday = nil
profile.date = { 'year' => '2001', 'month' => '02', 'day' => '31' }
profile.date = {"year" => "2001", "month" => "02", "day" => "31"}
expect(profile.birthday).to eq(nil)
end
it 'does not change with invalid dates' do
it "does not change with invalid dates" do
profile.birthday = Date.new(2000, 1, 1)
profile.date = { 'year' => '2001', 'month' => '02', 'day' => '31' }
profile.date = {"year" => "2001", "month" => "02", "day" => "31"}
expect(profile.birthday.year).to eq(2000)
expect(profile.birthday.month).to eq(1)
expect(profile.birthday.day).to eq(1)
@ -304,12 +315,12 @@ describe Profile, :type => :model do
@profile.tombstone!
@profile.reload
attributes.each{ |attr|
attributes.each {|attr|
expect(@profile[attr.to_sym]).to be_blank
}
end
it 'removes all the tags from the profile' do
it "removes all the tags from the profile" do
expect(@profile.taggings).to receive(:delete_all)
@profile.tombstone!
end
@ -322,23 +333,23 @@ describe Profile, :type => :model do
end
describe "#clearable_fields" do
it 'returns the current profile fields' do
it "returns the current profile fields" do
profile = FactoryBot.build :profile
expect(profile.send(:clearable_fields).sort).to eq(
["diaspora_handle",
"first_name",
"last_name",
"image_url",
"image_url_small",
"image_url_medium",
"birthday",
"gender",
"bio",
"searchable",
"nsfw",
"location",
"public_details",
"full_name"].sort
%w[diaspora_handle
first_name
last_name
image_url
image_url_small
image_url_medium
birthday
gender
bio
searchable
nsfw
location
public_details
full_name].sort
)
end
end

View file

@ -26,7 +26,7 @@ describe Reshare, type: :model do
reshare1 = FactoryBot.create(:reshare, author: alice.person)
reshare2 = FactoryBot.create(:reshare, author: alice.person)
reshare1.update_attributes(root_guid: nil)
reshare1.update(root_guid: nil)
reshare2.root_guid = nil
expect(reshare2).to be_valid
@ -97,19 +97,19 @@ describe Reshare, type: :model do
describe "#absolute_root" do
before do
@status_message = FactoryBot.build(:status_message, author: alice.person, public: true)
reshare_1 = FactoryBot.build(:reshare, root: @status_message)
reshare_2 = FactoryBot.build(:reshare, root: reshare_1)
@reshare_3 = FactoryBot.build(:reshare, root: reshare_2)
reshare1 = FactoryBot.build(:reshare, root: @status_message)
reshare2 = FactoryBot.build(:reshare, root: reshare1)
@reshare3 = FactoryBot.build(:reshare, root: reshare2)
status_message = FactoryBot.create(:status_message, author: alice.person, public: true)
reshare_1 = FactoryBot.create(:reshare, root: status_message)
@of_deleted = FactoryBot.build(:reshare, root: reshare_1)
reshare1 = FactoryBot.create(:reshare, root: status_message)
@of_deleted = FactoryBot.build(:reshare, root: reshare1)
status_message.destroy
reshare_1.reload
reshare1.reload
end
it "resolves root posts to the top level" do
expect(@reshare_3.absolute_root).to eq(@status_message)
expect(@reshare3.absolute_root).to eq(@status_message)
end
it "can handle deleted reshares" do
@ -117,19 +117,19 @@ describe Reshare, type: :model do
end
it "is used everywhere" do
expect(@reshare_3.message).to eq @status_message.message
expect(@reshare3.message).to eq @status_message.message
expect(@of_deleted.message).to be_nil
expect(@reshare_3.photos).to eq @status_message.photos
expect(@reshare3.photos).to eq @status_message.photos
expect(@of_deleted.photos).to be_empty
expect(@reshare_3.o_embed_cache).to eq @status_message.o_embed_cache
expect(@reshare3.o_embed_cache).to eq @status_message.o_embed_cache
expect(@of_deleted.o_embed_cache).to be_nil
expect(@reshare_3.open_graph_cache).to eq @status_message.open_graph_cache
expect(@reshare3.open_graph_cache).to eq @status_message.open_graph_cache
expect(@of_deleted.open_graph_cache).to be_nil
expect(@reshare_3.mentioned_people).to eq @status_message.mentioned_people
expect(@reshare3.mentioned_people).to eq @status_message.mentioned_people
expect(@of_deleted.mentioned_people).to be_empty
expect(@reshare_3.nsfw).to eq @status_message.nsfw
expect(@reshare3.nsfw).to eq @status_message.nsfw
expect(@of_deleted.nsfw).to be_nil
expect(@reshare_3.address).to eq @status_message.location.try(:address)
expect(@reshare3.address).to eq @status_message.location.try(:address)
expect(@of_deleted.address).to be_nil
end
end

View file

@ -31,10 +31,10 @@ describe StatusMessage, type: :model do
context "tag_streams" do
before do
@status_message_1 = FactoryBot.create(:status_message, text: "#hashtag", public: true)
@status_message_2 = FactoryBot.create(:status_message, text: "#hashtag")
@status_message_3 = FactoryBot.create(:status_message, text: "hashtags are #awesome", public: true)
@status_message_4 = FactoryBot.create(:status_message, text: "hashtags are #awesome")
@status_message1 = FactoryBot.create(:status_message, text: "#hashtag", public: true)
@status_message2 = FactoryBot.create(:status_message, text: "#hashtag")
@status_message3 = FactoryBot.create(:status_message, text: "hashtags are #awesome", public: true)
@status_message4 = FactoryBot.create(:status_message, text: "hashtags are #awesome")
@tag_id = ActsAsTaggableOn::Tag.where(name: "hashtag").first.id
end
@ -42,14 +42,14 @@ describe StatusMessage, type: :model do
describe ".tag_steam" do
it "returns status messages tagged with the tag" do
tag_stream = StatusMessage.send(:tag_stream, [@tag_id])
expect(tag_stream).to include @status_message_1
expect(tag_stream).to include @status_message_2
expect(tag_stream).to include @status_message1
expect(tag_stream).to include @status_message2
end
end
describe ".public_tag_stream" do
it "returns public status messages tagged with the tag" do
expect(StatusMessage.public_tag_stream([@tag_id])).to eq([@status_message_1])
expect(StatusMessage.public_tag_stream([@tag_id])).to eq([@status_message1])
end
it "returns a post with two tags only once" do
@ -57,7 +57,7 @@ describe StatusMessage, type: :model do
test_tag_id = ActsAsTaggableOn::Tag.where(name: "test").first.id
expect(StatusMessage.public_tag_stream([@tag_id, test_tag_id]))
.to match_array([@status_message_1, status_message])
.to match_array([@status_message1, status_message])
end
end
@ -75,10 +75,10 @@ describe StatusMessage, type: :model do
describe ".guids_for_author" do
it "returns an array of the status_message guids" do
status_message_1 = FactoryBot.create(:status_message, author: alice.person)
status_message1 = FactoryBot.create(:status_message, author: alice.person)
FactoryBot.create(:status_message, author: bob.person)
guids = StatusMessage.guids_for_author(alice.person)
expect(guids).to eq([status_message_1.guid])
expect(guids).to eq([status_message1.guid])
end
end

View file

@ -98,7 +98,7 @@ describe User::Querying, :type => :model do
describe "#visible_shareables" do
it 'never contains posts from people not in your aspects' do
FactoryBot.create(:status_message, :public => true)
FactoryBot.create(:status_message, public: true)
expect(bob.visible_shareables(Post).count(:all)).to eq(0)
end

View file

@ -4,7 +4,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
describe User, :type => :model do
describe User, type: :model do
context "relations" do
context "#conversations" do
it "doesn't find anything when there is nothing to find" do
@ -13,7 +13,7 @@ describe User, :type => :model do
end
it "finds the users conversations" do
c = FactoryBot.create(:conversation, { author: alice.person })
c = FactoryBot.create(:conversation, {author: alice.person})
expect(alice.conversations).to include c
end
@ -21,7 +21,7 @@ describe User, :type => :model do
it "doesn't find other users conversations" do
c1 = FactoryBot.create(:conversation)
c2 = FactoryBot.create(:conversation)
c_own = FactoryBot.create(:conversation, { author: alice.person })
c_own = FactoryBot.create(:conversation, {author: alice.person})
expect(alice.conversations).to include c_own
expect(alice.conversations).not_to include c1
@ -31,175 +31,170 @@ describe User, :type => :model do
end
describe "private key" do
it 'has a key' do
it "has a key" do
expect(alice.encryption_key).not_to be nil
end
it 'marshalls the key to and from the db correctly' do
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password')
it "marshalls the key to and from the db correctly" do
user = User.build(username: "max", email: "foo@bar.com", password: "password", password_confirmation: "password")
user.save!
expect(user.serialized_private_key).to be_present
expect{
expect {
user.reload.encryption_key
}.to_not raise_error
end
end
describe 'yearly_actives' do
it 'returns list which includes users within last year' do
describe "yearly_actives" do
it "returns list which includes users within last year" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 1.month
user.last_seen = Time.zone.now - 1.month
user.save
expect(User.yearly_actives).to include user
end
it 'returns list which does not include users seen within last year' do
it "returns list which does not include users seen within last year" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 2.year
user.last_seen = Time.zone.now - 2.years
user.save
expect(User.yearly_actives).not_to include user
end
end
describe 'monthly_actives' do
it 'returns list which includes users seen within last month' do
describe "monthly_actives" do
it "returns list which includes users seen within last month" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 1.day
user.last_seen = Time.zone.now - 1.day
user.save
expect(User.monthly_actives).to include user
end
it 'returns list which does not include users seen within last month' do
it "returns list which does not include users seen within last month" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 2.month
user.last_seen = Time.zone.now - 2.months
user.save
expect(User.monthly_actives).not_to include user
end
end
describe 'daily_actives' do
it 'returns list which includes users seen within last day' do
describe "daily_actives" do
it "returns list which includes users seen within last day" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 1.hour
user.last_seen = Time.zone.now - 1.hour
user.save
expect(User.daily_actives).to include(user)
end
it 'returns list which does not include users seen within last day' do
it "returns list which does not include users seen within last day" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 2.day
user.last_seen = Time.zone.now - 2.days
user.save
expect(User.daily_actives).not_to include(user)
end
end
describe 'halfyear_actives' do
it 'returns list which includes users seen within half a year' do
describe "halfyear_actives" do
it "returns list which includes users seen within half a year" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 4.month
user.last_seen = Time.zone.now - 4.months
user.save
expect(User.halfyear_actives).to include user
end
it 'returns list which does not include users seen within the last half a year' do
it "returns list which does not include users seen within the last half a year" do
user = FactoryBot.build(:user)
user.last_seen = Time.now - 7.month
user.last_seen = Time.zone.now - 7.months
user.save
expect(User.halfyear_actives).not_to include user
end
end
describe 'hidden_shareables' do
describe "hidden_shareables" do
before do
@sm = FactoryBot.create(:status_message)
@sm_id = @sm.id.to_s
@sm_class = @sm.class.base_class.to_s
end
it 'is a hash' do
it "is a hash" do
expect(alice.hidden_shareables).to eq({})
end
describe '#add_hidden_shareable' do
it 'adds the share id to an array which is keyed by the objects class' do
describe "#add_hidden_shareable" do
it "adds the share id to an array which is keyed by the objects class" do
alice.add_hidden_shareable(@sm_class, @sm_id)
expect(alice.hidden_shareables['Post']).to eq([@sm_id])
expect(alice.hidden_shareables["Post"]).to eq([@sm_id])
end
it 'handles having multiple posts' do
it "handles having multiple posts" do
sm2 = FactoryBot.build(:status_message)
alice.add_hidden_shareable(@sm_class, @sm_id)
alice.add_hidden_shareable(sm2.class.base_class.to_s, sm2.id.to_s)
expect(alice.hidden_shareables['Post']).to match_array([@sm_id, sm2.id.to_s])
expect(alice.hidden_shareables["Post"]).to match_array([@sm_id, sm2.id.to_s])
end
it 'handles having multiple shareable types' do
it "handles having multiple shareable types" do
photo = FactoryBot.create(:photo)
alice.add_hidden_shareable(photo.class.base_class.to_s, photo.id.to_s)
alice.add_hidden_shareable(@sm_class, @sm_id)
expect(alice.hidden_shareables['Photo']).to eq([photo.id.to_s])
expect(alice.hidden_shareables["Photo"]).to eq([photo.id.to_s])
end
end
describe '#remove_hidden_shareable' do
it 'removes the id from the hash if it is there' do
describe "#remove_hidden_shareable" do
it "removes the id from the hash if it is there" do
alice.add_hidden_shareable(@sm_class, @sm_id)
alice.remove_hidden_shareable(@sm_class, @sm_id)
expect(alice.hidden_shareables['Post']).to eq([])
expect(alice.hidden_shareables["Post"]).to eq([])
end
end
describe 'toggle_hidden_shareable' do
it 'calls add_hidden_shareable if the key does not exist, and returns true' do
describe "toggle_hidden_shareable" do
it "calls add_hidden_shareable if the key does not exist, and returns true" do
expect(alice).to receive(:add_hidden_shareable).with(@sm_class, @sm_id)
expect(alice.toggle_hidden_shareable(@sm)).to be true
end
it 'calls remove_hidden_shareable if the key exists' do
it "calls remove_hidden_shareable if the key exists" do
expect(alice).to receive(:remove_hidden_shareable).with(@sm_class, @sm_id)
alice.add_hidden_shareable(@sm_class, @sm_id)
expect(alice.toggle_hidden_shareable(@sm)).to be false
end
end
describe '#is_shareable_hidden?' do
it 'returns true if the shareable is hidden' do
describe "#is_shareable_hidden?" do
it "returns true if the shareable is hidden" do
post = FactoryBot.create(:status_message)
bob.toggle_hidden_shareable(post)
expect(bob.is_shareable_hidden?(post)).to be true
end
it 'returns false if the shareable is not present' do
it "returns false if the shareable is not present" do
post = FactoryBot.create(:status_message)
expect(bob.is_shareable_hidden?(post)).to be false
end
end
end
describe 'overwriting people' do
it 'does not overwrite old users with factory' do
describe "overwriting people" do
it "does not overwrite old users with factory" do
expect {
new_user = FactoryBot.create(:user, :id => alice.id)
FactoryBot.create(:user, id: alice.id)
}.to raise_error ActiveRecord::StatementInvalid
end
it 'does not overwrite old users with create' do
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
params[:id] = alice.id
it "does not overwrite old users with create" do
params = {username: "ohai",
email: "ohai@example.com",
password: "password",
password_confirmation: "password",
person: {profile: {first_name: "O",
last_name: "Hai"}}}
params[:id] = alice.id
new_user = User.build(params)
new_user.save
expect(new_user.persisted?).to be true
@ -233,15 +228,14 @@ describe User, :type => :model do
expect(alice).not_to be_valid
end
it 'requires uniqueness also amount Person objects with diaspora handle' do
p = FactoryBot.create(:person, :diaspora_handle => "jimmy#{User.diaspora_id_host}")
alice.username = 'jimmy'
it "requires uniqueness also amount Person objects with diaspora handle" do
FactoryBot.create(:person, diaspora_handle: "jimmy#{User.diaspora_id_host}")
alice.username = "jimmy"
expect(alice).not_to be_valid
end
it "downcases username" do
user = FactoryBot.build(:user, :username => "WeIrDcAsE")
user = FactoryBot.build(:user, username: "WeIrDcAsE")
expect(user).to be_valid
expect(user.username).to eq("weirdcase")
end
@ -252,7 +246,7 @@ describe User, :type => :model do
end
it "strips leading and trailing whitespace" do
user = FactoryBot.build(:user, :username => " janie ")
user = FactoryBot.build(:user, username: " janie ")
expect(user).to be_valid
expect(user.username).to eq("janie")
end
@ -262,12 +256,12 @@ describe User, :type => :model do
expect(alice).not_to be_valid
end
it 'can not contain non url safe characters' do
it "can not contain non url safe characters" do
alice.username = "kittens;"
expect(alice).not_to be_valid
end
it 'should not contain periods' do
it "should not contain periods" do
alice.username = "kittens."
expect(alice).not_to be_valid
end
@ -278,13 +272,13 @@ describe User, :type => :model do
end
it "cannot be 33 characters" do
alice.username = "hexagooooooooooooooooooooooooooon"
alice.username = "hexagooooooooooooooooooooooooooon"
expect(alice).not_to be_valid
end
it "cannot be one of the blacklist names" do
['hostmaster', 'postmaster', 'root', 'webmaster'].each do |username|
alice.username = username
%w[hostmaster postmaster root webmaster].each do |username|
alice.username = username
expect(alice).not_to be_valid
end
end
@ -307,8 +301,8 @@ describe User, :type => :model do
end
it "resets a matching unconfirmed_email and confirm_email_token on save" do
eve.update_attributes(unconfirmed_email: "new@example.com", confirm_email_token: SecureRandom.hex(15))
alice.update_attribute(:email, "new@example.com")
eve.update(unconfirmed_email: "new@example.com", confirm_email_token: SecureRandom.hex(15))
alice.update(email: "new@example.com")
eve.reload
expect(eve.unconfirmed_email).to eql(nil)
expect(eve.confirm_email_token).to eql(nil)
@ -324,7 +318,7 @@ describe User, :type => :model do
end
it "does NOT require a unique unconfirmed_email address" do
eve.update_attribute :unconfirmed_email, "new@example.com"
eve.update(unconfirmed_email: "new@example.com")
alice.unconfirmed_email = "new@example.com"
expect(alice).to be_valid
end
@ -346,20 +340,21 @@ describe User, :type => :model do
end
it "requires availability" do
alice.language = 'some invalid language'
alice.language = "some invalid language"
expect(alice).not_to be_valid
end
it "should save with current language if blank" do
I18n.locale = :fr
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password')
expect(user.language).to eq('fr')
user = User.build username: "max", email: "foo@bar.com", password: "password", password_confirmation: "password"
expect(user.language).to eq("fr")
end
it "should save with language what is set" do
I18n.locale = :fr
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password', :language => 'de')
expect(user.language).to eq('de')
user = User.build(username: "max", email: "foo@bar.com", password: "password",
password_confirmation: "password", language: "de")
expect(user.language).to eq("de")
end
end
@ -371,46 +366,42 @@ describe User, :type => :model do
end
end
describe ".build" do
context 'with valid params' do
context "with valid params" do
before do
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
params = {username: "ohai",
email: "ohai@example.com",
password: "password",
password_confirmation: "password",
person: {profile: {first_name: "O",
last_name: "Hai"}}}
@user = User.build(params)
end
it "does not save" do
expect(@user.persisted?).to be false
expect(@user.person.persisted?).to be false
expect(User.find_by_username("ohai")).to be_nil
expect(User.find_by(username: "ohai")).to be_nil
end
it 'saves successfully' do
it "saves successfully" do
expect(@user).to be_valid
expect(@user.save).to be true
expect(@user.persisted?).to be true
expect(@user.person.persisted?).to be true
expect(User.find_by_username("ohai")).to eq(@user)
expect(User.find_by(username: "ohai")).to eq(@user)
end
end
describe "with invalid params" do
before do
@invalid_params = {
:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "wrongpasswordz",
:person => {:profile => {:first_name => "", :last_name => ""}}}
username: "ohai",
email: "ohai@example.com",
password: "password",
password_confirmation: "wrongpasswordz",
person: {profile: {first_name: "", last_name: ""}}
}
end
it "raises no error" do
@ -421,30 +412,26 @@ describe User, :type => :model do
expect(User.build(@invalid_params).save).to be false
end
it 'does not save a person' do
it "does not save a person" do
expect { User.build(@invalid_params) }.not_to change(Person, :count)
end
it 'does not generate a key' do
it "does not generate a key" do
expect(User).to receive(:generate_key).exactly(0).times
User.build(@invalid_params)
end
end
describe "with malicious params" do
let(:person) {FactoryBot.create :person}
let(:person) { FactoryBot.create :person }
before do
@invalid_params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:id => person.id,
:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
@invalid_params = {username: "ohai",
email: "ohai@example.com",
password: "password",
password_confirmation: "password",
person: {id: person.id,
profile: {first_name: "O",
last_name: "Hai"}}}
end
it "does not assign it to the person" do
@ -453,60 +440,60 @@ describe User, :type => :model do
end
end
describe '#process_invite_acceptence' do
it 'sets the inviter on user' do
inv = InvitationCode.create(:user => bob)
describe "#process_invite_acceptence" do
it "sets the inviter on user" do
inv = InvitationCode.create(user: bob)
user = FactoryBot.build(:user)
user.process_invite_acceptence(inv)
expect(user.invited_by_id).to eq(bob.id)
end
end
describe 'update_user_preferences' do
describe "update_user_preferences" do
before do
@pref_count = UserPreference::VALID_EMAIL_TYPES.count
end
it 'unsets disable mail and makes the right amount of prefs' do
it "unsets disable mail and makes the right amount of prefs" do
alice.disable_mail = true
expect {
alice.update_user_preferences({})
}.to change(alice.user_preferences, :count).by(@pref_count)
end
it 'still sets new prefs to false on update' do
it "still sets new prefs to false on update" do
alice.disable_mail = true
expect {
alice.update_user_preferences({'mentioned' => false})
}.to change(alice.user_preferences, :count).by(@pref_count-1)
alice.update_user_preferences({"mentioned" => false})
}.to change(alice.user_preferences, :count).by(@pref_count - 1)
expect(alice.reload.disable_mail).to be false
end
end
describe ".find_for_database_authentication" do
it 'finds a user' do
expect(User.find_for_database_authentication(:username => alice.username)).to eq(alice)
it "finds a user" do
expect(User.find_for_database_authentication(username: alice.username)).to eq(alice)
end
it 'finds a user by email' do
expect(User.find_for_database_authentication(:username => alice.email)).to eq(alice)
it "finds a user by email" do
expect(User.find_for_database_authentication(username: alice.email)).to eq(alice)
end
it "does not preserve case" do
expect(User.find_for_database_authentication(:username => alice.username.upcase)).to eq(alice)
expect(User.find_for_database_authentication(username: alice.username.upcase)).to eq(alice)
end
end
describe '#update_profile' do
describe "#update_profile" do
before do
@params = {
:first_name => 'bob',
:last_name => 'billytown',
first_name: "bob",
last_name: "billytown"
}
end
it "dispatches the profile when tags are set" do
@params = {tag_string: '#what #hey'}
@params = {tag_string: "#what #hey"}
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, alice.profile, {})
expect(alice.update_profile(@params)).to be true
end
@ -516,29 +503,29 @@ describe User, :type => :model do
expect(alice.update_profile(@params)).to be true
end
it 'updates names' do
it "updates names" do
expect(alice.update_profile(@params)).to be true
expect(alice.reload.profile.first_name).to eq('bob')
expect(alice.reload.profile.first_name).to eq("bob")
end
it 'updates image_url' do
params = {:image_url => "http://clown.com"}
it "updates image_url" do
params = {image_url: "http://clown.com"}
expect(alice.update_profile(params)).to be true
expect(alice.reload.profile.image_url).to eq("http://clown.com")
end
context 'passing in a photo' do
context "passing in a photo" do
before do
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
fixture_filename = "button.png"
fixture_name = File.join(File.dirname(__FILE__), "..", "fixtures", fixture_filename)
image = File.open(fixture_name)
@photo = Photo.diaspora_initialize(:author => alice.person, :user_file => image)
@photo = Photo.diaspora_initialize(author: alice.person, user_file: image)
@photo.save!
@params = {:photo => @photo}
@params = {photo: @photo}
end
it 'updates image_url' do
it "updates image_url" do
expect(alice.update_profile(@params)).to be true
alice.reload
@ -547,7 +534,7 @@ describe User, :type => :model do
expect(alice.profile.image_url_small).to match(Regexp.new(@photo.url(:thumb_small)))
end
it 'unpends the photo' do
it "unpends the photo" do
@photo.pending = true
@photo.save!
@photo.reload
@ -557,11 +544,11 @@ describe User, :type => :model do
end
end
describe '#update_post' do
it 'should dispatch post' do
photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id)
describe "#update_post" do
it "should dispatch post" do
photo = alice.build_post(:photo, user_file: uploaded_photo, text: "hello", to: alice.aspects.first.id)
expect(alice).to receive(:dispatch_post).with(photo)
alice.update_post(photo, :text => 'hellp')
alice.update_post(photo, text: "hellp")
end
end
@ -573,42 +560,42 @@ describe User, :type => :model do
end
end
describe '#mail' do
it 'enqueues a mail job' do
describe "#mail" do
it "enqueues a mail job" do
alice.disable_mail = false
alice.save
expect(Workers::Mail::StartedSharing).to receive(:perform_async).with(alice.id, 'contactrequestid').once
alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid')
expect(Workers::Mail::StartedSharing).to receive(:perform_async).with(alice.id, "contactrequestid").once
alice.mail(Workers::Mail::StartedSharing, alice.id, "contactrequestid")
end
it 'does not enqueue a mail job if the correct corresponding job has a preference entry' do
alice.user_preferences.create(:email_type => 'started_sharing')
it "does not enqueue a mail job if the correct corresponding job has a preference entry" do
alice.user_preferences.create(email_type: "started_sharing")
expect(Workers::Mail::StartedSharing).not_to receive(:perform_async)
alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid')
alice.mail(Workers::Mail::StartedSharing, alice.id, "contactrequestid")
end
it 'does not send a mail if disable_mail is set to true' do
alice.disable_mail = true
alice.save
alice.reload
expect(Workers::Mail::StartedSharing).not_to receive(:perform_async)
alice.mail(Workers::Mail::StartedSharing, alice.id, 'contactrequestid')
it "does not send a mail if disable_mail is set to true" do
alice.disable_mail = true
alice.save
alice.reload
expect(Workers::Mail::StartedSharing).not_to receive(:perform_async)
alice.mail(Workers::Mail::StartedSharing, alice.id, "contactrequestid")
end
end
context 'likes' do
context "likes" do
before do
alices_aspect = alice.aspects.where(:name => "generic").first
@bobs_aspect = bob.aspects.where(:name => "generic").first
@message = alice.post(:status_message, :text => "cool", :to => alices_aspect)
@message2 = bob.post(:status_message, :text => "uncool", :to => @bobs_aspect)
alices_aspect = alice.aspects.where(name: "generic").first
@bobs_aspect = bob.aspects.where(name: "generic").first
@message = alice.post(:status_message, text: "cool", to: alices_aspect)
@message2 = bob.post(:status_message, text: "uncool", to: @bobs_aspect)
@like = alice.like!(@message)
@like2 = bob.like!(@message)
end
describe '#like_for' do
it 'returns the correct like' do
describe "#like_for" do
it "returns the correct like" do
expect(alice.like_for(@message)).to eq(@like)
expect(bob.like_for(@message)).to eq(@like2)
end
@ -618,7 +605,7 @@ describe User, :type => :model do
end
end
describe '#liked?' do
describe "#liked?" do
it "returns true if there's a like" do
expect(alice.liked?(@message)).to be true
expect(bob.liked?(@message)).to be true
@ -630,8 +617,8 @@ describe User, :type => :model do
end
end
context 'change email' do
let(:user){ alice }
context "change email" do
let(:user) { alice }
describe "#unconfirmed_email" do
it "is nil by default" do
@ -697,7 +684,7 @@ describe User, :type => :model do
describe "#send_confirm_email" do
it "enqueues a mail job on user with unconfirmed email" do
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
user.update(unconfirmed_email: "alice@newmail.com")
expect(Workers::Mail::ConfirmEmail).to receive(:perform_async).with(alice.id).once
alice.send_confirm_email
end
@ -708,34 +695,34 @@ describe User, :type => :model do
end
end
describe '#confirm_email' do
context 'on user with unconfirmed email' do
describe "#confirm_email" do
context "on user with unconfirmed email" do
before do
user.update_attribute(:unconfirmed_email, "alice@newmail.com")
user.update(unconfirmed_email: "alice@newmail.com")
end
it 'confirms email and set the unconfirmed_email to email on valid token' do
it "confirms email and set the unconfirmed_email to email on valid token" do
expect(user.confirm_email(user.confirm_email_token)).to eql(true)
expect(user.email).to eql("alice@newmail.com")
expect(user.unconfirmed_email).to eql(nil)
expect(user.confirm_email_token).to eql(nil)
end
it 'returns false and does not change anything on wrong token' do
it "returns false and does not change anything on wrong token" do
expect(user.confirm_email(user.confirm_email_token.reverse)).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).not_to eql(nil)
expect(user.confirm_email_token).not_to eql(nil)
end
it 'returns false and does not change anything on blank token' do
it "returns false and does not change anything on blank token" do
expect(user.confirm_email("")).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).not_to eql(nil)
expect(user.confirm_email_token).not_to eql(nil)
end
it 'returns false and does not change anything on blank token' do
it "returns false and does not change anything on blank token" do
expect(user.confirm_email(nil)).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).not_to eql(nil)
@ -743,22 +730,22 @@ describe User, :type => :model do
end
end
context 'on user without unconfirmed email' do
it 'returns false and does not change anything on any token' do
expect(user.confirm_email("12345"*6)).to eql(false)
context "on user without unconfirmed email" do
it "returns false and does not change anything on any token" do
expect(user.confirm_email("12345" * 6)).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).to eql(nil)
expect(user.confirm_email_token).to eql(nil)
end
it 'returns false and does not change anything on blank token' do
it "returns false and does not change anything on blank token" do
expect(user.confirm_email("")).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).to eql(nil)
expect(user.confirm_email_token).to eql(nil)
end
it 'returns false and does not change anything on blank token' do
it "returns false and does not change anything on blank token" do
expect(user.confirm_email(nil)).to eql(false)
expect(user.email).not_to eql("alice@newmail.com")
expect(user.unconfirmed_email).to eql(nil)
@ -768,7 +755,6 @@ describe User, :type => :model do
end
end
describe "#retract" do
let(:retraction) { double }
let(:post) { FactoryBot.build(:status_message, author: bob.person, public: true) }
@ -800,10 +786,10 @@ describe User, :type => :model do
user
}
[I18n.t('aspects.seed.family'), I18n.t('aspects.seed.friends'),
I18n.t('aspects.seed.work'), I18n.t('aspects.seed.acquaintances')].each do |aspect_name|
[I18n.t("aspects.seed.family"), I18n.t("aspects.seed.friends"),
I18n.t("aspects.seed.work"), I18n.t("aspects.seed.acquaintances")].each do |aspect_name|
it "creates an aspect named #{aspect_name} for the user" do
expect(user.aspects.find_by_name(aspect_name)).not_to be_nil
expect(user.aspects.find_by(name: aspect_name)).not_to be_nil
end
end
end
@ -855,7 +841,7 @@ describe User, :type => :model do
it "should send welcome message text from config" do
AppConfig.admins.account = podmin.username
AppConfig.settings.welcome_message.text = "Hello %{username}, welcome!"
AppConfig.settings.welcome_message.text = "Hello %{username}, welcome!" # rubocop:disable Style/FormatStringToken
user.send_welcome_message
expect(user.conversations.first.messages.first.text).to eq "Hello #{user.username}, welcome!"
end
@ -896,32 +882,32 @@ describe User, :type => :model do
end
describe "#close_account!" do
it 'locks the user out' do
it "locks the user out" do
@user.close_account!
expect(@user.reload.access_locked?).to be true
end
it 'creates an account deletion' do
expect{
it "creates an account deletion" do
expect {
@user.close_account!
}.to change(AccountDeletion, :count).by(1)
end
it 'calls person#lock_access!' do
it "calls person#lock_access!" do
expect(@user.person).to receive(:lock_access!)
@user.close_account!
end
end
describe "#clear_account!" do
it 'resets the password to a random string' do
it "resets the password to a random string" do
random_pass = "12345678909876543210"
expect(SecureRandom).to receive(:hex).and_return(random_pass)
@user.clear_account!
@user.valid_password?(random_pass)
end
it 'clears all the clearable fields' do
it "clears all the clearable fields" do
@user.reload
attributes = @user.send(:clearable_fields)
@user.clear_account!
@ -961,7 +947,7 @@ describe User, :type => :model do
it "returns the clearable fields" do
user = FactoryBot.create :user
expect(user.send(:clearable_fields)).to match_array(
%w(
%w[
language
reset_password_sent_at
reset_password_token
@ -988,7 +974,7 @@ describe User, :type => :model do
otp_backup_codes
otp_required_for_login
otp_secret
)
]
)
end
end
@ -1090,18 +1076,14 @@ describe User, :type => :model do
describe "sign up" do
before do
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:captcha => "12345",
params = {username: "ohai",
email: "ohai@example.com",
password: "password",
password_confirmation: "password",
captcha: "12345",
:person =>
{:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
person: {profile: {first_name: "O",
last_name: "Hai"}}}
@user = User.build(params)
end
@ -1134,7 +1116,7 @@ describe User, :type => :model do
describe "#auth database auth maintenance" do
before do
@user = bob
@user.remove_after = Time.now
@user.remove_after = Time.zone.now
@user.save
end
@ -1151,7 +1133,7 @@ describe User, :type => :model do
end
it "returns total_users excluding closed accounts & users without usernames" do
expect(User.active.count).to eq 6 # 6 users from fixtures
expect(User.active.count).to eq 6 # 6 users from fixtures
end
end
end

View file

@ -2,35 +2,35 @@
describe OEmbedPresenter do
before do
@oembed = OEmbedPresenter.new(FactoryBot.create(:status_message))
@oembed = OEmbedPresenter.new(FactoryBot.create(:status_message))
end
it 'is a hash' do
it "is a hash" do
expect(@oembed.as_json).to be_a Hash
end
context 'required options from oembed spec' do
it 'supports maxheight + maxwidth(required)' do
oembed = OEmbedPresenter.new(FactoryBot.create(:status_message), :maxwidth => 200, :maxheight => 300).as_json
context "required options from oembed spec" do
it "supports maxheight + maxwidth(required)" do
oembed = OEmbedPresenter.new(FactoryBot.create(:status_message), maxwidth: 200, maxheight: 300).as_json
expect(oembed[:width]).to eq(200)
expect(oembed[:height]).to eq(300)
end
end
describe '#iframe_html' do
it 'passes the height options to post_iframe_url' do
describe "#iframe_html" do
it "passes the height options to post_iframe_url" do
expect(@oembed).to receive(:post_iframe_url).with(kind_of(Integer), instance_of(Hash))
@oembed.iframe_html
end
end
describe '.id_from_url' do
it 'takes a long post url and gives you the id' do
expect(OEmbedPresenter.id_from_url('http://localhost:400/posts/1')).to eq("1")
describe ".id_from_url" do
it "takes a long post url and gives you the id" do
expect(OEmbedPresenter.id_from_url("http://localhost:400/posts/1")).to eq("1")
end
it 'takes a short post url and gives you the id' do
expect(OEmbedPresenter.id_from_url('http://localhost:400/p/1')).to eq("1")
it "takes a short post url and gives you the id" do
expect(OEmbedPresenter.id_from_url("http://localhost:400/p/1")).to eq("1")
end
end
end

View file

@ -3,7 +3,7 @@
describe PersonPresenter do
let(:profile_user) {
FactoryBot.create(:user_with_aspect,
profile: FactoryBot.create(:profile_with_image_url))
profile: FactoryBot.create(:profile_with_image_url))
}
let(:person) { profile_user.person }
@ -28,18 +28,18 @@ describe PersonPresenter do
it "returns the user's additional profile if the user has set additional profile public" do
person.profile.public_details = true
expect(PersonPresenter.new(person, nil).as_json[:profile]).to include(*%i(location bio gender birthday))
expect(PersonPresenter.new(person, nil).as_json[:profile]).to include(:location, :bio, :gender, :birthday)
end
it "doesn't return user's additional profile if the user hasn't set additional profile public" do
person.profile.public_details = false
expect(PersonPresenter.new(person, nil).as_json[:profile]).not_to include(*%i(location bio gender birthday))
expect(PersonPresenter.new(person, nil).as_json[:profile]).not_to include(:location, :bio, :gender, :birthday)
end
end
context "with a current_user" do
let(:current_user) { FactoryBot.create(:user) }
let(:presenter){ PersonPresenter.new(person, current_user) }
let(:presenter) { PersonPresenter.new(person, current_user) }
# here private information == addtional user profile, because additional profile by default is private
it "doesn't share private information when the users aren't connected" do
@ -149,7 +149,7 @@ describe PersonPresenter do
describe "#profile_hash_as_api_json" do
let(:current_user) {
FactoryBot.create(:user,
profile: FactoryBot.create(:profile_with_image_url))
profile: FactoryBot.create(:profile_with_image_url))
}
before do

View file

@ -2,25 +2,26 @@
describe Workers::FetchProfilePhoto do
before do
@user = alice
@service = FactoryBot.build(:service, :user => alice)
@user = alice
@service = FactoryBot.build(:service, user: alice)
@url = "https://service.com/user/profile_image"
@url = "https://service.com/user/profile_image"
allow(@service).to receive(:profile_photo_url).and_return(@url)
allow(@user).to receive(:update_profile)
allow(@service).to receive(:profile_photo_url).and_return(@url)
allow(@user).to receive(:update_profile)
allow(User).to receive(:find).and_return(@user)
allow(Service).to receive(:find).and_return(@service)
allow(User).to receive(:find).and_return(@user)
allow(Service).to receive(:find).and_return(@service)
@photo_double = double
allow(@photo_double).to receive(:save!).and_return(true)
allow(@photo_double).to receive(:url).and_return("image.jpg")
end
it 'saves the profile image' do
it "saves the profile image" do
expect(@photo_double).to receive(:save!).and_return(true)
expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_double)
expect(Photo).to receive(:diaspora_initialize)
.with(hash_including(author: @user.person, image_url: @url, pending: true)).and_return(@photo_double)
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
end
@ -36,22 +37,23 @@ describe Workers::FetchProfilePhoto do
it "fetches fallback if it's provided" do
expect(@photo_double).to receive(:save!).and_return(true)
allow(@service).to receive(:profile_photo_url).and_return(nil)
expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_double)
expect(Photo).to receive(:diaspora_initialize)
.with(hash_including(author: @user.person, image_url: "https://service.com/fallback_lowres.jpg", pending: true))
.and_return(@photo_double)
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id, "https://service.com/fallback_lowres.jpg")
end
end
it 'updates the profile' do
it "updates the profile" do
allow(@photo_double).to receive(:url).and_return("large.jpg", "medium.jpg", "small.jpg")
expect(Photo).to receive(:diaspora_initialize).and_return(@photo_double)
expect(@user).to receive(:update_profile).with(hash_including({
:image_url => "large.jpg",
:image_url_medium => "medium.jpg",
:image_url_small => "small.jpg"
}))
image_url: "large.jpg",
image_url_medium: "medium.jpg",
image_url_small: "small.jpg"
}))
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
end

View file

@ -7,10 +7,10 @@
describe Workers::Mail::Reshared do
describe "#perform" do
it "should call .deliver on the notifier object" do
sm = FactoryBot.build(:status_message, :author => bob.person, :public => true)
reshare = FactoryBot.build(:reshare, :author => alice.person, :root=> sm)
sm = FactoryBot.build(:status_message, author: bob.person, public: true)
reshare = FactoryBot.build(:reshare, author: alice.person, root: sm)
mail_double = double()
mail_double = double
expect(mail_double).to receive(:deliver_now)
expect(Notifier).to receive(:send_notification)
.with("reshared", bob.id, reshare.author.id, reshare.id).and_return(mail_double)

View file

@ -1,90 +1,89 @@
# frozen_string_literal: true
describe Workers::QueueUsersForRemoval do
describe 'remove_old_users is active' do
describe "remove_old_users is active" do
before do
AppConfig.settings.maintenance.remove_old_users.enable = true
AppConfig.settings.maintenance.remove_old_users.limit_removals_to_per_day = 1
ActionMailer::Base.deliveries = nil
Timecop.freeze
end
it '#does not queue user that is not inactive' do
user = FactoryBot.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 5)
it "#does not queue user that is not inactive" do
user = FactoryBot.create(:user, last_seen: Time.zone.now - 728.days, sign_in_count: 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#queues user that is inactive' do
removal_date = Time.now + (AppConfig.settings.maintenance.remove_old_users.warn_days.to_i).days
user = FactoryBot.create(:user, :last_seen => Time.now-732.days, :sign_in_count => 5)
it "#queues user that is inactive" do
removal_date = Time.zone.now + AppConfig.settings.maintenance.remove_old_users.warn_days.to_i.days
user = FactoryBot.create(:user, last_seen: Time.zone.now - 732.days, sign_in_count: 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after.to_i).to eq(removal_date.utc.to_i)
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
it '#queues user that is inactive and has not logged in' do
removal_date = Time.now
user = FactoryBot.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 0)
it "#queues user that is inactive and has not logged in" do
removal_date = Time.zone.now
user = FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 0)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after.to_i).to eq(removal_date.utc.to_i)
expect(ActionMailer::Base.deliveries.count).to eq(0) # no email sent
expect(ActionMailer::Base.deliveries.count).to eq(0) # no email sent
end
it '#does not queue user that is not inactive and has not logged in' do
user = FactoryBot.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 0)
it "#does not queue user that is not inactive and has not logged in" do
user = FactoryBot.create(:user, last_seen: Time.zone.now - 728.days, sign_in_count: 0)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#does not queue user that has already been flagged for removal' do
removal_date = Date.today + 5.days
user = FactoryBot.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 5, :remove_after => removal_date)
it "#does not queue user that has already been flagged for removal" do
removal_date = Time.zone.today + 5.days
user = FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 5, remove_after: removal_date)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(removal_date)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#does not queue more warnings than has been configured as limit' do
FactoryBot.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 1)
FactoryBot.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 1)
it "#does not queue more warnings than has been configured as limit" do
FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 1)
FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 1)
Workers::QueueUsersForRemoval.new.perform
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
after do
Timecop.return
end
end
end
describe 'remove_old_users is inactive' do
describe "remove_old_users is inactive" do
before do
AppConfig.settings.maintenance.remove_old_users.enable = false
ActionMailer::Base.deliveries = nil
end
it '#does not queue user that is not inactive' do
user = FactoryBot.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 5)
it "#does not queue user that is not inactive" do
user = FactoryBot.create(:user, last_seen: Time.zone.now - 728.days, sign_in_count: 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#does not queue user that is inactive' do
user = FactoryBot.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 5)
it "#does not queue user that is inactive" do
user = FactoryBot.create(:user, last_seen: Time.zone.now - 735.days, sign_in_count: 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end
end

View file

@ -3,7 +3,7 @@
describe Workers::RecurringPodCheck do
before do
@pods = (0..4).map do
FactoryBot.build(:pod).tap { |pod|
FactoryBot.build(:pod).tap {|pod|
expect(pod).to receive(:test_connection!)
}
end