-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FS-13] Show QR code in app panel (#30)
- Loading branch information
1 parent
364bf5c
commit 92aa5ae
Showing
6 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Callable | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def call(*, **, &) | ||
new(*, **).call(&) | ||
end | ||
end | ||
|
||
included do | ||
def call | ||
raise NotImplementedError | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "rqrcode" | ||
|
||
class QrCode | ||
include Callable | ||
|
||
attr_reader :text, :offset | ||
|
||
def initialize(text, offset: 30) | ||
@text = text | ||
@offset = offset | ||
end | ||
|
||
def call | ||
RQRCode::QRCode.new(text).as_svg(offset:, viewbox: true).html_safe | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe QrCode, type: :model do | ||
describe ".call" do | ||
let(:text) { "whatever" } | ||
let(:offset) { 100 } | ||
let(:qr_code) { instance_double("RQRCode::QRCode") } | ||
let(:result) { "some valid html" } | ||
|
||
subject { described_class.call(text, offset:) } | ||
|
||
before do | ||
allow(RQRCode::QRCode).to receive(:new).with(text).and_return(qr_code) | ||
allow(qr_code).to receive(:as_svg).with(offset:, viewbox: true).and_return(result) | ||
end | ||
|
||
it { is_expected.to eq(result) } | ||
end | ||
end |