Merge pull request #58 from SuperTux88/rspec-without-rails

rspec without rails
This commit is contained in:
Benjamin Neff 2017-04-19 00:03:52 +02:00
commit 5ad1bd32c9
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
107 changed files with 1123 additions and 1008 deletions

7
.gitignore vendored
View file

@ -20,15 +20,10 @@ doc
*.directory
# dummmy app
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/log/*.log*
test/dummy/tmp/
test/dummy/.sass-cache
test/dummy/test/fixtures/*.y*ml
rspec-persistance.txt
rspec-persistence.txt
.rake_tasks

View file

@ -15,8 +15,6 @@ Metrics/LineLength:
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
Max: 20
Exclude:
- "lib/diaspora_federation/test/factories.rb"
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
@ -27,8 +25,6 @@ Metrics/ModuleLength:
# Raise AbcSize from 15 to 20
Metrics/AbcSize:
Max: 20
Exclude:
- "lib/diaspora_federation/test/factories.rb"
# No space makes the method definition shorter and differentiates
# from a regular assignment.
@ -165,13 +161,14 @@ Metrics/BlockLength:
- "**/*.rake"
- "spec/**/*.rb"
- "test/dummy/config/**/*.rb"
- "lib/diaspora_federation/test/factories.rb"
# Rails cops only for controllers
Rails/Date:
Exclude:
- "spec/support/**/*"
Rails/TimeZone:
Exclude:
- "spec/lib/**/*"
# Rails cops only for controllers
Rails/Delegate:
Exclude:
- "lib/**/*"
@ -209,7 +206,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:

View file

@ -5,6 +5,15 @@ rvm:
- 2.3.3
- 2.2.5
- 2.1
gemfile:
- Gemfile
- test/gemfiles/rails4.Gemfile
- test/gemfiles/no-rails.Gemfile
matrix:
exclude:
- rvm: 2.1
gemfile: Gemfile
sudo: false
cache:
@ -15,7 +24,7 @@ branches:
- 'master'
- 'develop'
before_install: test/scripts/prepare-travis.sh
before_install: gem install bundler
bundler_args: "--deployment --without development --jobs=3 --retry=3"
script: test/scripts/travis.sh

20
Gemfile
View file

@ -17,9 +17,9 @@ end
group :development do
# code style
gem "pronto", "0.8.2"
gem "pronto-rubocop", "0.8.0", require: false
gem "rubocop", "0.48.0"
gem "pronto", "0.8.2", require: false
gem "pronto-rubocop", "0.8.0", require: false
gem "rubocop", "0.48.0", require: false
# automatic test runs
gem "guard-rspec", require: false
@ -49,8 +49,6 @@ group :test do
gem "simplecov-rcov", "0.2.3", require: false
# test helpers
gem "factory_girl_rails", "~> 4.7"
gem "fixture_builder", "0.5.0"
gem "json-schema-rspec", "0.0.4"
gem "rspec-collection_matchers", "~> 1.1.2"
gem "rspec-json_expectations", "~> 2.1"
@ -58,15 +56,9 @@ group :test do
end
group :development, :test do
gem "rake"
# unit tests
gem "rspec-core", "~> 3.5.1"
gem "rspec", "~> 3.5.0"
gem "rspec-rails", "~> 3.5.1"
# test database
gem "sqlite3", "~> 1.3.11"
end
group :development, :production do
# Logging (only for dummy-app, not for the gem)
gem "logging-rails", "0.5.0"
end

View file

@ -9,26 +9,16 @@ PATH
valid (~> 1.0)
diaspora_federation-json_schema (0.1.8)
diaspora_federation-rails (0.1.8)
actionpack (>= 4.2, < 6)
diaspora_federation (= 0.1.8)
rails (>= 4.2, < 6)
diaspora_federation-test (0.1.8)
diaspora_federation (= 0.1.8)
factory_girl (~> 4.7)
fabrication (~> 2.16.0)
uuid (~> 2.3.8)
GEM
remote: https://rubygems.org/
specs:
actioncable (5.0.2)
actionpack (= 5.0.2)
nio4r (>= 1.2, < 3.0)
websocket-driver (~> 0.6.1)
actionmailer (5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.0.2)
actionview (= 5.0.2)
activesupport (= 5.0.2)
@ -42,15 +32,6 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.0.2)
activesupport (= 5.0.2)
globalid (>= 0.3.6)
activemodel (5.0.2)
activesupport (= 5.0.2)
activerecord (5.0.2)
activemodel (= 5.0.2)
activesupport (= 5.0.2)
arel (~> 7.0)
activesupport (5.0.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
@ -58,7 +39,6 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (7.1.4)
ast (2.3.0)
builder (3.2.3)
byebug (9.0.6)
@ -73,19 +53,12 @@ GEM
erubis (2.7.0)
ethon (0.10.1)
ffi (>= 1.3.0)
factory_girl (4.8.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
fabrication (2.16.1)
faraday (0.12.0.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.11.0.1)
faraday (>= 0.7.4, < 1.0)
ffi (1.9.18)
fixture_builder (0.5.0)
activerecord (>= 2)
activesupport (>= 2)
formatador (0.2.5)
fuubar (2.2.0)
rspec-core (~> 3.0)
@ -93,8 +66,6 @@ GEM
gitlab (3.7.0)
httparty (~> 0.13.0)
terminal-table
globalid (0.3.7)
activesupport (>= 4.1.0)
guard (2.14.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
@ -127,30 +98,17 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
little-plugger (1.1.4)
logging (2.2.0)
little-plugger (~> 1.1)
multi_json (~> 1.10)
logging-rails (0.5.0)
logging (>= 1.8)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.11)
macaddr (1.7.1)
systemu (~> 2.6.2)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
notiffany (0.1.1)
@ -184,18 +142,6 @@ GEM
rack (2.0.1)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.2)
actioncable (= 5.0.2)
actionmailer (= 5.0.2)
actionpack (= 5.0.2)
actionview (= 5.0.2)
activejob (= 5.0.2)
activemodel (= 5.0.2)
activerecord (= 5.0.2)
activesupport (= 5.0.2)
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.2)
activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6)
@ -265,14 +211,6 @@ GEM
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
systemu (2.6.5)
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
@ -290,9 +228,6 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
yard (0.9.8)
PLATFORMS
@ -304,20 +239,18 @@ DEPENDENCIES
diaspora_federation-json_schema!
diaspora_federation-rails!
diaspora_federation-test!
factory_girl_rails (~> 4.7)
fixture_builder (= 0.5.0)
fuubar (= 2.2.0)
guard-rspec
guard-rubocop
json-schema-rspec (= 0.0.4)
logging-rails (= 0.5.0)
nyan-cat-formatter
pronto (= 0.8.2)
pronto-rubocop (= 0.8.0)
pry
pry-byebug
rake
rspec (~> 3.5.0)
rspec-collection_matchers (~> 1.1.2)
rspec-core (~> 3.5.1)
rspec-json_expectations (~> 2.1)
rspec-rails (~> 3.5.1)
rubocop (= 0.48.0)
@ -326,7 +259,6 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen
sqlite3 (~> 1.3.11)
webmock (~> 2.0)
yard

View file

@ -13,14 +13,19 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include("lib/**/*.rb")
end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load "rails/tasks/engine.rake"
if defined?(::Rails)
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"
load "rails/tasks/statistics.rake"
Rails.application.load_tasks
else
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
FileList["lib/tasks/**/*.rake"].each {|task| load(task) }
end
Bundler::GemHelper.install_tasks name: "diaspora_federation"
Rails.application.load_tasks
task test: %w(spec:prepare spec)
task test: :spec
task default: :test

View file

@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = "~> 2.1"
s.add_dependency "rails", ">= 4.2", "< 6"
s.add_dependency "actionpack", ">= 4.2", "< 6"
s.add_dependency "diaspora_federation", DiasporaFederation::VERSION
end

View file

@ -20,6 +20,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = "~> 2.1"
s.add_dependency "diaspora_federation", DiasporaFederation::VERSION
s.add_dependency "factory_girl", "~> 4.7"
s.add_dependency "fabrication", "~> 2.16.0"
s.add_dependency "uuid", "~> 2.3.8"
end

View file

@ -1,4 +1,7 @@
require "diaspora_federation/test/factories"
require "fabrication"
require "diaspora_federation"
require "diaspora_federation/test/entity_generator"
module DiasporaFederation
# This module encapsulates helper functions maybe wanted by a testsuite of a diaspora_federation gem user application.

View file

@ -0,0 +1,25 @@
module DiasporaFederation
module Test
# Generator to instantiate entities
class EntityGenerator < Fabrication::Generator::Base
def self.supports?(klass)
klass.ancestors.include?(DiasporaFederation::Entity)
end
def build_instance
self._instance = _klass.new(_attributes)
end
def to_hash(attributes=[], _callbacks=[])
process_attributes(attributes)
_attributes.each_with_object({}) do |(name, value), hash|
hash[name.to_sym] = value
end
end
end
Fabrication.configure do |config|
config.generators << EntityGenerator
end
end
end

View file

@ -1,238 +1,228 @@
require "diaspora_federation"
require "factory_girl"
require "uuid"
require "securerandom"
require "diaspora_federation/test"
module DiasporaFederation
module Test
# Factories for federation entities
module Factories
# Defines the federation entity factories
def self.federation_factories
FactoryGirl.define do
initialize_with { new(attributes) }
sequence(:guid) { UUID.generate :compact }
sequence(:diaspora_id) {|n| "person-#{n}-#{SecureRandom.hex(3)}@localhost:3000" }
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
Fabricate.sequence(:guid) { UUID.generate(:compact) }
Fabricate.sequence(:diaspora_id) {|n| "person-#{n}-#{SecureRandom.hex(3)}@localhost:3000" }
Fabricate.sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
factory :webfinger, class: DiasporaFederation::Discovery::WebFinger do
guid
acct_uri { "acct:#{generate(:diaspora_id)}" }
alias_url "http://localhost:3000/people/0123456789abcdef"
hcard_url "http://localhost:3000/hcard/users/user"
seed_url "http://localhost:3000/"
profile_url "http://localhost:3000/u/user"
atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key
subscribe_url "http://localhost:3000/people?q={uri}"
end
Fabricator(:webfinger, class_name: DiasporaFederation::Discovery::WebFinger) do
guid { Fabricate.sequence(:guid) }
acct_uri { "acct:#{Fabricate.sequence(:diaspora_id)}" }
alias_url "http://localhost:3000/people/0123456789abcdef"
hcard_url "http://localhost:3000/hcard/users/user"
seed_url "http://localhost:3000/"
profile_url "http://localhost:3000/u/user"
atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key { Fabricate.sequence(:public_key) }
subscribe_url "http://localhost:3000/people?q={uri}"
end
factory :h_card, class: DiasporaFederation::Discovery::HCard do
guid
nickname "some_name"
full_name "my name"
first_name "my name"
last_name ""
url "http://localhost:3000/"
public_key
photo_large_url "/assets/user/default.png"
photo_medium_url "/assets/user/default.png"
photo_small_url "/assets/user/default.png"
searchable true
end
Fabricator(:h_card, class_name: DiasporaFederation::Discovery::HCard) do
guid { Fabricate.sequence(:guid) }
nickname "some_name"
full_name "my name"
first_name "my name"
last_name ""
url "http://localhost:3000/"
public_key { Fabricate.sequence(:public_key) }
photo_large_url "/assets/user/default.png"
photo_medium_url "/assets/user/default.png"
photo_small_url "/assets/user/default.png"
searchable true
end
factory :account_migration_entity, class: DiasporaFederation::Entities::AccountMigration do
author { generate(:diaspora_id) }
profile {
FactoryGirl.build(:profile_entity)
}
end
Fabricator(:account_deletion_entity, class_name: DiasporaFederation::Entities::AccountDeletion) do
author { Fabricate.sequence(:diaspora_id) }
end
factory :person_entity, class: DiasporaFederation::Entities::Person do
guid
author { generate(:diaspora_id) }
url "http://localhost:3000/"
exported_key { generate(:public_key) }
profile {
FactoryGirl.build(:profile_entity, author: author)
}
end
Fabricator(:account_migration_entity, class_name: DiasporaFederation::Entities::AccountMigration) do
author { Fabricate.sequence(:diaspora_id) }
profile { Fabricate(:profile_entity) }
end
factory :profile_entity, class: DiasporaFederation::Entities::Profile do
author { generate(:diaspora_id) }
first_name "my name"
last_name ""
image_url "/assets/user/default.png"
image_url_medium "/assets/user/default.png"
image_url_small "/assets/user/default.png"
birthday "1988-07-15"
gender "Male"
bio "some text about me"
location "github"
searchable true
nsfw false
tag_string "#i #love #tags"
end
Fabricator(:person_entity, class_name: DiasporaFederation::Entities::Person) do
guid { Fabricate.sequence(:guid) }
author { Fabricate.sequence(:diaspora_id) }
url "http://localhost:3000/"
exported_key { Fabricate.sequence(:public_key) }
profile {|attrs| Fabricate(:profile_entity, author: attrs[:author]) }
end
factory :location_entity, class: DiasporaFederation::Entities::Location do
address "Vienna, Austria"
lat 48.208174.to_s
lng 16.373819.to_s
end
Fabricator(:profile_entity, class_name: DiasporaFederation::Entities::Profile) do
author { Fabricate.sequence(:diaspora_id) }
first_name "my name"
last_name ""
image_url "/assets/user/default.png"
image_url_medium "/assets/user/default.png"
image_url_small "/assets/user/default.png"
birthday "1988-07-15"
gender "Male"
bio "some text about me"
location "github"
searchable true
nsfw false
tag_string "#i #love #tags"
end
factory :photo_entity, class: DiasporaFederation::Entities::Photo do
guid
author { generate(:diaspora_id) }
public(true)
created_at { Time.now.utc }
remote_photo_path "https://diaspora.example.tld/uploads/images/"
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
text "what you see here..."
status_message_guid { generate(:guid) }
height 480
width 800
end
Fabricator(:location_entity, class_name: DiasporaFederation::Entities::Location) do
address "Vienna, Austria"
lat 48.208174.to_s
lng 16.373819.to_s
end
factory :relayable_entity, class: DiasporaFederation::Entities::Relayable do
parent_guid { generate(:guid) }
parent { FactoryGirl.build(:related_entity) }
end
Fabricator(:photo_entity, class_name: DiasporaFederation::Entities::Photo) do
guid { Fabricate.sequence(:guid) }
author { Fabricate.sequence(:diaspora_id) }
public true
created_at { Time.now.utc }
remote_photo_path "https://diaspora.example.tld/uploads/images/"
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
text "what you see here..."
status_message_guid { Fabricate.sequence(:guid) }
height 480
width 800
end
factory :participation_entity,
class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do
author { generate(:diaspora_id) }
guid
parent_type "Post"
end
Fabricator(:relayable_entity, class_name: DiasporaFederation::Entities::Relayable) do
parent_guid { Fabricate.sequence(:guid) }
parent { Fabricate(:related_entity) }
end
factory :status_message_entity, class: DiasporaFederation::Entities::StatusMessage do
text "i am a very interesting status update"
author { generate(:diaspora_id) }
guid
public(true)
created_at { Time.now.utc }
end
Fabricator(:participation_entity,
class_name: DiasporaFederation::Entities::Participation, from: :relayable_entity) do
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
parent_type "Post"
end
factory :request_entity, class: DiasporaFederation::Entities::Request do
author { generate(:diaspora_id) }
recipient { generate(:diaspora_id) }
end
Fabricator(:status_message_entity, class_name: DiasporaFederation::Entities::StatusMessage) do
text "i am a very interesting status update"
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
public true
created_at { Time.now.utc }
end
factory :contact_entity, class: DiasporaFederation::Entities::Contact do
author { generate(:diaspora_id) }
recipient { generate(:diaspora_id) }
following true
sharing true
end
Fabricator(:request_entity, class_name: DiasporaFederation::Entities::Request) do
author { Fabricate.sequence(:diaspora_id) }
recipient { Fabricate.sequence(:diaspora_id) }
end
factory :comment_entity, class: DiasporaFederation::Entities::Comment, parent: :relayable_entity do
author { generate(:diaspora_id) }
guid
text "this is a very informative comment"
end
Fabricator(:contact_entity, class_name: DiasporaFederation::Entities::Contact) do
author { Fabricate.sequence(:diaspora_id) }
recipient { Fabricate.sequence(:diaspora_id) }
following true
sharing true
end
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do
positive true
author { generate(:diaspora_id) }
guid
parent_type "Post"
end
Fabricator(:comment_entity, class_name: DiasporaFederation::Entities::Comment, from: :relayable_entity) do
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
text "this is a very informative comment"
end
factory :account_deletion_entity, class: DiasporaFederation::Entities::AccountDeletion do
author { generate(:diaspora_id) }
end
Fabricator(:like_entity, class_name: DiasporaFederation::Entities::Like, from: :relayable_entity) do
positive true
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
parent_type "Post"
end
factory :conversation_entity, class: DiasporaFederation::Entities::Conversation do
author { generate(:diaspora_id) }
guid
subject "this is a very informative subject"
created_at { Time.now.utc }
messages []
participants { Array.new(3) { generate(:diaspora_id) }.join(";") }
end
Fabricator(:conversation_entity, class_name: DiasporaFederation::Entities::Conversation) do
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
subject "this is a very informative subject"
created_at { Time.now.utc }
messages []
participants { Array.new(3) { Fabricate.sequence(:diaspora_id) }.join(";") }
end
factory :message_entity, class: DiasporaFederation::Entities::Message, parent: :relayable_entity do
guid
author { generate(:diaspora_id) }
text "this is a very informative text"
created_at { Time.now.utc }
conversation_guid { generate(:guid) }
end
Fabricator(:message_entity, class_name: DiasporaFederation::Entities::Message, from: :relayable_entity) do
guid { Fabricate.sequence(:guid) }
author { Fabricate.sequence(:diaspora_id) }
text "this is a very informative text"
created_at { Time.now.utc }
conversation_guid { Fabricate.sequence(:guid) }
end
factory :relayable_retraction_entity, class: DiasporaFederation::Entities::RelayableRetraction do
author { generate(:diaspora_id) }
target_guid { generate(:guid) }
target_type "Comment"
target { FactoryGirl.build(:related_entity, author: author) }
end
Fabricator(:relayable_retraction_entity, class_name: DiasporaFederation::Entities::RelayableRetraction) do
author { Fabricate.sequence(:diaspora_id) }
target_guid { Fabricate.sequence(:guid) }
target_type "Comment"
target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end
factory :reshare_entity, class: DiasporaFederation::Entities::Reshare do
root_author { generate(:diaspora_id) }
root_guid { generate(:guid) }
guid
author { generate(:diaspora_id) }
public(true)
created_at { Time.now.utc }
provider_display_name { "the testsuite" }
end
Fabricator(:reshare_entity, class_name: DiasporaFederation::Entities::Reshare) do
root_author { Fabricate.sequence(:diaspora_id) }
root_guid { Fabricate.sequence(:guid) }
guid { Fabricate.sequence(:guid) }
author { Fabricate.sequence(:diaspora_id) }
public true
created_at { Time.now.utc }
provider_display_name { "the testsuite" }
end
factory :retraction_entity, class: DiasporaFederation::Entities::Retraction do
author { generate(:diaspora_id) }
target_guid { generate(:guid) }
target_type "Post"
target { FactoryGirl.build(:related_entity, author: author) }
end
Fabricator(:retraction_entity, class_name: DiasporaFederation::Entities::Retraction) do
author { Fabricate.sequence(:diaspora_id) }
target_guid { Fabricate.sequence(:guid) }
target_type "Post"
target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end
factory :signed_retraction_entity, class: DiasporaFederation::Entities::SignedRetraction do
author { generate(:diaspora_id) }
target_guid { generate(:guid) }
target_type "Post"
target { FactoryGirl.build(:related_entity, author: author) }
end
Fabricator(:signed_retraction_entity, class_name: DiasporaFederation::Entities::SignedRetraction) do
author { Fabricate.sequence(:diaspora_id) }
target_guid { Fabricate.sequence(:guid) }
target_type "Post"
target {|attrs| Fabricate(:related_entity, author: attrs[:author]) }
end
factory :poll_answer_entity, class: DiasporaFederation::Entities::PollAnswer do
guid
answer { "Obama is a bicycle" }
end
Fabricator(:poll_answer_entity, class_name: DiasporaFederation::Entities::PollAnswer) do
guid { Fabricate.sequence(:guid) }
answer { "Obama is a bicycle" }
end
factory :poll_entity, class: DiasporaFederation::Entities::Poll do
guid
question { "Select an answer" }
poll_answers { Array.new(3) { FactoryGirl.build(:poll_answer_entity) } }
end
Fabricator(:poll_entity, class_name: DiasporaFederation::Entities::Poll) do
guid { Fabricate.sequence(:guid) }
question { "Select an answer" }
poll_answers { Array.new(3) { Fabricate(:poll_answer_entity) } }
end
factory :poll_participation_entity,
class: DiasporaFederation::Entities::PollParticipation, parent: :relayable_entity do
author { generate(:diaspora_id) }
guid
poll_answer_guid { generate(:guid) }
end
Fabricator(:poll_participation_entity,
class_name: DiasporaFederation::Entities::PollParticipation, from: :relayable_entity) do
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
poll_answer_guid { Fabricate.sequence(:guid) }
end
factory :event_entity, class: DiasporaFederation::Entities::Event do
author { generate(:diaspora_id) }
guid
summary "Cool event"
description "You need to see this!"
start { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) - 1.hour }
add_attribute(:end) { Time.now.utc.change(min: 0).change(sec: 0).change(usec: 0) + 1.hour }
all_day false
timezone "Europe/Berlin"
end
Fabricator(:event_entity, class_name: DiasporaFederation::Entities::Event) do |f|
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
summary "Cool event"
description "You need to see this!"
start { change_time(Time.now.utc, min: 0) - 3600 }
f.end { change_time(Time.now.utc, min: 0) + 3600 }
all_day false
timezone "Europe/Berlin"
end
factory :event_participation_entity,
class: DiasporaFederation::Entities::EventParticipation, parent: :relayable_entity do
author { generate(:diaspora_id) }
guid
status "accepted"
end
Fabricator(:event_participation_entity,
class_name: DiasporaFederation::Entities::EventParticipation, from: :relayable_entity) do
author { Fabricate.sequence(:diaspora_id) }
guid { Fabricate.sequence(:guid) }
status "accepted"
end
factory :related_entity, class: DiasporaFederation::Entities::RelatedEntity do
author { generate(:diaspora_id) }
local true
public false
parent nil
end
end
Fabricator(:related_entity, class_name: DiasporaFederation::Entities::RelatedEntity) do
author { Fabricate.sequence(:diaspora_id) }
local true
public false
parent nil
end
end
end

View file

@ -1,4 +0,0 @@
# desc "Explaining what the task does"
# task :diaspora_federation do
# # Task goes here
# end

28
lib/tasks/gemfiles.rake Normal file
View file

@ -0,0 +1,28 @@
namespace :gemfiles do
desc "Generates rails4.Gemfile and no-rails.Gemfile"
task :generate do
FileUtils.mkdir_p("test/gemfiles")
FileUtils.rm(Dir["test/gemfiles/*.Gemfile.lock"])
original_gemfile = File.read("Gemfile")
original_gemfile.sub!(/(gemspec name:.*)/) { "#{Regexp.last_match[1]}, path: \"../../\"" }
original_gemfile.sub!(/(gemspec\(name:.*)\)/) { "#{Regexp.last_match[1]}, path: \"../../\")" }
original_gemfile.sub!(/^group :development do$.*?^end$\n\n/m, "")
rails4_version = "4.2.8"
rails4_gemfile = "#{original_gemfile}\ngem \"actionpack\", \"#{rails4_version}\"\n"
rails4_path = "test/gemfiles/rails4.Gemfile"
File.write(rails4_path, rails4_gemfile)
no_rails_gemfile = original_gemfile.dup
no_rails_gemfile.sub!(/(gemspec\(name:.*)/) { "#{Regexp.last_match[1]} unless plugin == \"rails\"" }
no_rails_gemfile.sub!(/^.*rspec-rails.*$\n/, "")
no_rails_path = "test/gemfiles/no-rails.Gemfile"
File.write(no_rails_path, no_rails_gemfile)
Bundler.with_clean_env do
system("BUNDLE_GEMFILE=#{rails4_path} bundle install")
system("BUNDLE_GEMFILE=#{no_rails_path} bundle install")
end
end
end

View file

@ -1,15 +0,0 @@
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)
end
end

View file

@ -1,18 +0,0 @@
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
end
end

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe FetchController, type: :controller do
describe FetchController, type: :controller, rails: 5 do
routes { DiasporaFederation::Engine.routes }
let(:guid) { "12345678901234567890" }
let(:post) { FactoryGirl.build(:status_message_entity, guid: guid, author: alice.diaspora_id) }
let(:post) { Fabricate(:status_message_entity, guid: guid, author: alice.diaspora_id) }
describe "GET #fetch" do
it "returns the magic-envelope with the status message" do

View file

@ -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

View file

@ -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

View 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.diaspora_id
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

View file

@ -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)

View file

@ -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,20 +35,19 @@ module DiasporaFederation
end
end
describe "GET #legacy_webfinger" do
it "succeeds when the person exists", fixture: true do
get :legacy_webfinger, params: {q: "alice@localhost:3000"}
describe "GET #legacy_webfinger", rails: 5 do
it "succeeds when the person exists" do
get :legacy_webfinger, params: {q: alice.diaspora_id}
expect(response).to be_success
save_fixture(response.body, "legacy-webfinger")
end
it "succeeds with 'acct:' in the query when the person exists" do
get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"}
get :legacy_webfinger, params: {q: "acct:#{alice.diaspora_id}"}
expect(response).to be_success
end
it "contains the diaspora* ID" do
get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"}
get :legacy_webfinger, params: {q: "acct:#{alice.diaspora_id}"}
expect(response.body).to include "<Subject>acct:alice@localhost:3000</Subject>"
end

View file

@ -1,46 +1,42 @@
require "diaspora_federation/test"
require "diaspora_federation/test/factories"
DiasporaFederation::Test::Factories.federation_factories
Fabricator(:person) do
diaspora_id { Fabricate.sequence(:diaspora_id) }
url "http://somehost:3000/"
serialized_public_key { Fabricate.sequence(:public_key) }
end
FactoryGirl.define do
factory :person do
diaspora_id
url "http://somehost:3000/"
serialized_public_key { generate(:public_key) }
end
factory :user, class: Person do
diaspora_id
url "http://localhost:3000/"
after(:build) do |user|
private_key = OpenSSL::PKey::RSA.generate(1024)
user.serialized_private_key = private_key.export
user.serialized_public_key = private_key.public_key.export
end
end
factory :post, class: Entity do
entity_type "Post"
author { FactoryGirl.build(:person) }
end
factory :comment, class: Entity do
entity_type "Comment"
author { FactoryGirl.build(:person) }
end
factory :poll, class: Entity do
entity_type "Poll"
author { FactoryGirl.build(:person) }
end
factory :event, class: Entity do
entity_type "Event"
author { FactoryGirl.build(:person) }
end
factory :conversation, class: Entity do
entity_type "Conversation"
author { FactoryGirl.build(:person) }
Fabricator(:user, class_name: Person) do
diaspora_id { Fabricate.sequence(:diaspora_id) }
url "http://localhost:3000/"
after_build do |user|
private_key = OpenSSL::PKey::RSA.generate(1024)
user.serialized_private_key = private_key.export
user.serialized_public_key = private_key.public_key.export
end
end
Fabricator(:post, class_name: Entity) do
on_init { init_with("Post") }
author { Fabricate(:person) }
end
Fabricator(:comment, class_name: Entity) do
on_init { init_with("Comment") }
author { Fabricate(:person) }
end
Fabricator(:poll, class_name: Entity) do
on_init { init_with("Poll") }
author { Fabricate(:person) }
end
Fabricator(:event, class_name: Entity) do
on_init { init_with("Event") }
author { Fabricate(:person) }
end
Fabricator(:conversation, class_name: Entity) do
on_init { init_with("Conversation") }
author { Fabricate(:person) }
end

View file

@ -56,7 +56,7 @@ KEY
let(:new_data) { "foobar" }
let(:text) { "this is a very informative comment" }
let(:parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:comment) {
Entities::Comment.new(
author: author, guid: guid, parent_guid: parent_guid, text: text, parent: parent, new_data: new_data
@ -210,7 +210,7 @@ XML
end
context "parsing on every other pod" do
let(:parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id, local: false) }
let(:parent) { Fabricate(:related_entity, author: bob.diaspora_id, local: false) }
before do
expect_callback(:fetch_public_key, author).and_return(author_key.public_key)

View file

@ -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" }
@ -27,6 +54,7 @@ module DiasporaFederation
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
expect_callback(:save_person_after_webfinger, kind_of(Entities::Person))
person = Discovery::Discovery.new(account).fetch_and_save
expect(person.guid).to eq(alice.guid)
@ -73,6 +101,7 @@ module DiasporaFederation
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
expect_callback(:save_person_after_webfinger, kind_of(Entities::Person))
person = Discovery::Discovery.new(account).fetch_and_save
expect(person.guid).to eq(alice.guid)
@ -89,6 +118,7 @@ module DiasporaFederation
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
expect_callback(:save_person_after_webfinger, kind_of(Entities::Person))
person = Discovery::Discovery.new(account).fetch_and_save
expect(person.guid).to eq(alice.guid)
@ -179,7 +209,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)
@ -188,6 +218,7 @@ module DiasporaFederation
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: historic_hcard_html)
expect_callback(:save_person_after_webfinger, kind_of(Entities::Person))
person = Discovery::Discovery.new(account).fetch_and_save
expect(person.guid).to eq(alice.guid)

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Discovery::HCard do
let(:person) { FactoryGirl.create(:person) }
let(:person) { Fabricate(:person) }
let(:photo_large_url) { "#{person.url}/upload/large.png" }
let(:photo_medium_url) { "#{person.url}/upload/medium.png" }
let(:photo_small_url) { "#{person.url}/upload/small.png" }

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Discovery::WebFinger do
let(:person) { FactoryGirl.create(:person) }
let(:person) { Fabricate(:person) }
let(:acct) { "acct:#{person.diaspora_id}" }
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::AccountDeletion do
let(:data) { FactoryGirl.attributes_for(:account_deletion_entity) }
let(:data) { Fabricate.attributes_for(:account_deletion_entity) }
let(:xml) { <<-XML }
<account_deletion>

View file

@ -3,9 +3,8 @@ module DiasporaFederation
let(:new_diaspora_id) { alice.diaspora_id }
let(:new_author_pkey) { alice.private_key }
let(:hash) {
FactoryGirl.attributes_for(
:account_migration_entity,
profile: FactoryGirl.build(:profile_entity, author: new_diaspora_id)
Fabricate.attributes_for(:account_deletion_entity).merge(
profile: Fabricate(:profile_entity, author: new_diaspora_id)
)
}
let(:data) {

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Comment do
let(:parent) { FactoryGirl.create(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl
Fabricate
.attributes_for(
:comment_entity,
author: alice.diaspora_id,
@ -60,12 +60,12 @@ JSON
describe "#created_at" do
it "has a created_at after parse" do
entity = described_class.from_xml(Nokogiri::XML::Document.parse(xml).root)
expect(entity.created_at).to be_within(1.second).of(Time.now.utc)
expect(entity.created_at).to be_within(1).of(Time.now.utc)
end
it "parses the created_at from the xml if it is included and correctly signed" do
created_at = Time.now.utc.change(usec: 0) - 1.minute
comment_data = FactoryGirl.attributes_for(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid)
created_at = change_time(Time.now.utc) - 60
comment_data = Fabricate.attributes_for(:comment_entity, author: alice.diaspora_id, parent_guid: parent.guid)
comment_data[:created_at] = created_at
comment_data[:parent] = parent_entity
comment = described_class.new(comment_data, %i(author guid parent_guid text created_at))

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Contact do
let(:data) { FactoryGirl.attributes_for(:contact_entity) }
let(:data) { Fabricate.attributes_for(:contact_entity) }
let(:xml) { <<-XML }
<contact>

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Conversation do
let(:parent) { FactoryGirl.create(:conversation, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:conversation, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:signed_msg1) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:message_entity,
author: bob.diaspora_id,
parent_guid: parent.guid,
@ -11,7 +11,7 @@ module DiasporaFederation
).tap {|hash| add_signatures(hash, Entities::Message) }
}
let(:signed_msg2) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:message_entity,
author: bob.diaspora_id,
parent_guid: parent.guid,
@ -19,11 +19,11 @@ module DiasporaFederation
).tap {|hash| add_signatures(hash, Entities::Message) }
}
let(:data) {
FactoryGirl.attributes_for(:conversation_entity).merge!(
Fabricate.attributes_for(:conversation_entity).merge!(
messages: [Entities::Message.new(signed_msg1), Entities::Message.new(signed_msg2)],
author: bob.diaspora_id,
guid: parent.guid,
participants: "#{bob.diaspora_id};#{FactoryGirl.generate(:diaspora_id)}"
participants: "#{bob.diaspora_id};#{Fabricate.sequence(:diaspora_id)}"
)
}
@ -34,7 +34,7 @@ module DiasporaFederation
<subject>#{data[:subject]}</subject>
<created_at>#{data[:created_at].utc.iso8601}</created_at>
<participant_handles>#{data[:participants]}</participant_handles>
#{data[:messages].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
#{data[:messages].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")}
</conversation>
XML

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::EventParticipation do
let(:parent) { FactoryGirl.create(:event, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:event, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:event_participation_entity,
author: alice.diaspora_id,
parent_guid: parent.guid,

View file

@ -1,8 +1,8 @@
module DiasporaFederation
describe Entities::Event do
let(:location) { FactoryGirl.build(:location_entity) }
let(:location) { Fabricate(:location_entity) }
let(:data) {
FactoryGirl.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location)
Fabricate.attributes_for(:event_entity).merge(author: alice.diaspora_id, location: location)
}
let(:xml) { <<-XML }

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Like do
let(:parent) { FactoryGirl.create(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:like_entity,
author: alice.diaspora_id,
parent_guid: parent.guid,

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Location do
let(:data) { FactoryGirl.attributes_for(:location_entity) }
let(:data) { Fabricate.attributes_for(:location_entity) }
let(:xml) { <<-XML }
<location>

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Message do
let(:parent) { FactoryGirl.create(:conversation, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:conversation, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl
Fabricate
.attributes_for(:message_entity, author: alice.diaspora_id, parent_guid: parent.guid, parent: parent_entity)
.tap {|hash| add_signatures(hash) }
}
@ -44,7 +44,7 @@ XML
it "does not allow any other person" do
expect_callback(:fetch_related_entity, "Conversation", entity.conversation_guid).and_return(parent_entity)
invalid_sender = FactoryGirl.generate(:diaspora_id)
invalid_sender = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_sender)).to be_falsey
end

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Participation do
let(:parent) { FactoryGirl.create(:post, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:post, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:participation_entity,
author: alice.diaspora_id,
parent_guid: parent.guid,
@ -84,7 +84,7 @@ JSON
}
it "succeeds when the parent is local" do
local_parent = FactoryGirl.build(:related_entity, local: true)
local_parent = Fabricate(:related_entity, local: true)
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent)
expect {
@ -101,7 +101,7 @@ JSON
end
it "raises ParentNotLocal when the parent is not local" do
remote_parent = FactoryGirl.build(:related_entity, local: false)
remote_parent = Fabricate(:related_entity, local: false)
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(remote_parent)
expect {

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Person do
let(:data) { FactoryGirl.attributes_for(:person_entity) }
let(:data) { Fabricate.attributes_for(:person_entity) }
let(:xml) { <<-XML }
<person>

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Photo do
let(:data) { FactoryGirl.attributes_for(:photo_entity) }
let(:data) { Fabricate.attributes_for(:photo_entity) }
let(:xml) { <<-XML }
<photo>

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::PollAnswer do
let(:data) { FactoryGirl.attributes_for(:poll_answer_entity) }
let(:data) { Fabricate.attributes_for(:poll_answer_entity) }
let(:xml) { <<-XML }
<poll_answer>

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::PollParticipation do
let(:parent) { FactoryGirl.create(:poll, author: bob) }
let(:parent_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:parent) { Fabricate(:poll, author: bob) }
let(:parent_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:poll_participation_entity,
author: alice.diaspora_id,
parent_guid: parent.guid,

View file

@ -1,12 +1,12 @@
module DiasporaFederation
describe Entities::Poll do
let(:data) { FactoryGirl.attributes_for(:poll_entity) }
let(:data) { Fabricate.attributes_for(:poll_entity) }
let(:xml) { <<-XML }
<poll>
<guid>#{data[:guid]}</guid>
<question>#{data[:question]}</question>
#{data[:poll_answers].map {|a| a.to_xml.to_s.indent(2) }.join("\n")}
#{data[:poll_answers].map {|a| indent(a.to_xml.to_s, 2) }.join("\n")}
</poll>
XML
@ -17,7 +17,7 @@ XML
"guid": "#{data[:guid]}",
"question": "#{data[:question]}",
"poll_answers": [
#{data[:poll_answers].map {|a| JSON.pretty_generate(a.to_json).indent(6) }.join(",\n")}
#{data[:poll_answers].map {|a| indent(JSON.pretty_generate(a.to_json), 6) }.join(",\n")}
]
}
}

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Profile do
let(:data) { FactoryGirl.attributes_for(:profile_entity) }
let(:data) { Fabricate.attributes_for(:profile_entity) }
let(:xml) { <<-XML }
<profile>

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::RelatedEntity do
let(:data) { FactoryGirl.attributes_for(:related_entity) }
let(:data) { Fabricate.attributes_for(:related_entity) }
let(:string) { "RelatedEntity" }
it_behaves_like "an Entity subclass"

View file

@ -1,15 +1,15 @@
module DiasporaFederation
describe Entities::RelayableRetraction do
let(:target) { FactoryGirl.create(:comment, author: bob) }
let(:target) { Fabricate(:comment, author: bob) }
let(:target_entity) {
FactoryGirl.build(
Fabricate(
:related_entity,
author: bob.diaspora_id,
parent: FactoryGirl.build(:related_entity, author: alice.diaspora_id)
parent: Fabricate(:related_entity, author: alice.diaspora_id)
)
}
let(:data) {
FactoryGirl.build(
Fabricate(
:relayable_retraction_entity,
author: alice.diaspora_id,
target_guid: target.guid,
@ -41,11 +41,11 @@ XML
describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
let(:hash) { Fabricate.attributes_for(:relayable_retraction_entity) }
it "updates author signature when it was nil and key was supplied and author is not parent author" do
parent = FactoryGirl.build(:related_entity, author: bob.diaspora_id)
hash[:target] = FactoryGirl.build(:related_entity, author: hash[:author], parent: parent)
parent = Fabricate(:related_entity, author: bob.diaspora_id)
hash[:target] = Fabricate(:related_entity, author: hash[:author], parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -58,8 +58,8 @@ XML
end
it "sets parent author signature when author is parent author" do
parent = FactoryGirl.build(:related_entity, author: hash[:author])
hash[:target] = FactoryGirl.build(:related_entity, author: hash[:author], parent: parent)
parent = Fabricate(:related_entity, author: hash[:author])
hash[:target] = Fabricate(:related_entity, author: hash[:author], parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -72,8 +72,8 @@ XML
end
it "updates parent author signature when it was nil, key was supplied and sender is author of the parent" do
parent = FactoryGirl.build(:related_entity, author: hash[:author])
hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent)
parent = Fabricate(:related_entity, author: hash[:author])
hash[:target] = Fabricate(:related_entity, author: bob.diaspora_id, parent: parent)
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -105,7 +105,7 @@ XML
describe "#to_retraction" do
it "copies the attributes to a Retraction" do
relayable_retraction = FactoryGirl.build(:relayable_retraction_entity)
relayable_retraction = Fabricate(:relayable_retraction_entity)
retraction = relayable_retraction.to_retraction
expect(retraction).to be_a(Entities::Retraction)

View file

@ -3,13 +3,13 @@ module DiasporaFederation
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:parent_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:guid) { FactoryGirl.generate(:guid) }
let(:parent_guid) { FactoryGirl.generate(:guid) }
let(:author) { FactoryGirl.generate(:diaspora_id) }
let(:guid) { Fabricate.sequence(:guid) }
let(:parent_guid) { Fabricate.sequence(:guid) }
let(:author) { Fabricate.sequence(:diaspora_id) }
let(:property) { "hello" }
let(:new_property) { "some text" }
let(:local_parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:remote_parent) { FactoryGirl.build(:related_entity, author: bob.diaspora_id, local: false) }
let(:local_parent) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:remote_parent) { Fabricate(:related_entity, author: bob.diaspora_id, local: false) }
let(:hash) { {guid: guid, author: author, parent_guid: parent_guid, parent: local_parent, property: property} }
let(:hash_with_fake_signatures) { hash.merge!(author_signature: "aa", parent_author_signature: "bb") }
@ -521,7 +521,7 @@ XML
it "does not allow any random author" do
entity = Entities::SomeRelayable.new(hash)
invalid_author = FactoryGirl.generate(:diaspora_id)
invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey
end

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Entities::Request do
let(:data) { FactoryGirl.attributes_for(:request_entity) }
let(:data) { Fabricate.attributes_for(:request_entity) }
let(:xml) { <<-XML }
<request>
@ -17,7 +17,7 @@ XML
describe "#to_contact" do
it "copies the attributes to a Contact" do
request = FactoryGirl.build(:request_entity)
request = Fabricate(:request_entity)
contact = request.to_contact
expect(contact).to be_a(Entities::Contact)

View file

@ -1,7 +1,7 @@
module DiasporaFederation
describe Entities::Reshare do
let(:root) { FactoryGirl.create(:post, author: bob) }
let(:data) { FactoryGirl.attributes_for(:reshare_entity, root_guid: root.guid, root_author: bob.diaspora_id) }
let(:root) { Fabricate(:post, author: bob) }
let(:data) { Fabricate.attributes_for(:reshare_entity, root_guid: root.guid, root_author: bob.diaspora_id) }
let(:xml) { <<-XML }
<reshare>

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::Retraction do
let(:target) { FactoryGirl.create(:post, author: bob) }
let(:target_entity) { FactoryGirl.build(:related_entity, author: bob.diaspora_id) }
let(:target) { Fabricate(:post, author: bob) }
let(:target_entity) { Fabricate(:related_entity, author: bob.diaspora_id) }
let(:data) {
FactoryGirl.attributes_for(
Fabricate.attributes_for(
:retraction_entity,
target_guid: target.guid,
target_type: target.entity_type,
@ -37,7 +37,7 @@ XML
it "does not allow any random author" do
entity = Entities::Retraction.new(data)
invalid_author = FactoryGirl.generate(:diaspora_id)
invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey
end
@ -46,10 +46,10 @@ XML
%w(Comment Like PollParticipation).each do |target_type|
context "#{target_type} target" do
let(:relayable_target) {
FactoryGirl.build(
Fabricate(
:related_entity,
author: bob.diaspora_id,
parent: FactoryGirl.build(:related_entity, author: alice.diaspora_id)
parent: Fabricate(:related_entity, author: alice.diaspora_id)
)
}
let(:relayable_data) { data.merge(target_type: target_type, target: relayable_target) }
@ -68,7 +68,7 @@ XML
it "does not allow any random author" do
entity = Entities::Retraction.new(relayable_data)
invalid_author = FactoryGirl.generate(:diaspora_id)
invalid_author = Fabricate.sequence(:diaspora_id)
expect(entity.sender_valid?(invalid_author)).to be_falsey
end

View file

@ -1,9 +1,9 @@
module DiasporaFederation
describe Entities::SignedRetraction do
let(:target) { FactoryGirl.create(:post, author: alice) }
let(:target_entity) { FactoryGirl.build(:related_entity, author: alice.diaspora_id) }
let(:target) { Fabricate(:post, author: alice) }
let(:target_entity) { Fabricate(:related_entity, author: alice.diaspora_id) }
let(:data) {
FactoryGirl.build(
Fabricate(
:signed_retraction_entity,
author: alice.diaspora_id,
target_guid: target.guid,
@ -31,7 +31,7 @@ XML
describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
let(:hash) { Fabricate.attributes_for(:signed_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do
expect_callback(:fetch_private_key, hash[:author]).and_return(author_pkey)
@ -62,7 +62,7 @@ XML
describe "#to_retraction" do
it "copies the attributes to a Retraction" do
signed_retraction = FactoryGirl.build(:signed_retraction_entity)
signed_retraction = Fabricate(:signed_retraction_entity)
retraction = signed_retraction.to_retraction
expect(retraction).to be_a(Entities::Retraction)

View file

@ -1,10 +1,10 @@
module DiasporaFederation
describe Entities::StatusMessage do
let(:photo1) { FactoryGirl.build(:photo_entity, author: alice.diaspora_id) }
let(:photo2) { FactoryGirl.build(:photo_entity, author: alice.diaspora_id) }
let(:location) { FactoryGirl.build(:location_entity) }
let(:photo1) { Fabricate(:photo_entity, author: alice.diaspora_id) }
let(:photo2) { Fabricate(:photo_entity, author: alice.diaspora_id) }
let(:location) { Fabricate(:location_entity) }
let(:data) {
FactoryGirl.attributes_for(:status_message_entity).merge(
Fabricate.attributes_for(:status_message_entity).merge(
author: alice.diaspora_id,
photos: [photo1, photo2],
location: location,
@ -140,7 +140,7 @@ XML
context "nested entities" do
it "validates that nested photos have the same author" do
invalid_data = data.merge(author: FactoryGirl.generate(:diaspora_id))
invalid_data = data.merge(author: Fabricate.sequence(:diaspora_id))
expect {
Entities::StatusMessage.new(invalid_data)
}.to raise_error Entity::ValidationError

View file

@ -158,7 +158,7 @@ XML
test2: false,
test3: "456",
test4: 789,
test5: Time.current.utc
test5: Time.now.utc
}
}
@ -208,7 +208,7 @@ XML
describe ".from_json" do
it "parses entity properties from the input JSON data" do
now = Time.now.change(usec: 0).utc
now = change_time(Time.now.utc)
entity_data = <<-JSON
{
"entity_type": "test_complex_entity",
@ -281,7 +281,7 @@ JSON
describe ".from_hash" do
it "parses entity properties from the input data" do
now = Time.now.change(usec: 0).utc
now = change_time(Time.now.utc)
entity_data = {
test1: "abc",
test2: false,
@ -417,7 +417,7 @@ JSON
end
it "is not added to xml if #to_xml returns nil" do
entity = Entities::TestEntityWithRelatedEntity.new(test: "test", parent: FactoryGirl.build(:related_entity))
entity = Entities::TestEntityWithRelatedEntity.new(test: "test", parent: Fabricate(:related_entity))
xml = entity.to_xml
expect(xml.children).to have_exactly(1).items
xml.children.first.name = "test"

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Federation::Fetcher do
let(:post) { FactoryGirl.build(:status_message_entity, public: true) }
let(:post) { Fabricate(:status_message_entity, public: true) }
let(:post_magic_env) { Salmon::MagicEnvelope.new(post, post.author).envelop(alice.private_key).to_xml }
describe ".fetch_public" do

View file

@ -1,7 +1,7 @@
module DiasporaFederation
describe Federation::Receiver::Private do
let(:recipient) { 42 }
let(:post) { FactoryGirl.build(:status_message_entity, public: false) }
let(:post) { Fabricate(:status_message_entity, public: false) }
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
describe "#receive" do
@ -12,7 +12,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(post, sender)
expect {
@ -27,7 +27,7 @@ module DiasporaFederation
end
context "with relayable" do
let(:comment) { FactoryGirl.build(:comment_entity, parent: FactoryGirl.build(:related_entity, public: false)) }
let(:comment) { Fabricate(:comment_entity, parent: Fabricate(:related_entity, public: false)) }
it "receives a comment from the author" do
magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
@ -46,7 +46,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(comment, sender)
expect {
@ -57,7 +57,7 @@ module DiasporaFederation
context "with retraction" do
context "for a post" do
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") }
let(:retraction) { Fabricate(:retraction_entity, target_type: "Post") }
it "retracts a post from the author" do
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.target.author)
@ -68,7 +68,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect {
@ -79,10 +79,10 @@ module DiasporaFederation
context "for a comment" do
let(:retraction) {
FactoryGirl.build(
Fabricate(
:retraction_entity,
target_type: "Comment",
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity))
target: Fabricate(:related_entity, parent: Fabricate(:related_entity))
)
}
@ -103,7 +103,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect {

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Federation::Receiver::Public do
let(:post) { FactoryGirl.build(:status_message_entity) }
let(:post) { Fabricate(:status_message_entity) }
let(:magic_env) { Salmon::MagicEnvelope.new(post, post.author) }
describe "#receive" do
@ -11,7 +11,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(post, sender)
expect {
@ -20,7 +20,7 @@ module DiasporaFederation
end
context "with relayable" do
let(:comment) { FactoryGirl.build(:comment_entity) }
let(:comment) { Fabricate(:comment_entity) }
it "receives a comment from the author" do
magic_env = Salmon::MagicEnvelope.new(comment, comment.author)
@ -39,7 +39,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(comment, sender)
expect {
@ -50,7 +50,7 @@ module DiasporaFederation
context "with retraction" do
context "for a post" do
let(:retraction) { FactoryGirl.build(:retraction_entity, target_type: "Post") }
let(:retraction) { Fabricate(:retraction_entity, target_type: "Post") }
it "retracts a post from the author" do
magic_env = Salmon::MagicEnvelope.new(retraction, retraction.author)
@ -61,7 +61,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect {
@ -72,10 +72,10 @@ module DiasporaFederation
context "for a comment" do
let(:retraction) {
FactoryGirl.build(
Fabricate(
:retraction_entity,
target_type: "Comment",
target: FactoryGirl.build(:related_entity, parent: FactoryGirl.build(:related_entity))
target: Fabricate(:related_entity, parent: Fabricate(:related_entity))
)
}
@ -96,7 +96,7 @@ module DiasporaFederation
end
it "validates the sender" do
sender = FactoryGirl.generate(:diaspora_id)
sender = Fabricate.sequence(:diaspora_id)
bad_env = Salmon::MagicEnvelope.new(retraction, sender)
expect {
@ -108,7 +108,7 @@ module DiasporaFederation
context "validates if it is public" do
it "allows public entities" do
public_post = FactoryGirl.build(:status_message_entity, public: true)
public_post = Fabricate(:status_message_entity, public: true)
magic_env = Salmon::MagicEnvelope.new(public_post, public_post.author)
expect_callback(:receive_entity, public_post, public_post.author, nil)
@ -117,7 +117,7 @@ module DiasporaFederation
end
it "does not allow non-public entities" do
private_post = FactoryGirl.build(:status_message_entity, public: false)
private_post = Fabricate(:status_message_entity, public: false)
magic_env = Salmon::MagicEnvelope.new(private_post, private_post.author)
expect {
@ -126,7 +126,7 @@ module DiasporaFederation
end
it "allows entities without public flag" do
profile = FactoryGirl.build(:profile_entity)
profile = Fabricate(:profile_entity)
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
expect_callback(:receive_entity, profile, profile.author, nil)

View file

@ -4,7 +4,7 @@ module DiasporaFederation
let(:recipient_key) { OpenSSL::PKey::RSA.generate(1024) }
describe ".receive_public" do
let(:post) { FactoryGirl.build(:status_message_entity) }
let(:post) { Fabricate(:status_message_entity) }
it "parses the entity with magic envelope receiver" do
expect_callback(:fetch_public_key, post.author).and_return(sender_key)
@ -44,7 +44,7 @@ module DiasporaFederation
end
describe ".receive_private" do
let(:post) { FactoryGirl.build(:status_message_entity, public: false) }
let(:post) { Fabricate(:status_message_entity, public: false) }
it "parses the entity with magic envelope receiver" do
expect_callback(:fetch_public_key, post.author).and_return(sender_key)

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Federation::Sender::HydraWrapper do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) }
let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:obj_str) { "status_message@guid" }
let(:xml) { "<xml>post</xml>" }
let(:url) { "http://example.org/receive/public" }

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Federation::Sender do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) }
let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:obj_str) { "status_message@guid" }
let(:hydra_wrapper) { double }

View file

@ -26,7 +26,7 @@ JSON
'{"entity_type": "test_complex_entity"}'
it "returns a hash for the correct JSON input" do
now = Time.now.change(usec: 0).utc
now = change_time(Time.now.utc)
json = <<-JSON
{
"entity_type": "test_complex_entity",

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Salmon::EncryptedMagicEnvelope do
let(:sender_id) { FactoryGirl.generate(:diaspora_id) }
let(:sender_id) { Fabricate.sequence(:diaspora_id) }
let(:sender_key) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs
let(:entity) { Entities::TestEntity.new(test: "abcd") }
let(:magic_env) { Salmon::MagicEnvelope.new(entity, sender_id).envelop(sender_key) }

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Salmon::MagicEnvelope do
let(:sender) { FactoryGirl.generate(:diaspora_id) }
let(:sender) { Fabricate.sequence(:diaspora_id) }
let(:privkey) { OpenSSL::PKey::RSA.generate(512) } # use small key for speedy specs
let(:payload) { Entities::TestEntity.new(test: "asdf") }
let(:envelope) { Salmon::MagicEnvelope.new(payload, sender) }
@ -139,7 +139,7 @@ module DiasporaFederation
end
it "verifies the signature" do
other_sender = FactoryGirl.generate(:diaspora_id)
other_sender = Fabricate.sequence(:diaspora_id)
other_key = OpenSSL::PKey::RSA.generate(512)
expect_callback(:fetch_public_key, other_sender).and_return(other_key)

View file

@ -25,7 +25,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :messages }
let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:message_entity)]] }
let(:correct_values) { [[], [Fabricate(:message_entity)]] }
end
end
@ -33,8 +33,8 @@ module DiasporaFederation
# must not contain more than 20 participant handles
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :participants }
let(:wrong_values) { [Array.new(21) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
let(:correct_values) { [Array.new(20) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
let(:wrong_values) { [Array.new(21) { Fabricate.sequence(:diaspora_id) }.join(";")] }
let(:correct_values) { [Array.new(20) { Fabricate.sequence(:diaspora_id) }.join(";")] }
end
end
end

View file

@ -21,11 +21,11 @@ module DiasporaFederation
describe "#poll_answers" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :poll_answers }
let(:wrong_values) { [nil, [FactoryGirl.attributes_for(:poll_answer_entity)]] }
let(:wrong_values) { [nil, [Fabricate.attributes_for(:poll_answer_entity)]] }
let(:correct_values) {
[
Array.new(2) { FactoryGirl.build(:poll_answer_entity) },
Array.new(5) { FactoryGirl.build(:poll_answer_entity) }
Array.new(2) { Fabricate(:poll_answer_entity) },
Array.new(5) { Fabricate(:poll_answer_entity) }
]
}
end

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
let(:correct_values) { [Fabricate(:related_entity)] }
end
end
end

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
let(:correct_values) { [Fabricate(:related_entity)] }
end
end
end

View file

@ -1,5 +1,5 @@
describe Validation::Rule::DiasporaIdCount do
let(:id_str) { Array.new(3) { FactoryGirl.generate(:diaspora_id) }.join(";") }
let(:id_str) { Array.new(3) { Fabricate.sequence(:diaspora_id) }.join(";") }
it "requires a parameter" do
validator = Validation::Validator.new({})

View file

@ -22,7 +22,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
let(:correct_values) { [Fabricate(:related_entity)] }
end
end
end

View file

@ -17,7 +17,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :photos }
let(:wrong_values) { [nil] }
let(:correct_values) { [[], [FactoryGirl.build(:photo_entity)]] }
let(:correct_values) { [[], [Fabricate(:photo_entity)]] }
end
end

View file

@ -14,7 +14,7 @@ module DiasporaFederation
DiasporaFederation.server_uri = temp
end
context "certificate_authorities" do
context "certificate_authorities", rails: true do
before do
@certificate_authorities = DiasporaFederation.certificate_authorities
end

View file

@ -12,76 +12,52 @@ unless ENV["NO_COVERAGE"] == "true"
end
end
ENV["RAILS_ENV"] ||= "test"
require File.join(File.dirname(__FILE__), "..", "test", "dummy", "config", "environment")
dummy_app_path = File.join(File.dirname(__FILE__), "..", "test", "dummy")
require "rspec/rails"
require "webmock/rspec"
begin
require "rails" # try to load rails
rescue LoadError
Dir["#{File.join(dummy_app_path, 'app', 'models')}/*.rb"].each {|f| require f }
require File.join(dummy_app_path, "config", "initializers", "diaspora_federation")
else
ENV["RAILS_ENV"] ||= "test"
require File.join(dummy_app_path, "config", "environment")
require "rspec/rails"
end
# test helpers
require "json-schema-rspec"
require "rspec/collection_matchers"
require "rspec/json_expectations"
require "webmock/rspec"
# load factory girl factories
# load factories
require "factories"
# load test entities
require "entities"
# some helper methods
def alice
@alice ||= Person.find_by(diaspora_id: "alice@localhost:3000")
end
def bob
@bob ||= Person.find_by(diaspora_id: "bob@localhost:3000")
end
def expect_callback(*opts)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
end
def add_signatures(hash, klass=described_class)
properties = klass.new(hash).send(:enriched_properties)
hash[:author_signature] = properties[:author_signature]
hash[:parent_author_signature] = properties[:parent_author_signature]
end
def sign_with_key(privkey, signature_data)
Base64.strict_encode64(privkey.sign(OpenSSL::Digest::SHA256.new, signature_data))
end
def verify_signature(pubkey, signature, signed_string)
pubkey.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signed_string)
end
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb"
support_files = Dir["#{File.dirname(__FILE__)}/support/**/*.rb"] - [fixture_builder_file]
support_files.each {|f| require f }
require fixture_builder_file
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
RSpec.configure do |config|
config.include JSON::SchemaMatchers
config.json_schemas[:entity_schema] = "lib/diaspora_federation/schemas/federation_entities.json"
config.example_status_persistence_file_path = "spec/rspec-persistance.txt"
config.infer_spec_type_from_file_location!
config.render_views
config.example_status_persistence_file_path = "spec/rspec-persistence.txt"
config.expect_with :rspec do |expect_config|
expect_config.syntax = :expect
end
config.include FactoryGirl::Syntax::Methods
config.use_transactional_fixtures = true
# load fixtures
config.fixture_path = "#{::Rails.root}/test/fixtures"
config.global_fixtures = :all
config.filter_run_excluding rails4: true if Rails::VERSION::MAJOR == 5
if defined?(::Rails)
config.filter_run_excluding rails: (::Rails::VERSION::MAJOR == 5 ? 4 : 5)
else
config.exclude_pattern = "**/controllers/**/*_spec.rb, **/routing/**/*_spec.rb"
config.filter_run_excluding rails: true
end
# whitelist codeclimate.com so test coverage can be reported
config.after(:suite) do

View file

@ -1,17 +1,14 @@
require "fixture_builder"
# set default users as initial database for each test
RSpec.configure do |config|
config.before(:suite) do
Person.reset_database
Fabricate(:user, diaspora_id: "alice@localhost:3000")
Fabricate(:user, diaspora_id: "bob@localhost:3000")
Person.init_database = Person.database
end
FixtureBuilder.configure do |fbuilder|
# rebuild fixtures automatically when these files change:
fbuilder.files_to_check += Dir[
"lib/**/*.rb",
"spec/factories.rb",
"spec/support/fixture_builder.rb",
"test/dummy/app/models/*.rb"
]
# now declare objects
fbuilder.factory do
FactoryGirl.create(:user, diaspora_id: "alice@localhost:3000")
FactoryGirl.create(:user, diaspora_id: "bob@localhost:3000")
config.after(:each) do
Entity.reset_database
Person.reset_database
end
end

View file

@ -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

View file

@ -0,0 +1,42 @@
# default users
def alice
@alice ||= Person.find_by(diaspora_id: "alice@localhost:3000")
end
def bob
@bob ||= Person.find_by(diaspora_id: "bob@localhost:3000")
end
# callback expectation helper
def expect_callback(*opts)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
end
# signature methods
def add_signatures(hash, klass=described_class)
properties = klass.new(hash).send(:enriched_properties)
hash[:author_signature] = properties[:author_signature]
hash[:parent_author_signature] = properties[:parent_author_signature]
end
def sign_with_key(privkey, signature_data)
Base64.strict_encode64(privkey.sign(OpenSSL::Digest::SHA256.new, signature_data))
end
def verify_signature(pubkey, signature, signed_string)
pubkey.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signed_string)
end
# time helper
def change_time(time, options={})
new_hour = options.fetch(:hour, time.hour)
new_min = options.fetch(:min, options[:hour] ? 0 : time.min)
new_sec = options.fetch(:sec, options[:hour] || options[:min] ? 0 : time.sec)
::Time.utc(time.year, time.month, time.day, new_hour, new_min, new_sec)
end
# indent helper
def indent(string, amount)
string.gsub(/^/, " " * amount)
end

View file

@ -1,15 +1,15 @@
def entity_hash_from(hash)
hash.transform_values {|value|
hash.map {|key, value|
if [String, TrueClass, FalseClass, Integer, NilClass].any? {|c| value.is_a? c }
value
[key, value]
elsif value.is_a? Time
value.iso8601
[key, value.iso8601]
elsif value.instance_of?(Array)
value.map(&:to_h)
[key, value.map(&:to_h)]
else
value.to_h
[key, value.to_h]
end
}
}.to_h
end
shared_examples "an Entity subclass" do
@ -90,7 +90,7 @@ shared_examples "an XML Entity" do |ignored_props=[]|
def validate_property(value, parsed_value)
if value.is_a?(Time)
expect(parsed_value).to eq(value.change(usec: 0))
expect(parsed_value).to eq(change_time(value))
else
expect(parsed_value).to eq(value)
end
@ -121,7 +121,7 @@ end
shared_examples "a retraction" do
context "receive with no target found" do
let(:unknown_guid) { FactoryGirl.generate(:guid) }
let(:unknown_guid) { Fabricate.sequence(:guid) }
let(:instance) { described_class.new(data.merge(target_guid: unknown_guid)) }
it "raises when no target is found" do

View file

@ -1,6 +1,6 @@
def entity_stub(entity, data={})
OpenStruct.new(FactoryGirl.factory_by_name(entity).build_class.default_values
.merge(FactoryGirl.attributes_for(entity)).merge(data))
OpenStruct.new(Fabricate.schematic(entity).options[:class_name].default_values
.merge(Fabricate.attributes_for(entity)).merge(data))
end
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze
@ -39,7 +39,7 @@ shared_examples "a relayable validator" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :parent }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
let(:correct_values) { [Fabricate(:related_entity)] }
end
end
end
@ -135,7 +135,7 @@ shared_examples "a boolean validator" do
end
it "must not be an arbitrary string or other object" do
["asdf", Time.zone.today, 1234].each do |val|
["asdf", Date.today, 1234].each do |val|
validator = described_class.new(entity_stub(entity, property => val))
expect(validator).not_to be_valid

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -1,5 +0,0 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end

View file

@ -1,7 +0,0 @@
class DiscoveryController < ApplicationController
def discovery
discovery = DiasporaFederation::Discovery::Discovery.new(params[:q])
render json: discovery.fetch_and_save
end
end

View file

@ -1,5 +1,27 @@
class Entity < ActiveRecord::Base
include ::Diaspora::Guid
class Entity
attr_accessor :author, :guid
attr_reader :entity_type
belongs_to :author, class_name: "Person"
def initialize(entity_type)
@entity_type = entity_type
@guid = UUID.generate(:compact)
end
def save!
Entity.database[entity_type][guid] = self
end
class << self
def find_by(opts)
database[opts[:entity_type]][opts[:guid]]
end
def database
@database ||= Hash.new({})
end
def reset_database
@database = nil
end
end
end

View file

@ -1,5 +1,9 @@
class Person < ActiveRecord::Base
include ::Diaspora::Guid
class Person
attr_accessor :diaspora_id, :url, :guid, :serialized_public_key, :serialized_private_key
def initialize
@guid = UUID.generate(:compact)
end
def private_key; OpenSSL::PKey::RSA.new(serialized_private_key) end
def public_key; OpenSSL::PKey::RSA.new(serialized_public_key) end
@ -19,4 +23,26 @@ class Person < ActiveRecord::Base
def full_name; "Dummy User" end
def first_name; "Dummy" end
def last_name; "User" end
def save!
Person.database[:diaspora_id][diaspora_id] = self
Person.database[:guid][guid] = self
end
class << self
attr_writer :init_database
def find_by(opts)
return database[:diaspora_id][opts[:diaspora_id]] if opts[:diaspora_id]
database[:guid][opts[:guid]]
end
def database
@database ||= @init_database || {diaspora_id: {}, guid: {}}
end
def reset_database
@database = nil
end
end
end

View file

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>

View file

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

View file

@ -1,9 +0,0 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
require_relative '../config/boot'
require 'rake'
Rake.application.run

View file

@ -1,29 +0,0 @@
#!/usr/bin/env ruby
require 'pathname'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:
puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || bundle install"
# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# system "cp config/database.yml.sample config/database.yml"
# end
puts "\n== Preparing database =="
system "bin/rake db:setup"
puts "\n== Removing old logs and tempfiles =="
system "rm -f log/*"
system "rm -rf tmp/cache"
puts "\n== Restarting application server =="
system "touch tmp/restart.txt"
end

View file

@ -1,16 +0,0 @@
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
unless defined?(Spring)
require 'rubygems'
require 'bundler'
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end

View file

@ -1,6 +1,6 @@
require_relative "boot"
require "rails/all"
require "action_controller/railtie"
Bundler.require(*Rails.groups)
require "diaspora_federation/rails"
@ -20,7 +20,7 @@ module Dummy
# config.i18n.default_locale = :de
# Version of your assets, change this if you want to expire all your assets
config.assets.version = "1.0"
# config.assets.version = "1.0"
# autoload files from test/dummy/lib
config.autoload_once_paths += %W(#{config.root}/lib)

View file

@ -1,25 +0,0 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3

View file

@ -14,27 +14,27 @@ Rails.application.configure do
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

View file

@ -25,15 +25,15 @@ Rails.application.configure do
config.serve_static_files = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# config.assets.compile = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
@ -81,5 +81,5 @@ Rails.application.configure do
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# config.active_record.dump_schema_after_migration = false
end

View file

@ -34,13 +34,13 @@ Rails.application.configure do
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# config.action_mailer.delivery_method = :test
# Randomize the order test cases are executed.
config.active_support.test_order = :random
# config.active_support.test_order = :random
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

View file

@ -1,7 +0,0 @@
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View file

@ -1,4 +1,4 @@
require "diaspora_federation/discovery"
require "diaspora_federation"
ca_file = if File.file?("/etc/ssl/certs/ca-certificates.crt")
# For Debian, Ubuntu, Archlinux, Gentoo
@ -53,20 +53,16 @@ DiasporaFederation.configure do |config|
end
end
on :save_person_after_webfinger do |person|
unless Person.exists?(diaspora_id: person.diaspora_id)
Person.new(diaspora_id: person.diaspora_id, guid: person.guid,
serialized_public_key: person.exported_key, url: person.url).save!
end
on :save_person_after_webfinger do
end
on :fetch_private_key do |diaspora_id|
key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_private_key).first
OpenSSL::PKey::RSA.new(key) unless key.nil?
person = Person.find_by(diaspora_id: diaspora_id)
OpenSSL::PKey::RSA.new(person.serialized_private_key) unless person.nil?
end
on :fetch_public_key do |diaspora_id|
key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_public_key).first
key = Person.find_by(diaspora_id: diaspora_id).serialized_public_key
key = DiasporaFederation::Discovery::Discovery.new(diaspora_id).fetch_and_save.exported_key if key.nil?
OpenSSL::PKey::RSA.new(key) unless key.nil?
end
@ -94,7 +90,7 @@ DiasporaFederation.configure do |config|
on :fetch_public_entity do |entity_type, guid|
type = DiasporaFederation::Entities.const_get(entity_type).entity_name
FactoryGirl.build("#{type}_entity", guid: guid)
Fabricate("#{type}_entity", guid: guid)
end
on :fetch_person_url_to do |diaspora_id, path|

View file

@ -1,93 +0,0 @@
Logging::Rails.configure do |config|
# Configure the Logging framework with the default log levels
Logging.init %w(debug info warn error fatal)
# Objects will be converted to strings using the :inspect method.
Logging.format_as :inspect
# The default layout used by the appenders.
pattern = "[%d] %-5l PID-%p TID-%t %c: %m\n"
layout = Logging.layouts.pattern(pattern: pattern)
# Setup a color scheme called 'bright' than can be used to add color codes
# to the pattern layout. Color schemes should only be used with appenders
# that write to STDOUT or STDERR; inserting terminal color codes into a file
# is generally considered bad form.
Logging.color_scheme(
"bright",
levels: {
info: :green,
warn: :yellow,
error: :red,
fatal: %i(white on_red)
},
date: :blue,
logger: :cyan,
message: :magenta
)
# Configure an appender that will write log events to STDOUT. A colorized
# pattern layout is used to format the log events into strings before
# writing.
if config.log_to.include? "stdout"
Logging.appenders.stdout(
"stdout",
auto_flushing: true,
layout: Logging.layouts.pattern(
pattern: pattern,
color_scheme: "bright"
)
)
end
# Configure an appender that will write log events to a file. The file will
# be rolled on a daily basis, and the past 7 rolled files will be kept.
# Older files will be deleted. The default pattern layout is used when
# formatting log events into strings.
if config.log_to.include? "file"
Logging.appenders.rolling_file(
"file",
filename: config.paths["log"].first,
keep: 7,
age: "daily",
truncate: false,
auto_flushing: true,
layout: layout
)
end
# Setup the root logger with the Rails log level and the desired set of
# appenders. The list of appenders to use should be set in the environment
# specific configuration file.
#
# For example, in a production application you would not want to log to
# STDOUT, but you would want to send an email for "error" and "fatal"
# messages:
#
# => config/environments/production.rb
#
# config.log_to = %w[file email]
#
# In development you would want to log to STDOUT and possibly to a file:
#
# => config/environments/development.rb
#
# config.log_to = %w[stdout file]
#
Logging.logger.root.appenders = config.log_to unless config.log_to.empty?
# Default log-level (development=debug, production=info)
Logging.logger.root.level = config.log_level
# log-levels for SQL and federation debug-logging
Logging.logger[ActiveRecord::Base].level = :debug
Logging.logger["XMLLogger"].level = :debug
end
module ActiveSupport
module Dependencies
def self.logger=(_)
# This was remove in rails 5: https://github.com/rails/rails/commit/798dc5a92537ba4202a1a8e127a5ebdae87bc78d
end
end
end

View file

@ -1,12 +0,0 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string "guid", null: false
t.text "url", null: false
t.string "diaspora_handle", null: false
t.text "serialized_public_key", null: false
t.timestamps null: false
end
end
end

View file

@ -1,5 +0,0 @@
class RenameDiasporaHandleToDiasporaId < ActiveRecord::Migration
def change
rename_column :people, :diaspora_handle, :diaspora_id
end
end

View file

@ -1,5 +0,0 @@
class AddSerializedPrivateKeyToPerson < ActiveRecord::Migration
def change
add_column :people, :serialized_private_key, :text
end
end

View file

@ -1,11 +0,0 @@
class CreateEntity < ActiveRecord::Migration
def change
create_table :entities do |t|
t.belongs_to :author, class_name: "Person", null: false
t.string :guid, null: false
t.string :entity_type, null: false
t.timestamps null: false
end
end
end

View file

@ -1,33 +0,0 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160202221606) do
create_table "entities", force: :cascade do |t|
t.integer "author_id", null: false
t.string "guid", null: false
t.string "entity_type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "people", force: :cascade do |t|
t.string "guid", null: false
t.text "url", null: false
t.string "diaspora_id", null: false
t.text "serialized_public_key", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "serialized_private_key"
end
end

View file

@ -1,22 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# from diaspora for testing
module Diaspora
module Guid
# Creates a before_create callback which calls #set_guid
def self.included(model)
model.class_eval do
after_initialize :set_guid
validates :guid, uniqueness: true
end
end
# @return [String] The model's guid.
def set_guid
self.guid = UUID.generate :compact if guid.blank?
end
end
end

Some files were not shown because too many files have changed in this diff Show more