* 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
156 lines
5.6 KiB
Ruby
156 lines
5.6 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "/listings", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:organization) { create(:organization) }
|
|
|
|
describe "GETS /listings" do
|
|
it "has page content" do
|
|
get "/listings"
|
|
expect(response.body).to include("classified-filters")
|
|
end
|
|
it "has page content for category page" do
|
|
get "/listings/saas"
|
|
expect(response.body).to include("classified-filters")
|
|
end
|
|
end
|
|
|
|
describe "GETS /listings/new" do
|
|
it "has page content" do
|
|
get "/listings"
|
|
expect(response.body).to include("classified-filters")
|
|
end
|
|
end
|
|
|
|
describe "POST /listings" do
|
|
before do
|
|
create_list(:credit, 20, user_id: user.id)
|
|
sign_in user
|
|
end
|
|
|
|
it "creates proper listing if credits are available" do
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my" }
|
|
}
|
|
expect(ClassifiedListing.last.processed_html).to include("hey my")
|
|
end
|
|
|
|
it "spends credits" do
|
|
num_credits = Credit.where(spent: true).size
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my" }
|
|
}
|
|
expect(Credit.where(spent: true).size).to be > num_credits
|
|
end
|
|
|
|
it "adds tags" do
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my", tag_list: "ruby, rails, go" }
|
|
}
|
|
expect(ClassifiedListing.last.cached_tag_list).to include("rails")
|
|
end
|
|
|
|
it "creates the listing under the user" do
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my", tag_list: "ruby, rails, go" }
|
|
}
|
|
expect(ClassifiedListing.last.user_id).to eq user.id
|
|
end
|
|
|
|
it "creates the listing for the user if no organization_id is selected" do
|
|
create(:organization_membership, user_id: user.id, organization_id: organization.id)
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my", tag_list: "ruby, rails, go" }
|
|
}
|
|
expect(ClassifiedListing.last.organization_id).to eq nil
|
|
expect(ClassifiedListing.last.user_id).to eq user.id
|
|
end
|
|
|
|
it "creates the listing for the organization" do
|
|
create(:organization_membership, user_id: user.id, organization_id: organization.id)
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my", tag_list: "ruby, rails, go", organization_id: organization.id }
|
|
}
|
|
expect(ClassifiedListing.last.organization_id).to eq(organization.id)
|
|
end
|
|
|
|
it "does not create an org listing if a different org member doesn't belong to the org" do
|
|
another_org = create(:organization)
|
|
create(:organization_membership, user_id: user.id, organization_id: another_org.id)
|
|
expect do
|
|
post "/listings", params: {
|
|
classified_listing: { title: "Hey", category: "education", body_markdown: "hey hey my my", tag_list: "ruby, rails, go", organization_id: organization.id }
|
|
}
|
|
end.to raise_error Pundit::NotAuthorizedError
|
|
end
|
|
end
|
|
|
|
describe "GETS /listings/edit" do
|
|
let(:classified_listing) { create(:classified_listing, user_id: user.id) }
|
|
|
|
before do
|
|
create_list(:credit, 20, user_id: user.id)
|
|
sign_in user
|
|
end
|
|
|
|
it "has page content" do
|
|
get "/listings/#{classified_listing.id}/edit"
|
|
expect(response.body).to include("You can bump your listing")
|
|
end
|
|
end
|
|
|
|
describe "PUT /listings/:id" do
|
|
let(:classified_listing) { create(:classified_listing, user_id: user.id) }
|
|
|
|
before do
|
|
create_list(:credit, 20, user_id: user.id)
|
|
sign_in user
|
|
end
|
|
|
|
it "updates bumped_at if action is bump" do
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { action: "bump" }
|
|
}
|
|
expect(ClassifiedListing.last.bumped_at).to be > 10.seconds.ago
|
|
end
|
|
|
|
it "updates publish if action is unpublish" do
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { action: "unpublish" }
|
|
}
|
|
expect(ClassifiedListing.last.published).to eq(false)
|
|
end
|
|
|
|
it "updates body_markdown" do
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { body_markdown: "hello new markdown" }
|
|
}
|
|
expect(ClassifiedListing.last.body_markdown).to eq("hello new markdown")
|
|
end
|
|
|
|
it "does not update body_markdown if not bumped/created recently" do
|
|
classified_listing.update_column(:bumped_at, 50.hours.ago)
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { body_markdown: "hello new markdown" }
|
|
}
|
|
expect(ClassifiedListing.last.body_markdown).not_to eq("hello new markdown")
|
|
end
|
|
|
|
it "updates other fields" do
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { body_markdown: "hello new markdown", title: "New title!", tag_list: "new, tags, hey" }
|
|
}
|
|
expect(ClassifiedListing.last.title).to eq("New title!")
|
|
expect(ClassifiedListing.last.cached_tag_list).to include("hey")
|
|
end
|
|
|
|
it "does not update other fields" do
|
|
classified_listing.update_column(:bumped_at, 50.hours.ago)
|
|
put "/listings/#{classified_listing.id}", params: {
|
|
classified_listing: { body_markdown: "hello new markdown", title: "New title!", tag_list: "new, tags, hey" }
|
|
}
|
|
expect(ClassifiedListing.last.title).not_to eq("New title!")
|
|
expect(ClassifiedListing.last.cached_tag_list).not_to include("hey")
|
|
end
|
|
end
|
|
end
|