diff --git a/.env b/.env index af7723c..3b245d8 100644 --- a/.env +++ b/.env @@ -24,4 +24,4 @@ SERVE_STATIC_ASSETS="true" # Session secrets - do not change unless you want all sessions to expire WEB_SESSIONS_SECRET="<< `rake secret` >>" API_SESSIONS_SECRET="<< `rake secret` >>" -ADMIN_SESSIONS_SECRET="<< `rake secret` >>" \ No newline at end of file +ADMIN_SESSIONS_SECRET="<< `rake secret` >>" diff --git a/.env.test b/.env.test index b2da58e..41efdc4 100644 --- a/.env.test +++ b/.env.test @@ -1,7 +1,8 @@ # Define ENV variables for test environment # Database URI -FIREFLY_DATABASE_URL="sqlite://db/firefly_test.sqlite" +DB="sqlite" +FIREFLY_DATABASE_URL="$DB://db/firefly_test.sqlite" FIREFLY_REDIS_URL=redis://localhost:6379/0 # Top level, short domain name diff --git a/.env.test.mysql b/.env.test.mysql new file mode 100644 index 0000000..748308e --- /dev/null +++ b/.env.test.mysql @@ -0,0 +1,27 @@ +# Define ENV variables for test environment + +# Database URI +FIREFLY_DATABASE_URL="mysql://root@localhost/firefly_test" +FIREFLY_REDIS_URL=redis://localhost:6379/0 + +# Top level, short domain name +FIREFLY_SHORT_TLD="test.host" + +# Should firefly enforce HTTPS? true/false +FIREFLY_SSL_ENABLED="false" + +# Admin username/password +ADMIN_USERNAME="admin" +ADMIN_PASSWORD="password" + +# API token used by third-party apps to shorten URLs +FIREFLY_API_TOKEN="token" + +# Service static assets through Firefly (set to "false" if you have a +# web server sitting in front of Firefly taking care of this. +SERVE_STATIC_ASSETS="true" + +# Session secrets - do not change unless you want all sessions to expire +WEB_SESSIONS_SECRET="18746306638e0cbbf9e6963e555c9f4dc855e87213e524d7c8f6feee67f06e23" +API_SESSIONS_SECRET="629d421db660c33840b7c77b2d44e87b907c7853e6c8d0b08bbeacff54a5d45e" +ADMIN_SESSIONS_SECRET="5cb43bc6e474b4bce1f24c4aecba214152cf99b9bebefbb6071697b90e47b8ba" diff --git a/.env.test.sqlite b/.env.test.sqlite new file mode 100644 index 0000000..41efdc4 --- /dev/null +++ b/.env.test.sqlite @@ -0,0 +1,28 @@ +# Define ENV variables for test environment + +# Database URI +DB="sqlite" +FIREFLY_DATABASE_URL="$DB://db/firefly_test.sqlite" +FIREFLY_REDIS_URL=redis://localhost:6379/0 + +# Top level, short domain name +FIREFLY_SHORT_TLD="test.host" + +# Should firefly enforce HTTPS? true/false +FIREFLY_SSL_ENABLED="false" + +# Admin username/password +ADMIN_USERNAME="admin" +ADMIN_PASSWORD="password" + +# API token used by third-party apps to shorten URLs +FIREFLY_API_TOKEN="token" + +# Service static assets through Firefly (set to "false" if you have a +# web server sitting in front of Firefly taking care of this. +SERVE_STATIC_ASSETS="true" + +# Session secrets - do not change unless you want all sessions to expire +WEB_SESSIONS_SECRET="18746306638e0cbbf9e6963e555c9f4dc855e87213e524d7c8f6feee67f06e23" +API_SESSIONS_SECRET="629d421db660c33840b7c77b2d44e87b907c7853e6c8d0b08bbeacff54a5d45e" +ADMIN_SESSIONS_SECRET="5cb43bc6e474b4bce1f24c4aecba214152cf99b9bebefbb6071697b90e47b8ba" diff --git a/.travis.yml b/.travis.yml index 0ce9dd5..8dcea2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ sudo: false cache: bundler install: bundle install --jobs=3 --retry=3 --without production +before_script: + - cp .env.test.$DB .env.test + script: - 'HANAMI_ENV=test bundle exec hanami db create' - 'HANAMI_ENV=test bundle exec hanami db migrate' @@ -13,6 +16,10 @@ rvm: - 2.3.0 - ruby-head +env: + - DB=sqlite + - DB=mysql + matrix: allow_failures: - rvm: ruby-head diff --git a/Gemfile b/Gemfile index 36f18e8..f35d16a 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,13 @@ gem 'hanami-model', '~> 0.5' gem 'haml' gem 'sass' -gem 'sqlite3' +case ENV['DB'] +when 'mysql' + gem 'mysql' +else + gem 'sqlite3' +end + gem 'redis' gem 'rqrcode' diff --git a/spec/admin/features/dashboard_spec.rb b/spec/admin/features/dashboard_spec.rb index 742985b..b7e2d8c 100644 --- a/spec/admin/features/dashboard_spec.rb +++ b/spec/admin/features/dashboard_spec.rb @@ -6,7 +6,7 @@ @items = [] 10.times do |n| - @items << ItemRepository.create(Item.new(type: 'url', content: "https://devroom.io/page-#{n}")) + @items << url_item("https://devroom.io/page-#{n}", age: n) end basic_auth('admin', 'password') diff --git a/spec/firefly/repositories/item_repository_spec.rb b/spec/firefly/repositories/item_repository_spec.rb index ec8e26f..5f33da7 100644 --- a/spec/firefly/repositories/item_repository_spec.rb +++ b/spec/firefly/repositories/item_repository_spec.rb @@ -4,8 +4,8 @@ before do ItemRepository.clear - @item1 = url_item("http://test.host/1") - @item2 = url_item("http://test.host/2") + @item1 = url_item("http://test.host/1", age: 2) + @item2 = url_item("http://test.host/2", age: 1) end describe '.recent' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d7463c1..f9a777b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,6 +24,16 @@ Hanami::Application.preload! -def url_item(url = 'http://test.host/test') - CreateItemFromURL.new(url).call.item +def url_item(url = 'http://test.host/test', opts = {}) + options = { + age: 0 + }.merge!(opts) + + params = { + type: 'url', + content: url, + created_at: Time.now - options[:age] * 3600 + } + + ItemRepository.create(Item.new(params)) end