Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Furniture: Appease the Fuzz #1211

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ RSpec/AnyInstance:
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/furniture/journal/entry_policy_spec.rb'
- 'spec/models/authenticated_session_spec.rb'
- 'spec/support/shared_examples/a_space_member_only_route.rb'

Expand All @@ -37,15 +36,9 @@ RSpec/DescribeClass:
# Configuration parameters: Max, CountAsOne.
RSpec/ExampleLength:
Exclude:
- 'spec/furniture/embedded_form_spec.rb'
- 'spec/furniture/journal/entries_request_spec.rb'
- 'spec/furniture/markdown_text_block_spec.rb'
- 'spec/furniture/marketplace/products_controller_request_spec.rb'
- 'spec/models/furniture_spec.rb'
- 'spec/models/membership_spec.rb'
- 'spec/models/room_spec.rb'
- 'spec/policies/room_policy_spec.rb'
- 'spec/requests/furnitures_controller_request_spec.rb'
- 'spec/requests/rsvps_controller_request_spec.rb'
- 'spec/requests/spaces/invitations_request_spec.rb'
- 'spec/requests/spaces_controller_request_spec.rb'
Expand All @@ -66,8 +59,6 @@ RSpec/LeakyConstantDeclaration:
# Offense count: 4
RSpec/LetSetup:
Exclude:
- 'spec/furniture/marketplace/checkouts_controller_request_spec.rb'
- 'spec/furniture/marketplace/stripe_accounts_controller_request_spec.rb'
- 'spec/policies/membership_policy_spec.rb'

# Offense count: 6
Expand All @@ -80,11 +71,6 @@ RSpec/NamedSubject:
- 'spec/models/membership_spec.rb'
- 'spec/models/space_spec.rb'

# Offense count: 2
RSpec/RepeatedExampleGroupBody:
Exclude:
- 'spec/furniture/marketplace/checkout_policy_spec.rb'

# Offense count: 2
RSpec/RepeatedExampleGroupDescription:
Exclude:
Expand All @@ -94,9 +80,6 @@ RSpec/RepeatedExampleGroupDescription:
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/furniture/marketplace/checkouts_controller_request_spec.rb'
- 'spec/furniture/marketplace/stripe_accounts_controller_request_spec.rb'
- 'spec/furniture/marketplace/stripe_events_controller_request_spec.rb'
- 'spec/requests/spaces/invitations_request_spec.rb'

# Offense count: 6
Expand Down Expand Up @@ -142,7 +125,6 @@ Rails/HasManyOrHasOneDependent:
# Offense count: 2
Rails/I18nLocaleTexts:
Exclude:
- 'app/furniture/marketplace/stripe_accounts_controller.rb'
- 'app/mailers/authenticated_session_mailer.rb'

# Offense count: 1
Expand Down
25 changes: 18 additions & 7 deletions spec/furniture/embedded_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
require "rails_helper"

RSpec.describe EmbeddedForm do
subject(:embedded_form) { build(:embedded_form, form_url: form_url) }

describe "#embeddable_form_url" do
it "converts Airtable Share URLs into the Embed url" do
embedded_form = build(:embedded_form, form_url: "https://airtable.com/shrCnrBzflvzDIlvg")
expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg")
subject(:embeddable_form_url) { embedded_form.embeddable_form_url }

context "with a #form_url that is the basic share url" do
let(:form_url) { "https://airtable.com/shrCnrBzflvzDIlvg" }

it { is_expected.to eql "https://airtable.com/embed/shrCnrBzflvzDIlvg" }
end

context "with a #form_url that is the embed instructions url" do
let(:form_url) { "https://airtable.com/shrCnrBzflvzDIlvg/embed" }

it { is_expected.to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") }
end

embedded_form = build(:embedded_form, form_url: "https://airtable.com/shrCnrBzflvzDIlvg/embed")
expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg")
context "with a #form_url that is the actual embed url" do
let(:form_url) { "https://airtable.com/embed/shrCnrBzflvzDIlvg" }

embedded_form = build(:embedded_form, form_url: "https://airtable.com/embed/shrCnrBzflvzDIlvg")
expect(embedded_form.embeddable_form_url).to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg")
it { is_expected.to eql("https://airtable.com/embed/shrCnrBzflvzDIlvg") }
end
end
end
66 changes: 41 additions & 25 deletions spec/furniture/journal/entries_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,60 @@
let(:room) { journal.room }
let(:member) { create(:person, spaces: [space]) }

describe "#index" do
it "shows all the journal entries" do
sign_in(space, member)
unpublished_entry = create(:journal_entry, journal: journal)
published_entry = create(:journal_entry, journal: journal, published_at: 1.week.ago)
before { sign_in(space, member) }

describe "#index" do
subject(:perform_request) do
get polymorphic_path(journal.location(child: :entries))
response
end

let!(:unpublished_entry) { create(:journal_entry, journal: journal) }
let!(:published_entry) { create(:journal_entry, journal: journal, published_at: 1.week.ago) }

it { is_expected.to be_ok }

describe "response body" do
subject(:response_body) { response.body }

before { perform_request }

expect(response).to be_ok
expect(response.body).to include(CGI.escapeHTML(published_entry.headline))
expect(response.body).to include(CGI.escapeHTML(unpublished_entry.headline))
it { is_expected.to include(CGI.escapeHTML(published_entry.headline)) }
it { is_expected.to include(CGI.escapeHTML(unpublished_entry.headline)) }
end
end

describe "#create" do
it "Creates an Entry in the Journal" do
sign_in(space, member)
subject(:perform_request) do
post polymorphic_path([space, room, journal, :entries]), params: {entry: journal_entry_attributes}
end

attributes = attributes_for(:journal_entry)
let(:journal_entry_attributes) { attributes_for(:journal_entry) }
let(:created_journal_entry) { journal.entries.first }

expect do
post polymorphic_path([space, room, journal, :entries]), params: {entry: attributes}
end.to change(journal.entries, :count).by(1)
specify { expect { perform_request }.to change(journal.entries, :count).by(1) }

created_entry = journal.entries.first
expect(created_entry.headline).to eql(attributes[:headline])
expect(created_entry.body).to eql(attributes[:body])
end
specify {
perform_request
expect(created_journal_entry.headline).to eql(journal_entry_attributes[:headline])
}

specify {
perform_request
expect(created_journal_entry.body).to eql(journal_entry_attributes[:body])
}
end

describe "#update" do
it "allows members to update Journal Entries" do
sign_in(space, member)
entry = create(:journal_entry, journal: journal)
published_at = 1.day.ago.beginning_of_day
expect do
put polymorphic_path(entry.location), params: {entry: {published_at: published_at}}
end.to change { entry.reload.published_at }.from(nil).to(published_at.to_time)
subject(:perform_request) do
put polymorphic_path(entry.location), params: {entry: {published_at: published_at}}
end

let(:published_at) { 1.day.ago.beginning_of_day }
let(:entry) { create(:journal_entry, journal: journal) }

before { sign_in(space, member) }

specify { expect { perform_request }.to change { entry.reload.published_at }.from(nil).to(published_at.to_time) }
end
end
2 changes: 1 addition & 1 deletion spec/furniture/journal/entry_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

let!(:unpublished_entry) { create(:journal_entry, journal: published_entry.journal) }

context "When a Guest" do
context "when a Guest" do
let(:user) { Guest.new }

it { is_expected.not_to include(unpublished_entry) }
Expand Down
13 changes: 8 additions & 5 deletions spec/furniture/markdown_text_block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
subject(:content_block) { create(:furniture).becomes(described_class) }

describe "#to_html" do
it "renders markdown correctly" do
subject(:to_html) { content_block.to_html }

before do
content_block.content = <<~MARKDOWN
# Title
## Subtitle
* item the first
* item the _second_
MARKDOWN
expect(content_block.to_html).to include '<h1 id="title">Title</h1>'
expect(content_block.to_html).to include '<h2 id="subtitle">Subtitle</h2>'
expect(content_block.to_html).to include "<li>item the first</li>"
expect(content_block.to_html).to include "<li>item the <em>second</em></li>"
end

it { is_expected.to include '<h1 id="title">Title</h1>' }
it { is_expected.to include '<h2 id="subtitle">Subtitle</h2>' }
it { is_expected.to include "<li>item the first</li>" }
it { is_expected.to include "<li>item the <em>second</em></li>" }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:marketplace) { create(:marketplace) }
let(:space) { marketplace.space }
let(:room) { marketplace.room }
let!(:cart) { create(:marketplace_cart, :with_products, marketplace: marketplace) }
let(:cart) { create(:marketplace_cart, :with_products, marketplace: marketplace) }
let(:checkout) { build(:marketplace_checkout, cart: cart) }

before { create(:stripe_utility, space: space) }
Expand All @@ -16,7 +16,7 @@
}

let(:stripe_checkout_session) do
double(Stripe::Checkout::Session, url: "http://stripe.redirect")
double(Stripe::Checkout::Session, url: "http://stripe.redirect") # rubocop:disable RSpec/VerifiedDoubles
end

before do
Expand All @@ -25,15 +25,15 @@
end

context "when a Guest checks out their Cart" do
let!(:cart) { create(:marketplace_cart, :with_products, marketplace: marketplace) }
let(:cart) { create(:marketplace_cart, :with_products, marketplace: marketplace) }

it "Redirects to Stripe" do
expect(completed_request).to redirect_to(stripe_checkout_session.url)
end
end

context "when the Cart is empty" do
let!(:cart) { create(:marketplace_cart, marketplace: marketplace) }
let(:cart) { create(:marketplace_cart, marketplace: marketplace) }

it "shows an error notice" do
completed_request
Expand Down
35 changes: 21 additions & 14 deletions spec/furniture/marketplace/products_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@
let(:member) { create(:membership, space: space).member }

describe "#create" do
it "Creates a Product in the Marketplace" do
tax_rate = create(:marketplace_tax_rate, marketplace: marketplace)
attributes = attributes_for(:marketplace_product, tax_rate_ids: [tax_rate.id])
subject(:perform_request) do
post polymorphic_path([space, room, marketplace, :products]),
params: {product: product_attributes}
end

let(:tax_rate) { create(:marketplace_tax_rate, marketplace: marketplace) }
let(:product_attributes) { attributes_for(:marketplace_product, tax_rate_ids: [tax_rate.id]) }

before do
sign_in(space, member)
end

specify { expect { perform_request }.to change(marketplace.products, :count).by(1) }

describe "the created product" do
subject(:created_product) { marketplace.products.last }

before { perform_request }

expect do
post polymorphic_path([space, room, marketplace, :products]),
params: {product: attributes}
end.to change(marketplace.products, :count).by(1)

created_product = marketplace.products.last
expect(created_product.name).to eql(attributes[:name])
expect(created_product.description).to eql(attributes[:description])
expect(created_product.price_cents).to eql(attributes[:price_cents])
expect(created_product.price_currency).to eql(Money.default_currency.to_s)
expect(created_product.tax_rates).to include(tax_rate)
specify { expect(created_product.name).to eql(product_attributes[:name]) }
specify { expect(created_product.description).to eql(product_attributes[:description]) }
specify { expect(created_product.price_cents).to eql(product_attributes[:price_cents]) }
specify { expect(created_product.price_currency).to eql(Money.default_currency.to_s) }
specify { expect(created_product.tax_rates).to include(tax_rate) }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require "rails_helper"

# rubocop:disable Rspec/VerifiedDoubles
RSpec.describe Marketplace::StripeAccountsController, type: :request do
let(:marketplace) { create(:marketplace) }
let(:space) { marketplace.space }
let(:member) { create(:membership, space: space).member }
let!(:stripe) { create(:stripe_utility, space: space, configuration: {"api_token" => "asdf"}) }

let(:stripe_account_link) { double(Stripe::AccountLink, url: "http://example.com/") }
let(:stripe_account) { double(Stripe::Account, id: "ac_1234", details_submitted?: false) }
let(:stripe_webhook_endpoint) { double(Stripe::WebhookEndpoint, id: "whe_1234", secret: "oooooooooooo") }

before do
create(:stripe_utility, space: space, configuration: {"api_token" => "asdf"})
allow(Stripe::Account).to receive(:create).and_return(stripe_account)
allow(Stripe::AccountLink).to receive(:create).and_return(stripe_account_link)
allow(Stripe::WebhookEndpoint).to receive(:create)
Expand Down Expand Up @@ -47,3 +49,4 @@
end
end
end
# rubocop:enable Rspec/VerifiedDoubles
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "rails_helper"

# `Stripe` gem doesn't support verified doubles for some reason...
# rubocop:disable Rspec/VerifiedDoubles
RSpec.describe Marketplace::StripeEventsController, type: :request do
let(:marketplace) { create(:marketplace, :with_stripe_utility, stripe_account: "sa_1234", stripe_webhook_endpoint_secret: "whsec_1234") }
let(:space) { marketplace.space }
Expand Down Expand Up @@ -51,3 +52,4 @@
end
end
end
# rubocop:enable Rspec/VerifiedDoubles
12 changes: 10 additions & 2 deletions spec/models/furniture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@

describe "#slot" do
let(:room) { create(:room) }
let!(:placements) { create_list(:furniture, 3, room: room) }
let(:placements) { create_list(:furniture, 3, room: room) }
let(:placement1) { placements[0] }
let(:placement2) { placements[1] }
let(:placement3) { placements[2] }

before {
placement1
placement2
placement3
}

it "inserts new placement between existing slots" do
placement1, placement2, placement3 = placements
new_placement = create(:furniture, room: room, slot_position: 1)
expect(placement1.slot_rank).to eq(0)
expect(new_placement.slot_rank).to eq(1)
Expand Down
11 changes: 7 additions & 4 deletions spec/requests/furnitures_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
let(:space) { room.space }

describe "#create" do
subject(:perform_request) do
post polymorphic_path(room.location(child: :furnitures)), params: {furniture: {furniture_kind: :markdown_text_block}}
end

let(:membership) { create(:membership, space: space) }
let!(:person) { membership.member }

before { sign_in(space, person) }

it "creates a furniture placement of the kind of furniture provided within the room" do
expect do
post polymorphic_path(room.location(child: :furnitures)), params: {furniture: {furniture_kind: :markdown_text_block}}
end.to change { room.furnitures.count }.by(1)
specify { expect { perform_request }.to change { room.furnitures.count }.by(1) }

it "creates a furniture placement of the kind of furniture provided within the room" do
perform_request
placement = room.furnitures.last
expect(placement.furniture).to be_a(MarkdownTextBlock)
expect(placement.slot).to be(0)
Expand Down