Initial commit
This commit is contained in:
45
spec/adamantium/micropub_request_parser_spec.rb
Normal file
45
spec/adamantium/micropub_request_parser_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
RSpec.describe Adamantium::MicropubRequestParser do
|
||||
subject { described_class.new }
|
||||
|
||||
context "json request" do
|
||||
context "HTML post" do
|
||||
let(:params) {
|
||||
{
|
||||
type: ["h-entry"],
|
||||
properties: {
|
||||
name: ["title"],
|
||||
content: [
|
||||
"Hello world"
|
||||
]
|
||||
},
|
||||
category: ["ruby", "rspec"]
|
||||
}
|
||||
}
|
||||
|
||||
it "parses the params in to the expected shape" do
|
||||
Timecop.freeze do
|
||||
result = subject.call(params: params)
|
||||
expect(result).to be_a Adamantium::Entities::PostRequest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "form request" do
|
||||
let(:params) {
|
||||
{
|
||||
h: "entry",
|
||||
name: "title",
|
||||
content: "Hello world",
|
||||
category: ["ruby", "rspec"]
|
||||
}
|
||||
}
|
||||
|
||||
it "parses the params in to the expected shape" do
|
||||
Timecop.freeze do
|
||||
result = subject.call(params: params)
|
||||
expect(result).to be_a Adamantium::Entities::PostRequest
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
spec/adamantium/slug_creator_spec.rb
Normal file
23
spec/adamantium/slug_creator_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Adamantium::SlugCreator do
|
||||
describe "#call" do
|
||||
subject { described_class.new }
|
||||
let(:checker) { ->(_input) { false } }
|
||||
let(:uuid_regex) { /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ }
|
||||
|
||||
it "creates a slugified string" do
|
||||
expect(subject.call(text: "my string", checker: checker)).to eq "my-string"
|
||||
end
|
||||
|
||||
it "can handle no input" do
|
||||
expect(subject.call(text: nil, checker: checker)).to match(uuid_regex)
|
||||
end
|
||||
|
||||
it "adds a number to the end of the slug if the checker finds an existing slug" do
|
||||
text = "my-existing-slug"
|
||||
checker = ->(input) { true if input == text }
|
||||
expect(subject.call(text: text, checker: checker)).to eq "my-existing-slug-1"
|
||||
end
|
||||
end
|
||||
end
|
28
spec/adamantium/unit/commands/media/upload_spec.rb
Normal file
28
spec/adamantium/unit/commands/media/upload_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "dry/monads"
|
||||
|
||||
RSpec.describe Adamantium::Commands::Media::Upload do
|
||||
subject { described_class.new }
|
||||
|
||||
it "saves a file and returns its URL" do
|
||||
file = {
|
||||
filename: "foo.txt",
|
||||
tempfile: Tempfile.new
|
||||
}
|
||||
|
||||
result = subject.call(file: file)
|
||||
expected_path = "media/#{Time.now.strftime("%m-%Y")}/foo.txt"
|
||||
expect(result).to be_success
|
||||
expect(result.value!).to eq "http://localhost/#{expected_path}"
|
||||
File.read("public/#{expected_path}")
|
||||
File.delete("public/#{expected_path}")
|
||||
end
|
||||
|
||||
it "returns a Failure if the file couldn't be saved" do
|
||||
file = {filename: "file.txt", tempfile: ""}
|
||||
|
||||
result = subject.call(file: file)
|
||||
expect(result).to be_failure
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user