Don't generate file fixtures anymore
When we want to test without rails, we can't use the controllers to generate them. Also fixes the problem where there is still an old file fixture that doesn't match the users in the database.
This commit is contained in:
parent
184954e09c
commit
7fe7a5da97
12 changed files with 127 additions and 84 deletions
|
|
@ -204,7 +204,7 @@ Performance/RegexpMatch:
|
|||
# for rails 4 and ruby < 2.2.2
|
||||
Rails/HttpPositionalArguments:
|
||||
Exclude:
|
||||
- "spec/controllers/diaspora_federation/fixtures_rails4_spec.rb"
|
||||
- "spec/controllers/diaspora_federation/rails4_spec.rb"
|
||||
|
||||
# remove with next rubocop update, see https://github.com/bbatsov/rubocop/issues/4172
|
||||
Style/MixinGrouping:
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
if defined?(RSpec)
|
||||
namespace :rails4 do
|
||||
desc "Run all specs that generate fixtures for rspec with rails 4"
|
||||
RSpec::Core::RakeTask.new(:generate_fixtures) do |t|
|
||||
t.rspec_opts = ["--tag fixture4"]
|
||||
end
|
||||
|
||||
desc "Run all specs in spec directory (exluding controller specs)"
|
||||
RSpec::Core::RakeTask.new(:spec) do |task|
|
||||
task.pattern = FileList["spec/**/*_spec.rb"].exclude("spec/controllers/**/*_spec.rb")
|
||||
end
|
||||
|
||||
task test: %w(spec:prepare_db generate_fixtures spec)
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
task test: %w(spec:prepare_db spec)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,18 +1,8 @@
|
|||
if defined?(RSpec)
|
||||
namespace :spec do
|
||||
task prepare_db: %w(db:create db:test:load)
|
||||
task :prepare_fixtures do
|
||||
ENV["NO_COVERAGE"] = "true"
|
||||
Rake::Task["spec:generate_fixtures"].invoke
|
||||
ENV["NO_COVERAGE"] = "false"
|
||||
end
|
||||
|
||||
desc "Prepare for rspec"
|
||||
task prepare: %w(db:environment:set prepare_db prepare_fixtures)
|
||||
|
||||
desc "Run all specs that generate fixtures for rspec"
|
||||
RSpec::Core::RakeTask.new(:generate_fixtures) do |t|
|
||||
t.rspec_opts = ["--tag fixture"]
|
||||
end
|
||||
task prepare: %w(db:environment:set prepare_db)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
module DiasporaFederation
|
||||
describe FetchController, type: :controller do
|
||||
describe FetchController, type: :controller, rails: 5 do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
let(:guid) { "12345678901234567890" }
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
module DiasporaFederation
|
||||
describe WebfingerController, type: :controller do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
it "generates webfinger fixture", fixture4: true, rails4: true do
|
||||
get :legacy_webfinger, q: "alice@localhost:3000"
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "legacy-webfinger")
|
||||
end
|
||||
end
|
||||
|
||||
describe HCardController, type: :controller do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
it "generates hcard fixture", fixture4: true, rails4: true do
|
||||
get :hcard, guid: alice.guid
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "hcard")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
module DiasporaFederation
|
||||
describe HCardController, type: :controller do
|
||||
describe HCardController, type: :controller, rails: 5 do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "GET #hcard" do
|
||||
it "succeeds when the person exists", fixture: true do
|
||||
it "succeeds when the person exists" do
|
||||
get :hcard, params: {guid: alice.guid}
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "hcard")
|
||||
end
|
||||
|
||||
it "contains the guid" do
|
||||
|
|
|
|||
81
spec/controllers/diaspora_federation/rails4_spec.rb
Normal file
81
spec/controllers/diaspora_federation/rails4_spec.rb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# only some basic controller tests for rails 4
|
||||
module DiasporaFederation
|
||||
describe WebfingerController, type: :controller, rails: 4 do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
it "contains the webfinger result" do
|
||||
webfinger_xrd = DiasporaFederation::Discovery::WebFinger.new(
|
||||
acct_uri: "acct:#{alice.diaspora_id}",
|
||||
alias_url: alice.alias_url,
|
||||
hcard_url: alice.hcard_url,
|
||||
seed_url: alice.url,
|
||||
profile_url: alice.profile_url,
|
||||
atom_url: alice.atom_url,
|
||||
salmon_url: alice.salmon_url,
|
||||
subscribe_url: alice.subscribe_url,
|
||||
guid: alice.guid,
|
||||
public_key: alice.serialized_public_key
|
||||
).to_xml
|
||||
|
||||
get :legacy_webfinger, q: "alice@localhost:3000"
|
||||
expect(response).to be_success
|
||||
expect(response.body).to eq(webfinger_xrd)
|
||||
end
|
||||
|
||||
it "404s when the person does not exist" do
|
||||
get :legacy_webfinger, q: "me@mydiaspora.pod.com"
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
|
||||
describe HCardController, type: :controller, rails: 4 do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
it "contains the hcard result" do
|
||||
hcard_html = DiasporaFederation::Discovery::HCard.new(
|
||||
guid: alice.guid,
|
||||
nickname: alice.nickname,
|
||||
full_name: alice.full_name,
|
||||
url: alice.url,
|
||||
photo_large_url: alice.photo_default_url,
|
||||
photo_medium_url: alice.photo_default_url,
|
||||
photo_small_url: alice.photo_default_url,
|
||||
public_key: alice.serialized_public_key,
|
||||
searchable: alice.searchable,
|
||||
first_name: alice.first_name,
|
||||
last_name: alice.last_name
|
||||
).to_html
|
||||
|
||||
get :hcard, guid: alice.guid
|
||||
expect(response).to be_success
|
||||
expect(response.body).to eq(hcard_html)
|
||||
end
|
||||
|
||||
it "404s when the person does not exist" do
|
||||
get :hcard, guid: "unknown_guid"
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
|
||||
describe ReceiveController, type: :controller, rails: 4 do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "POST #public" do
|
||||
it "returns a 202 if queued correctly" do
|
||||
expect_callback(:queue_public_receive, "<diaspora/>", true)
|
||||
|
||||
post :public, xml: "<diaspora/>"
|
||||
expect(response.code).to eq("202")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #private" do
|
||||
it "returns a 202 if the callback returned true" do
|
||||
expect_callback(:queue_private_receive, "any-guid", "<diaspora/>", true).and_return(true)
|
||||
|
||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||
expect(response.code).to eq("202")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -15,21 +15,21 @@ module DiasporaFederation
|
|||
expect(response.code).to eq("422")
|
||||
end
|
||||
|
||||
it "returns a 202 if queued correctly" do
|
||||
it "returns a 202 if queued correctly", rails: 5 do
|
||||
expect_callback(:queue_public_receive, "<diaspora/>", true)
|
||||
|
||||
post :public, params: {xml: "<diaspora/>"}
|
||||
expect(response.code).to eq("202")
|
||||
end
|
||||
|
||||
it "unescapes the xml before sending it to the callback" do
|
||||
it "unescapes the xml before sending it to the callback", rails: 5 do
|
||||
expect_callback(:queue_public_receive, "<diaspora/>", true)
|
||||
|
||||
post :public, params: {xml: CGI.escape("<diaspora/>")}
|
||||
end
|
||||
end
|
||||
|
||||
context "magic envelope" do
|
||||
context "magic envelope", rails: 5 do
|
||||
before do
|
||||
Mime::Type.register("application/magic-envelope+xml", :magic_envelope)
|
||||
@request.env["CONTENT_TYPE"] = "application/magic-envelope+xml"
|
||||
|
|
@ -44,7 +44,7 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST #private" do
|
||||
describe "POST #private", rails: 5 do
|
||||
context "legacy salmon slap" do
|
||||
it "return a 404 if not queued successfully (unknown user guid)" do
|
||||
expect_callback(:queue_private_receive, "any-guid", "<diaspora/>", true).and_return(false)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ module DiasporaFederation
|
|||
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
||||
end
|
||||
|
||||
it "succeeds", fixture: true, fixture4: true do
|
||||
it "succeeds" do
|
||||
get :host_meta
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "host-meta")
|
||||
end
|
||||
|
||||
it "contains the webfinger-template" do
|
||||
|
|
@ -36,11 +35,10 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET #legacy_webfinger" do
|
||||
it "succeeds when the person exists", fixture: true do
|
||||
describe "GET #legacy_webfinger", rails: 5 do
|
||||
it "succeeds when the person exists" do
|
||||
get :legacy_webfinger, params: {q: "alice@localhost:3000"}
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "legacy-webfinger")
|
||||
end
|
||||
|
||||
it "succeeds with 'acct:' in the query when the person exists" do
|
||||
|
|
|
|||
|
|
@ -1,8 +1,35 @@
|
|||
module DiasporaFederation
|
||||
describe Discovery::Discovery do
|
||||
let(:host_meta_xrd) { FixtureGeneration.load_fixture("host-meta") }
|
||||
let(:webfinger_xrd) { FixtureGeneration.load_fixture("legacy-webfinger") }
|
||||
let(:hcard_html) { FixtureGeneration.load_fixture("hcard") }
|
||||
let(:host_meta_xrd) { Discovery::HostMeta.from_base_url("http://localhost:3000/").to_xml }
|
||||
let(:webfinger_xrd) {
|
||||
DiasporaFederation::Discovery::WebFinger.new(
|
||||
acct_uri: "acct:#{alice.diaspora_id}",
|
||||
alias_url: alice.alias_url,
|
||||
hcard_url: alice.hcard_url,
|
||||
seed_url: alice.url,
|
||||
profile_url: alice.profile_url,
|
||||
atom_url: alice.atom_url,
|
||||
salmon_url: alice.salmon_url,
|
||||
subscribe_url: alice.subscribe_url,
|
||||
guid: alice.guid,
|
||||
public_key: alice.serialized_public_key
|
||||
).to_xml
|
||||
}
|
||||
let(:hcard_html) {
|
||||
DiasporaFederation::Discovery::HCard.new(
|
||||
guid: alice.guid,
|
||||
nickname: alice.nickname,
|
||||
full_name: alice.full_name,
|
||||
url: alice.url,
|
||||
photo_large_url: alice.photo_default_url,
|
||||
photo_medium_url: alice.photo_default_url,
|
||||
photo_small_url: alice.photo_default_url,
|
||||
public_key: alice.serialized_public_key,
|
||||
searchable: alice.searchable,
|
||||
first_name: alice.first_name,
|
||||
last_name: alice.last_name
|
||||
).to_html
|
||||
}
|
||||
let(:account) { alice.diaspora_id }
|
||||
let(:default_image) { "http://localhost:3000/assets/user/default.png" }
|
||||
|
||||
|
|
@ -179,7 +206,7 @@ module DiasporaFederation
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
HTML
|
||||
HTML
|
||||
|
||||
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
|
||||
.to_return(status: 200, body: host_meta_xrd)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ RSpec.configure do |config|
|
|||
config.fixture_path = "#{::Rails.root}/test/fixtures"
|
||||
config.global_fixtures = :all
|
||||
|
||||
config.filter_run_excluding rails4: true if Rails::VERSION::MAJOR == 5
|
||||
config.filter_run_excluding rails: (Rails::VERSION::MAJOR == 5 ? 4 : 5)
|
||||
|
||||
# whitelist codeclimate.com so test coverage can be reported
|
||||
config.after(:suite) do
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
module FixtureGeneration
|
||||
# Saves the markup to a fixture file using the given name
|
||||
def save_fixture(markup, name, fixture_path=nil)
|
||||
fixture_path = Rails.root.join("tmp", "fixtures") unless fixture_path
|
||||
Dir.mkdir(fixture_path) unless File.exist?(fixture_path)
|
||||
|
||||
fixture_file = fixture_path.join("#{name}.fixture.html")
|
||||
File.open(fixture_file, "w") do |file|
|
||||
file.puts(markup)
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_fixture(name, fixture_path=nil)
|
||||
fixture_path = Rails.root.join("tmp", "fixtures") unless fixture_path
|
||||
fixture_file = fixture_path.join("#{name}.fixture.html")
|
||||
File.open(fixture_file).read
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Rails::ControllerExampleGroup.class_eval do
|
||||
include FixtureGeneration
|
||||
end
|
||||
Loading…
Reference in a new issue