* Allow user to have many orgs * Allow users to handle multi orgs in settings * Make rounded buttons inline * Add multi org function to dashboards * Fix merge conflicts * Fix mistake in merge conflict fix oops * Display the correct membership level * Fix accessibility issues * Display organizations for article editors * Handle submitting org id with preact editors * Make listings work with multiple organizations * Allow listings to have multiple orgs on create * Display the correct number of credits for each org * Move script tag to Webpack * Allow multi orgs for purchasing and viewing credits * Use OrganizationMembership as authorization check * Display multiple organizations for notifications * Allow dashboard to be viewable under multi-orgs * Remove unused method * Add multi-org functionality for article editors * Show pro dashboard buttons for member+ org levels * Leave the correct organization * Allow article API to change org id * Add left-out authorization method oops * Make nav buttons a bit more clear * Fix merge conflict * Fix adding org id for /api/articles and tests * Fix tests for org policy * Use proper logic for displaying org members * Update org actions with new authorization * Use correct org when creating a listing * Remove additional payment charge oops * Mark org notifications as read with authorization * Remove deprecated post_as_organization attribute * Use new org_admin syntax * Remove deprecated org logic for article create and update * Default all RSS posts to not belong to any org * Render org_member page for guest users * Update org policy spec to work with multi orgs * Use org_membership for org traits and move identity code * Use org_member trait * Update to work with multi-orgs * Validate article's org_id if param org_id is blank * Make a let variable * Remove unnecessary eager load for credits * Fix HTML structure and org logic for non-org users * Update credits spec for multi-org * Add test for failed payment when purchased by org * Lint listings_spec * Test that the listing was created under the user * Add tests for POST /listings multi-org * Use double quotes for classes * Fix /manage and a few other multi-org bugs * Fix test for multi org * Use correct method SQL exists? not Rails exist? * Fix reads spec for multi-org * Fix org_controller actions to work with multi org * Test only multi org and not old usage and fix leave_org * Fix org showing user profile img test for multi-org * Fix org logic for users with no orgs * Remove switch org functionality * Update tests and add hidden param for org id * Redirect to the specific organization * Test other org button actions * Use settings_notice instead of legacy notice and refactor * Fix weird extra end issue prob from merge conflicts * Test for with new flash key * Fix user_views_org tests for multi-org * Test for new flash message * Update snapshot with new a11y html * Move styling to stylesheet * Add site admins functionality * Move org_member? method in user model and refactor * Use unspent_credits_count for organizations * Add tests for /listings/new and minor bug fixes * Use .present? in case of empty array * Fix a lingering deprecated method * Use greater than 1 for random numbers * Add tests for counting spent and unspent credits
103 lines
3 KiB
Ruby
103 lines
3 KiB
Ruby
FactoryBot.define do
|
|
sequence(:email) { |n| "person#{n}@example.com" }
|
|
sequence(:username) { |n| "username#{n}" }
|
|
sequence(:twitter_username) { |n| "twitter#{n}" }
|
|
sequence(:github_username) { |n| "github#{n}" }
|
|
|
|
image = Rack::Test::UploadedFile.new(
|
|
Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg"),
|
|
"image/jpeg",
|
|
)
|
|
|
|
factory :user do
|
|
name { Faker::Name.name }
|
|
email { generate :email }
|
|
username { generate :username }
|
|
profile_image { image }
|
|
twitter_username { generate :twitter_username }
|
|
github_username { generate :github_username }
|
|
summary { Faker::Lorem.paragraph[0..rand(190)] }
|
|
website_url { Faker::Internet.url }
|
|
confirmed_at { Time.current }
|
|
saw_onboarding { true }
|
|
signup_cta_variant { "navbar_basic" }
|
|
email_digest_periodic { false }
|
|
|
|
after(:create) do |user|
|
|
create(:identity, user_id: user.id)
|
|
end
|
|
|
|
trait :two_identities do
|
|
after(:create) { |user| create(:identity, user_id: user.id, provider: "twitter") }
|
|
end
|
|
|
|
trait :super_admin do
|
|
after(:build) { |user| user.add_role(:super_admin) }
|
|
end
|
|
|
|
trait :admin do
|
|
after(:build) { |user| user.add_role(:admin) }
|
|
end
|
|
|
|
trait :trusted do
|
|
after(:build) { |user| user.add_role(:trusted) }
|
|
end
|
|
|
|
trait :banned do
|
|
after(:build) { |user| user.add_role(:banned) }
|
|
end
|
|
|
|
trait :video_permission do
|
|
after(:build) { |user| user.created_at = 3.weeks.ago }
|
|
end
|
|
|
|
trait :ignore_after_callback do
|
|
after(:build) do |user|
|
|
user.define_singleton_method(:subscribe_to_mailchimp_newsletter) {}
|
|
# user.class.skip_callback(:validates, :after_create)
|
|
end
|
|
end
|
|
|
|
trait :pro do
|
|
after(:build) { |user| user.add_role :pro }
|
|
end
|
|
|
|
trait :org_member do
|
|
after(:create) do |user|
|
|
org = create(:organization)
|
|
create(:organization_membership, user_id: user.id, organization_id: org.id, type_of_user: "member")
|
|
end
|
|
end
|
|
|
|
trait :org_admin do
|
|
after(:create) do |user|
|
|
org = create(:organization)
|
|
create(:organization_membership, user_id: user.id, organization_id: org.id, type_of_user: "admin")
|
|
end
|
|
end
|
|
|
|
trait :with_article do
|
|
after(:create) do |user|
|
|
create(:article, user_id: user.id)
|
|
user.update(articles_count: 1)
|
|
end
|
|
end
|
|
|
|
trait :with_only_comment do
|
|
after(:create) do |user|
|
|
other_user = create(:user)
|
|
article = create(:article, user_id: other_user.id)
|
|
create(:comment, user_id: user.id, commentable_id: article.id)
|
|
user.update(comments_count: 1)
|
|
end
|
|
end
|
|
|
|
trait :with_article_and_comment do
|
|
after(:create) do |user|
|
|
article = create(:article, user_id: user.id)
|
|
create(:comment, user_id: user.id, commentable_id: article.id)
|
|
user.update(articles_count: 1, comments_count: 1)
|
|
end
|
|
end
|
|
end
|
|
end
|