Skip to content

Commit

Permalink
Use updated version of Quickdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Sep 2, 2024
1 parent de2e0fb commit 3fbc982
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gemspec

group :test do
gem "sus"
gem "quickdraw", github: "joeldrapper/quickdraw", ref: "061b0fa9c6f10bc95190de2e1f2812fa52ff01a3"
gem "quickdraw", github: "joeldrapper/quickdraw"
gem "simplecov", require: false
if RUBY_ENGINE == "ruby" && RUBY_VERSION[0] > "3"
gem "async"
Expand Down
80 changes: 39 additions & 41 deletions quickdraw/csv.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,61 @@ def render_headers?
end
end

describe Phlex::CSV do
test "renders a CSV" do
products = [
Product.new("Apple", 1.00),
Product.new("Banana", 2.00),
test "renders a CSV" do
products = [
Product.new("Apple", 1.00),
Product.new("Banana", 2.00),
]

csv = Example.new(products).call
csv = Example.new(products).call

expect(csv) == <<~CSV
name,price
Apple,1.0
Banana,2.0
expect(csv) == <<~CSV
name,price
Apple,1.0
Banana,2.0
CSV
end
end

test "escapes commas" do
product = Product.new("Apple, Inc.", 1.00)
csv = Example.new([product]).call
test "escapes commas" do
product = Product.new("Apple, Inc.", 1.00)
csv = Example.new([product]).call

expect(csv) == <<~CSV
name,price
"Apple, Inc.",1.0
expect(csv) == <<~CSV
name,price
"Apple, Inc.",1.0
CSV
end
end

test "escapes newlines" do
product = Product.new("Apple\nInc.", 1.00)
csv = Example.new([product]).call
test "escapes newlines" do
product = Product.new("Apple\nInc.", 1.00)
csv = Example.new([product]).call

expect(csv) == <<~CSV
name,price
"Apple\nInc.",1.0
expect(csv) == <<~CSV
name,price
"Apple\nInc.",1.0
CSV
end
end

test "escapes quotes" do
product = Product.new("Apple\"Inc.", 1.00)
csv = Example.new([product]).call
test "escapes quotes" do
product = Product.new("Apple\"Inc.", 1.00)
csv = Example.new([product]).call

expect(csv) == <<~CSV
name,price
"Apple""Inc.",1.0
expect(csv) == <<~CSV
name,price
"Apple""Inc.",1.0
CSV
end
end

test "renders without headers" do
products = [
Product.new("Apple", 1.00),
Product.new("Banana", 2.00),
test "renders without headers" do
products = [
Product.new("Apple", 1.00),
Product.new("Banana", 2.00),
]

csv = ExampleWithoutHeaders.new(products).call
csv = ExampleWithoutHeaders.new(products).call

expect(csv) == <<~CSV
Apple,1.0
Banana,2.0
expect(csv) == <<~CSV
Apple,1.0
Banana,2.0
CSV
end
end
14 changes: 6 additions & 8 deletions quickdraw/kit.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ def view_template

# This feature is only supported in Ruby 3.2 or later.
if Phlex::SUPPORTS_FIBER_STORAGE
describe Phlex::Kit do
test "raises when you try to render a component outside of a rendering context" do
expect { Components::SayHi() }.to_raise(RuntimeError) do |error|
expect(error.message) == "You can't call `SayHi' outside of a Phlex rendering context."
end
test "raises when you try to render a component outside of a rendering context" do
expect { Components::SayHi() }.to_raise(RuntimeError) do |error|
expect(error.message) == "You can't call `SayHi' outside of a Phlex rendering context."
end
end

test "defines methods for its components" do
expect(Example.new.call) == %(<article><h1>Hi Joel</h1><h1>Hi Joel</h1>Inside</article><article><h1>Hi Will</h1>Inside</article>)
end
test "defines methods for its components" do
expect(Example.new.call) == %(<article><h1>Hi Joel</h1><h1>Hi Joel</h1>Inside</article><article><h1>Hi Will</h1>Inside</article>)
end
end
24 changes: 8 additions & 16 deletions quickdraw/sgml/attributes.test.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
# frozen_string_literal: true

{ div: "div" }.each do |method_name, tag|
describe "<#{tag}> with class array attribute" do
test "<#{tag}> with class array attribute" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, class: ["class", nil, inactive: false, truthy: 1]) { "content" }
end
end

test "produces the correct output" do
expect(example.call) == %(<#{tag} class="class truthy">content</#{tag}>)
end
expect(example.call) == %(<#{tag} class="class truthy">content</#{tag}>)
end

describe "<#{tag}> with class hash attribute" do
test "<#{tag}> with class hash attribute" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, class: { class: true, inactive: false, truthy: 1 }) { "content" }
end
end

test "produces the correct output" do
expect(example.call) == %(<#{tag} class="class truthy">content</#{tag}>)
end
expect(example.call) == %(<#{tag} class="class truthy">content</#{tag}>)
end

describe "<#{tag}> with style array attribute" do
test "<#{tag}> with style array attribute" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, style: ["color: red", nil, font_weight: "bold", opacity: 0]) { "content" }
end
end

test "produces the correct output" do
expect(example.call) == %(<#{tag} style="color: red;font-weight:bold;opacity:0;">content</#{tag}>)
end
expect(example.call) == %(<#{tag} style="color: red;font-weight:bold;opacity:0;">content</#{tag}>)
end

describe "<#{tag}> with style hash attribute" do
test "<#{tag}> with style hash attribute" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, style: { color: "red", word_break: nil, font_weight: "bold" }) { "content" }
end
end

test "produces the correct output" do
expect(example.call) == %(<#{tag} style="color:red;font-weight:bold;">content</#{tag}>)
end
expect(example.call) == %(<#{tag} style="color:red;font-weight:bold;">content</#{tag}>)
end
end
53 changes: 24 additions & 29 deletions quickdraw/sgml/await.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,40 @@ def view_template
end
end

describe Phlex::SGML do
# The Async gem only works with CRuby 3.0 and above.
if RUBY_ENGINE == "ruby" && RUBY_VERSION[0] > "3"
describe "with Async tasks" do
test "flushes when waiting" do
Sync do
task = Async { sleep 0.01; "Hello" }
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1>", "<h1>Hello</h1><h1>After</h1>"])
end
end

test "doesn't flush when it doesn't need to wait" do
Sync do
task = Async { sleep 0.01; "Hello" }
task.wait
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1><h1>Hello</h1><h1>After</h1>"])
end
end
end
end
# The Async gem only works with CRuby 3.0 and above.
if RUBY_ENGINE == "ruby" && RUBY_VERSION[0] > "3"

describe "with Concurrent Promise" do
test "flushes when waiting" do
task = Concurrent::Promise.execute { sleep 0.01; "Hello" }
test "async task flushes when waiting" do
Sync do
task = Async { sleep 0.01; "Hello" }
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1>", "<h1>Hello</h1><h1>After</h1>"])
end
end

test "doesn't flush when it doesn't need to wait" do
task = Concurrent::Promise.execute { sleep 0.01; "Hello" }
test "async task doesn't flush when it doesn't need to wait" do
Sync do
task = Async { sleep 0.01; "Hello" }
task.wait
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1><h1>Hello</h1><h1>After</h1>"])
end
end
end

test "concurrent promise flushes when waiting" do
task = Concurrent::Promise.execute { sleep 0.01; "Hello" }
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1>", "<h1>Hello</h1><h1>After</h1>"])
end

test "concurrent promise doesn't flush when it doesn't need to wait" do
task = Concurrent::Promise.execute { sleep 0.01; "Hello" }
task.wait
buffer = []
Example.new(task).call(buffer)
expect(buffer) == (["<h1>Before</h1><h1>Hello</h1><h1>After</h1>"])
end
12 changes: 5 additions & 7 deletions quickdraw/sgml/render_enumerable.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ def view_template
end
end

describe Phlex::SGML do
test "can render enumerables without a block" do
expect(WithoutBlock.call) == "<article></article><article></article>"
end
test "can render enumerables without a block" do
expect(WithoutBlock.call) == "<article></article><article></article>"
end

test "can render enumerables with a block" do
expect(WithBlock.call) == "<article><h1>Hi</h1></article><article><h1>Hi</h1></article>"
end
test "can render enumerables with a block" do
expect(WithBlock.call) == "<article><h1>Hi</h1></article><article><h1>Hi</h1></article>"
end
30 changes: 14 additions & 16 deletions quickdraw/sgml/selective_rendering.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,20 @@ def view_template
expect(called) == false
end

describe "with a capture block" do
test "doesn't render the capture block" do
expect(
WithCaptureBlock.new.call(fragments: ["after"]),
) == %(<h1 id="after">After</h1>)
end
test "with a capture block doesn't render the capture block" do
expect(
WithCaptureBlock.new.call(fragments: ["after"]),
) == %(<h1 id="after">After</h1>)
end

test "renders the capture block when selected" do
expect(
WithCaptureBlock.new.call(fragments: ["around"]),
) == %(<div id="around">&lt;h1 id=&quot;inside&quot;&gt;Inside&lt;/h1&gt;</div>)
end
test "with a capture block renders the capture block when selected" do
expect(
WithCaptureBlock.new.call(fragments: ["around"]),
) == %(<div id="around">&lt;h1 id=&quot;inside&quot;&gt;Inside&lt;/h1&gt;</div>)
end

test "doesn't select from the capture block" do
expect(
WithCaptureBlock.new.call(fragments: ["inside"]),
) == ""
end
test "with a capture block doesn't select from the capture block" do
expect(
WithCaptureBlock.new.call(fragments: ["inside"]),
) == ""
end
Loading

0 comments on commit 3fbc982

Please sign in to comment.