1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 08:46:41 +01:00

Merge remote-tracking branch 'origin/master' into translation-tips

# Conflicts:
#	app/controllers/translations_controller.rb
This commit is contained in:
Philipp Fischbeck 2019-02-02 19:23:55 +01:00
commit 2fb1a2d6a1
36 changed files with 455 additions and 315 deletions

View File

@ -1,9 +1,10 @@
language: ruby language: ruby
cache: bundler cache: bundler
rvm: rvm:
- 2.6
- 2.5
- 2.4 - 2.4
- 2.3 - 2.3
- 2.2
script: script:
- export RAILS_ENV=test - export RAILS_ENV=test
- bundle exec rake db:create db:migrate - bundle exec rake db:create db:migrate

34
Gemfile
View File

@ -2,41 +2,43 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.1.4' gem 'rails', '5.2.2'
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.3.13' gem 'sqlite3', '~> 1.3.13'
gem 'mysql2', '~> 0.4.10', group: :production gem 'mysql2', '~> 0.5.2', group: :production
gem 'bootsnap', require: false
# Use SCSS for stylesheets # Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.7' gem 'sassc-rails', '~> 2.1.0'
# Use Uglifier as compressor for JavaScript assets # Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '~> 3.2.0' gem 'uglifier', '~> 4.1.20'
# Use CoffeeScript for .js.coffee assets and views # Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.2.2' gem 'coffee-rails', '~> 4.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes # See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby # gem 'therubyracer', platforms: :ruby
gem 'rails-i18n', '~> 5.0.0' gem 'rails-i18n', '~> 5.1.3'
gem 'rails-controller-testing' gem 'rails-controller-testing'
# Use jquery as the JavaScript library # Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3.1' gem 'jquery-rails', '~> 4.3.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '~> 5.0.1' gem 'turbolinks', '~> 5.2.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7.0' gem 'jbuilder', '~> 2.8.0'
# bundle exec rake doc:rails generates the API under doc/api. # bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.2', group: :doc gem 'sdoc', '~> 1.0.0', group: :doc
gem 'web-console', '~> 3.5.1', group: :development gem 'web-console', '~> 3.7.0', group: :development
# Use Coveralls for coverage documentation # Use Coveralls for coverage documentation
gem 'coveralls', '~> 0.8.21', require: false gem 'coveralls', '~> 0.8.22', require: false
gem 'bootstrap-sass', '~> 3.3.7' gem 'bootstrap-sass', '~> 3.4.0'
gem 'autoprefixer-rails', '~> 7.1.6' gem 'autoprefixer-rails', '~> 9.4.6'
gem 'bh', '~> 1.3.6' gem 'bh', '~> 1.3.6'
@ -44,9 +46,7 @@ gem 'will_paginate', '~> 3.1.6'
gem 'will-paginate-i18n', '~> 0.1.15' gem 'will-paginate-i18n', '~> 0.1.15'
gem 'will_paginate-bootstrap', '~> 1.0.1' gem 'will_paginate-bootstrap', '~> 1.0.1'
gem 'mathjax-rails', '~> 2.6.1' gem 'devise', '~> 4.5.0'
gem 'devise', '~> 4.3.0'
gem 'devise-bootstrap-views', '~> 0.0.11' gem 'devise-bootstrap-views', '~> 0.0.11'
gem 'codemirror-rails', '~> 5.16.0' gem 'codemirror-rails', '~> 5.16.0'
@ -63,4 +63,4 @@ gem 'codemirror-rails', '~> 5.16.0'
# gem 'debugger', group: [:development, :test] # gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

View File

@ -1,55 +1,62 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (5.1.4) actioncable (5.2.2)
actionpack (= 5.1.4) actionpack (= 5.2.2)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (~> 0.6.1) websocket-driver (>= 0.6.1)
actionmailer (5.1.4) actionmailer (5.2.2)
actionpack (= 5.1.4) actionpack (= 5.2.2)
actionview (= 5.1.4) actionview (= 5.2.2)
activejob (= 5.1.4) activejob (= 5.2.2)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.1.4) actionpack (5.2.2)
actionview (= 5.1.4) actionview (= 5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
rack (~> 2.0) rack (~> 2.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4) actionview (5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.4) activejob (5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.1.4) activemodel (5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
activerecord (5.1.4) activerecord (5.2.2)
activemodel (= 5.1.4) activemodel (= 5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
arel (~> 8.0) arel (>= 9.0)
activesupport (5.1.4) activestorage (5.2.2)
actionpack (= 5.2.2)
activerecord (= 5.2.2)
marcel (~> 0.3.1)
activesupport (5.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (8.0.0) arel (9.0.0)
autoprefixer-rails (7.1.6) autoprefixer-rails (9.4.6)
execjs execjs
bcrypt (3.1.11) bcrypt (3.1.12)
bcrypt (3.1.11-x86-mingw32) bcrypt (3.1.12-x64-mingw32)
bcrypt (3.1.12-x86-mingw32)
bh (1.3.6) bh (1.3.6)
actionpack actionpack
activesupport activesupport
bindex (0.5.0) bindex (0.5.0)
bootstrap-sass (3.3.7) bootsnap (1.3.2)
msgpack (~> 1.0)
bootstrap-sass (3.4.0)
autoprefixer-rails (>= 5.2.1) autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4) sassc (>= 2.0.0)
builder (3.2.3) builder (3.2.3)
codemirror-rails (5.16.0) codemirror-rails (5.16.0)
railties (>= 3.0, < 6.0) railties (>= 3.0, < 6.0)
@ -60,140 +67,154 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.1.4)
coveralls (0.8.21) coveralls (0.8.22)
json (>= 1.8, < 3) json (>= 1.8, < 3)
simplecov (~> 0.14.1) simplecov (~> 0.16.1)
term-ansicolor (~> 1.3) term-ansicolor (~> 1.3)
thor (~> 0.19.4) thor (~> 0.19.4)
tins (~> 1.6) tins (~> 1.6)
crass (1.0.3) crass (1.0.4)
devise (4.3.0) devise (4.5.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2) railties (>= 4.1.0, < 6.0)
responders responders
warden (~> 1.2.3) warden (~> 1.2.3)
devise-bootstrap-views (0.0.11) devise-bootstrap-views (0.0.11)
docile (1.1.5) docile (1.3.1)
erubi (1.7.0) erubi (1.8.0)
execjs (2.7.0) execjs (2.7.0)
globalid (0.4.1) ffi (1.9.25)
ffi (1.9.25-x64-mingw32)
ffi (1.9.25-x86-mingw32)
globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
i18n (0.9.1) i18n (0.9.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jbuilder (2.7.0) jbuilder (2.8.0)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
multi_json (>= 1.2) multi_json (>= 1.2)
jquery-rails (4.3.1) jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.6) json (1.8.6)
loofah (2.1.1) loofah (2.2.3)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.0) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
mathjax-rails (2.6.1) marcel (0.3.3)
railties (>= 3.0) mimemagic (~> 0.3.2)
method_source (0.9.0) method_source (0.9.2)
mini_mime (1.0.0) mimemagic (0.3.3)
mini_portile2 (2.3.0) mini_mime (1.0.1)
minitest (5.10.3) mini_portile2 (2.4.0)
multi_json (1.12.2) minitest (5.11.3)
mysql2 (0.4.10) msgpack (1.2.6)
mysql2 (0.4.10-x86-mingw32) msgpack (1.2.6-x64-mingw32)
nio4r (2.1.0) msgpack (1.2.6-x86-mingw32)
nokogiri (1.8.1) multi_json (1.13.1)
mini_portile2 (~> 2.3.0) mysql2 (0.5.2)
nokogiri (1.8.1-x86-mingw32) mysql2 (0.5.2-x64-mingw32)
mini_portile2 (~> 2.3.0) mysql2 (0.5.2-x86-mingw32)
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
nokogiri (1.10.1-x64-mingw32)
mini_portile2 (~> 2.4.0)
nokogiri (1.10.1-x86-mingw32)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
rack (2.0.3) rack (2.0.6)
rack-test (0.8.2) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (5.1.4) rails (5.2.2)
actioncable (= 5.1.4) actioncable (= 5.2.2)
actionmailer (= 5.1.4) actionmailer (= 5.2.2)
actionpack (= 5.1.4) actionpack (= 5.2.2)
actionview (= 5.1.4) actionview (= 5.2.2)
activejob (= 5.1.4) activejob (= 5.2.2)
activemodel (= 5.1.4) activemodel (= 5.2.2)
activerecord (= 5.1.4) activerecord (= 5.2.2)
activesupport (= 5.1.4) activestorage (= 5.2.2)
activesupport (= 5.2.2)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.1.4) railties (= 5.2.2)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2) rails-controller-testing (1.0.4)
actionpack (~> 5.x, >= 5.0.1) actionpack (>= 5.0.1.x)
actionview (~> 5.x, >= 5.0.1) actionview (>= 5.0.1.x)
activesupport (~> 5.x) activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.4)
loofah (~> 2.0) loofah (~> 2.2, >= 2.2.2)
rails-i18n (5.0.4) rails-i18n (5.1.3)
i18n (~> 0.7) i18n (>= 0.7, < 2)
railties (~> 5.0) railties (>= 5.0, < 6)
railties (5.1.4) railties (5.2.2)
actionpack (= 5.1.4) actionpack (= 5.2.2)
activesupport (= 5.1.4) activesupport (= 5.2.2)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.19.0, < 2.0)
rake (12.3.0) rake (12.3.2)
rdoc (4.3.0) rdoc (6.1.1)
responders (2.4.0) responders (2.4.1)
actionpack (>= 4.2.0, < 5.3) actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 6.0)
sass (3.4.19) sassc (2.0.0)
sass-rails (5.0.7) ffi (~> 1.9.6)
railties (>= 4.0.0, < 6) rake
sass (~> 3.1) sassc-rails (2.1.0)
sprockets (>= 2.8, < 4.0) railties (>= 4.0.0)
sprockets-rails (>= 2.0, < 4.0) sassc (>= 2.0)
tilt (>= 1.1, < 3) sprockets (> 3.0)
sdoc (0.4.2) sprockets-rails
json (~> 1.7, >= 1.7.7) tilt
rdoc (~> 4.0) sdoc (1.0.0)
simplecov (0.14.1) rdoc (>= 5.0)
docile (~> 1.1.0) simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3) json (>= 1.8, < 3)
simplecov-html (~> 0.10.0) simplecov-html (~> 0.10.0)
simplecov-html (0.10.2) simplecov-html (0.10.2)
sprockets (3.4.1) sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
sprockets-rails (2.3.3) sprockets-rails (3.2.1)
actionpack (>= 3.0) actionpack (>= 4.0)
activesupport (>= 3.0) activesupport (>= 4.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 3.0.0)
sqlite3 (1.3.13) sqlite3 (1.3.13)
sqlite3 (1.3.13-x64-mingw32)
sqlite3 (1.3.13-x86-mingw32) sqlite3 (1.3.13-x86-mingw32)
term-ansicolor (1.6.0) term-ansicolor (1.7.1)
tins (~> 1.0) tins (~> 1.0)
thor (0.19.4) thor (0.19.4)
thread_safe (0.3.6) thread_safe (0.3.6)
tilt (2.0.8) tilt (2.0.9)
tins (1.15.1) tins (1.20.2)
turbolinks (5.0.1) turbolinks (5.2.0)
turbolinks-source (~> 5) turbolinks-source (~> 5.2)
turbolinks-source (5.0.3) turbolinks-source (5.2.0)
tzinfo (1.2.4) tzinfo (1.2.5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo-data (1.2015.7) tzinfo-data (1.2018.9)
tzinfo (>= 1.0.0) tzinfo (>= 1.0.0)
uglifier (3.2.0) uglifier (4.1.20)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
warden (1.2.7) warden (1.2.8)
rack (>= 1.0) rack (>= 2.0.6)
web-console (3.5.1) web-console (3.7.0)
actionview (>= 5.0) actionview (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
bindex (>= 0.4.0) bindex (>= 0.4.0)
railties (>= 5.0) railties (>= 5.0)
websocket-driver (0.6.5) websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3) websocket-extensions (0.1.3)
will-paginate-i18n (0.1.15) will-paginate-i18n (0.1.15)
@ -203,34 +224,35 @@ GEM
PLATFORMS PLATFORMS
ruby ruby
x64-mingw32
x86-mingw32 x86-mingw32
DEPENDENCIES DEPENDENCIES
autoprefixer-rails (~> 7.1.6) autoprefixer-rails (~> 9.4.6)
bh (~> 1.3.6) bh (~> 1.3.6)
bootstrap-sass (~> 3.3.7) bootsnap
bootstrap-sass (~> 3.4.0)
codemirror-rails (~> 5.16.0) codemirror-rails (~> 5.16.0)
coffee-rails (~> 4.2.2) coffee-rails (~> 4.2.2)
coveralls (~> 0.8.21) coveralls (~> 0.8.22)
devise (~> 4.3.0) devise (~> 4.5.0)
devise-bootstrap-views (~> 0.0.11) devise-bootstrap-views (~> 0.0.11)
jbuilder (~> 2.7.0) jbuilder (~> 2.8.0)
jquery-rails (~> 4.3.1) jquery-rails (~> 4.3.3)
mathjax-rails (~> 2.6.1) mysql2 (~> 0.5.2)
mysql2 (~> 0.4.10) rails (= 5.2.2)
rails (= 5.1.4)
rails-controller-testing rails-controller-testing
rails-i18n (~> 5.0.0) rails-i18n (~> 5.1.3)
sass-rails (~> 5.0.7) sassc-rails (~> 2.1.0)
sdoc (~> 0.4.2) sdoc (~> 1.0.0)
sqlite3 (~> 1.3.13) sqlite3 (~> 1.3.13)
turbolinks (~> 5.0.1) turbolinks (~> 5.2.0)
tzinfo-data tzinfo-data
uglifier (~> 3.2.0) uglifier (~> 4.1.20)
web-console (~> 3.5.1) web-console (~> 3.7.0)
will-paginate-i18n (~> 0.1.15) will-paginate-i18n (~> 0.1.15)
will_paginate (~> 3.1.6) will_paginate (~> 3.1.6)
will_paginate-bootstrap (~> 1.0.1) will_paginate-bootstrap (~> 1.0.1)
BUNDLED WITH BUNDLED WITH
1.16.0 1.17.2

View File

@ -4,8 +4,8 @@ Projekt Euler
[![Build Status](https://travis-ci.org/PFischbeck/projekteuler.svg?branch=master)](https://travis-ci.org/PFischbeck/projekteuler) [![Build Status](https://travis-ci.org/PFischbeck/projekteuler.svg?branch=master)](https://travis-ci.org/PFischbeck/projekteuler)
[![Coverage Status](https://img.shields.io/coveralls/PFischbeck/projekteuler.svg)](https://coveralls.io/r/PFischbeck/projekteuler?branch=master) [![Coverage Status](https://img.shields.io/coveralls/PFischbeck/projekteuler.svg)](https://coveralls.io/r/PFischbeck/projekteuler?branch=master)
[![Code Climate](https://codeclimate.com/github/PFischbeck/projekteuler/badges/gpa.svg)](https://codeclimate.com/github/PFischbeck/projekteuler) [![Code Climate](https://codeclimate.com/github/PFischbeck/projekteuler/badges/gpa.svg)](https://codeclimate.com/github/PFischbeck/projekteuler)
[![Dependency Status](https://gemnasium.com/PFischbeck/projekteuler.svg)](https://gemnasium.com/PFischbeck/projekteuler)
[![security](https://hakiri.io/github/PFischbeck/projekteuler/master.svg)](https://hakiri.io/github/PFischbeck/projekteuler/master) [![security](https://hakiri.io/github/PFischbeck/projekteuler/master.svg)](https://hakiri.io/github/PFischbeck/projekteuler/master)
This is a rails app for the german translation of [projecteuler.net](https://projecteuler.net). This is a rails app for the german translation of [projecteuler.net](https://projecteuler.net).
Currently, it doesn't have a website, but when most of the current issues are fixed, it will be uploaded. Currently, it doesn't have a website, but when most of the current issues are fixed, it will be uploaded.

View File

@ -1,3 +1,6 @@
# Place all the behaviors and hooks related to the matching controller here. # Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js. # All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/ # You can use CoffeeScript in this file: http://coffeescript.org/
$(document).on "turbolinks:load", ->
$('[data-toggle="tooltip"]').tooltip()

View File

@ -1,18 +1,28 @@
class Admin::TranslationsController < AdminController class Admin::TranslationsController < AdminController
before_action :set_translation, only: :show before_action :set_translation, only: [:show, :accept, :decline]
# GET /translations # GET /translations
# GET /translations.json
def index def index
@translations = Translation.paginate(page: params[:page]) @translations = Translation.pending.order(created_at: :desc).paginate(page: params[:page])
end end
# GET /translations/1 # GET /translations/1
# GET /translations/1.json
def show def show
end end
def accept
raise t('.must_be_pending') unless @translation.pending?
@translation.problem.set_translation(@translation)
redirect_to @translation.problem, notice: t('.success_message')
end
def decline
raise t('.must_be_pending') unless @translation.pending?
@translation.declined!
redirect_to admin_translations_path, notice: t('.success_message')
end
def set_translation def set_translation
@translation = Translation.find(params[:id]) @translation = Translation.find(params[:translation_id])
end end
end end

View File

@ -1,38 +1,32 @@
class TranslationsController < ApplicationController class TranslationsController < ApplicationController
before_action :set_problem, only: [:new, :create] before_action :set_problem, only: [:new, :create]
# GET /translations/new # GET /translations/new
def new def new
@translation = @problem.translations.build @translation = @problem.translations.build
if @problem.is_translated? if @problem.is_translated?
@translation.title = @problem.translation.title @translation.title = @problem.translation.title
@translation.content = @problem.translation.content @translation.content = @problem.translation.content
end end
end end
# POST /translations # POST /translations
# POST /translations.json def create
def create @translation = @problem.translations.new(translation_params)
@translation = @problem.translations.new(translation_params) if @translation.save
redirect_to @problem, notice: t('translations.notice.successfully_created')
respond_to do |format| else
if @translation.save render :new
format.html { redirect_to @problem, notice: t('translations.notice.successfully_created') } end
format.json { render :show, status: :created, location: @translation } end
else
format.html { render :new } private
format.json { render json: @translation.errors, status: :unprocessable_entity } # Never trust parameters from the scary internet, only allow the white list through.
end def translation_params
end params.require(:translation).permit(:title, :content)
end end
private def set_problem
# Never trust parameters from the scary internet, only allow the white list through. @problem = Problem.find(params[:problem_id])
def translation_params end
params.require(:translation).permit(:title, :content) end
end
def set_problem
@problem = Problem.find(params[:problem_id])
end
end

View File

@ -11,6 +11,14 @@ class Problem < ApplicationRecord
!!self.translation !!self.translation
end end
def set_translation(translation)
if self.is_translated?
self.translation.outdated!
end
self.update(translation: translation)
self.translation.in_use!
end
def original_url def original_url
"https://projecteuler.net/problem=#{self.id}" "https://projecteuler.net/problem=#{self.id}"
end end

View File

@ -1,5 +1,6 @@
class Translation < ApplicationRecord class Translation < ApplicationRecord
belongs_to :problem, inverse_of: :translations belongs_to :problem, inverse_of: :translations
enum status: [:pending, :in_use, :outdated, :declined]
validates :title, :content, :problem_id, presence: true validates :title, :content, :problem_id, presence: true
validate :title_is_unique_among_other_problems validate :title_is_unique_among_other_problems

View File

@ -14,7 +14,7 @@
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<h2>Ansehen</h2> <h2>Ansehen</h2>
<p>Bisher wurden leider erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt, es gibt also noch einiges zu tun!</p> <p>Sehen Sie sich die mathematischen Probleme in deutscher Sprache an.</p>
<p> <p>
<%= link_to problems_path, class: 'btn btn-default' do %> <%= link_to problems_path, class: 'btn btn-default' do %>
Zu den Problemen &raquo; Zu den Problemen &raquo;
@ -22,14 +22,13 @@
</p> </p>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h2>Erweitern</h2> <h2>Übersetzen</h2>
<p>Sie haben in Zukunft auch die Möglichkeit, eigene Übersetzungen vorzuschlagen. An diesem Feature wird aber zurzeit noch gearbeitet.</p> <p>Bisher wurden erst <%= Problem.translated_count %> der <%= Problem.count %> Probleme übersetzt. Helfen Sie mit, Übersetzungen zu erstellen und anzupassen!</p>
<p><a class="btn btn-default disabled" href="#" role="button">Übersetzung vorschlagen &raquo;</a></p>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h2>Verbessern</h2> <h2>Verbessern</h2>
<p>Haben Sie Verbesserungsvorschläge für eine der Übersetzungen? Fehlt Ihnen eine Funktion auf der Webseite, oder ist Ihnen ein Fehler aufgefallen? Dann schreiben Sie uns!</p> <p>Vermissen Sie eine Funktion auf der Webseite, oder ist Ihnen ein Fehler aufgefallen? Dann helfen Sie beim Entwickeln der Webseite in Ruby on Rails!</p>
<p><a class="btn btn-default disabled" href="#" role="button">Zum Kontaktformular &raquo;</a></p> <p><a class="btn btn-default" href="https://github.com/pfischbeck/projekteuler" target="_blank" role="button">Projekt Euler auf GitHub &raquo;</a></p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -6,7 +6,8 @@
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th><%= Translation.human_attribute_name(:id) %></th> <th><%= Translation.human_attribute_name(:created_at) %></th>
<th><%= Translation.human_attribute_name(:problem_id) %></th>
<th><%= Translation.human_attribute_name(:title) %></th> <th><%= Translation.human_attribute_name(:title) %></th>
</tr> </tr>
</thead> </thead>
@ -14,7 +15,8 @@
<tbody> <tbody>
<% @translations.each do |translation| %> <% @translations.each do |translation| %>
<tr> <tr>
<td><%= translation.id %></td> <td><div data-toggle="tooltip" data-placement="left" title="<%= l translation.created_at %>"><%= time_ago_in_words(translation.created_at) %></div></td>
<td><%= translation.problem_id %></td>
<td><%= link_to translation.title, [:admin, translation] %></td> <td><%= link_to translation.title, [:admin, translation] %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -4,6 +4,20 @@
<h1><%= @translation.title %> <small><%= t 'problems.show.problem_subtitle', id: @translation.problem_id %></small></h1> <h1><%= @translation.title %> <small><%= t 'problems.show.problem_subtitle', id: @translation.problem_id %></small></h1>
</div> </div>
<% if @translation.problem.is_translated? %>
<div class="alert alert-warning" role="alert"><%= t('.already_translated') %> <%= link_to t('.visit_current_translation'), @translation.problem, target: '_blank', class: 'alert-link' %></div>
<% else %>
<div class="alert alert-info" role="alert"><%= t('.is_new_translation') %></div>
<% end %>
<% if @translation.pending? %>
<%= link_to admin_translation_decline_path(@translation), method: :post, class: 'btn btn-default btn-sm pull-right' do %>
<%= icon :remove %> <%= t '.decline_translation' %>
<% end %>
<%= link_to admin_translation_accept_path(@translation), method: :post, class: 'btn btn-default btn-sm pull-right' do %>
<%= icon :ok %> <%= t '.accept_translation' %>
<% end %>
<% end %>
<%= panel do %> <%= panel do %>
<div class="panel-body problem-content"> <div class="panel-body problem-content">
<%= sanitize @translation.content %> <%= sanitize @translation.content %>

View File

@ -16,19 +16,19 @@
"HTML-CSS": { availableFonts: ["TeX"] } "HTML-CSS": { availableFonts: ["TeX"] }
}); });
</script> </script>
<%= mathjax_tag config: 'TeX-AMS_HTML' %> <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML' async></script>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body> <body>
<%= render 'layouts/header' %> <main role="main">
<div class="container"> <%= render 'layouts/header' %>
<%= flash_messages %> <div class="container">
<div class="row"> <%= flash_messages %>
<div class="col-md-12" role="main"> <div class="row">
<%= yield %> <%= yield %>
</div> </div>
</div> </div>
</div> </main>
<%= render 'layouts/footer' %> <%= render 'layouts/footer' %>
</body> </body>

View File

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

View File

@ -1,10 +1,9 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
require 'pathname'
require 'fileutils' require 'fileutils'
include FileUtils include FileUtils
# path to your application root. # path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) APP_ROOT = File.expand_path('..', __dir__)
def system!(*args) def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==") system(*args) || abort("\n== Command #{args} failed ==")
@ -21,7 +20,6 @@ chdir APP_ROOT do
# Install JavaScript dependencies if using Yarn # Install JavaScript dependencies if using Yarn
# system('bin/yarn') # system('bin/yarn')
# puts "\n== Copying sample files ==" # puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml') # unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml' # cp 'config/database.yml.sample', 'config/database.yml'

View File

@ -1,10 +1,9 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
require 'pathname'
require 'fileutils' require 'fileutils'
include FileUtils include FileUtils
# path to your application root. # path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) APP_ROOT = File.expand_path('..', __dir__)
def system!(*args) def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==") system(*args) || abort("\n== Command #{args} failed ==")
@ -18,6 +17,9 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative' system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install') system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
puts "\n== Updating database ==" puts "\n== Updating database =="
system! 'bin/rails db:migrate' system! 'bin/rails db:migrate'

View File

@ -1,8 +1,8 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
VENDOR_PATH = File.expand_path('..', __dir__) APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do Dir.chdir(APP_ROOT) do
begin begin
exec "yarnpkg #{ARGV.join(" ")}" exec "yarnpkg", *ARGV
rescue Errno::ENOENT rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system." $stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"

View File

@ -9,11 +9,12 @@ Bundler.require(*Rails.groups)
module Projekteuler module Projekteuler
class Application < Rails::Application class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version. # Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1 config.load_defaults 5.2
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.

View File

@ -1,3 +1,4 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.

View File

@ -6,5 +6,5 @@ test:
production: production:
adapter: redis adapter: redis
url: redis://localhost:6379/1 url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: projekteuler_production channel_prefix: projekteuler_production

View File

@ -13,12 +13,13 @@ Rails.application.configure do
config.consider_all_requests_local = true config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled. # Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist? # Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
config.cache_store = :memory_store config.cache_store = :memory_store
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" 'Cache-Control' => "public, max-age=#{2.days.to_i}"
} }
else else
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
@ -26,6 +27,9 @@ Rails.application.configure do
config.cache_store = :null_store config.cache_store = :null_store
end end
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Don't care if the mailer can't send. # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
@ -37,6 +41,9 @@ Rails.application.configure do
# Raise an error on page load if there are pending migrations. # 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
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Debug mode disables concatenation and preprocessing of assets. # Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large # This option may cause significant delays in view rendering with a large
# number of complex assets. # number of complex assets.

View File

@ -14,10 +14,9 @@ Rails.application.configure do
config.consider_all_requests_local = false config.consider_all_requests_local = false
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
# Attempt to read encrypted secrets from `config/secrets.yml.enc`. # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# `config/secrets.yml.key`. config.require_master_key = true
config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since # Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this. # Apache or NGINX already handles this.
@ -30,8 +29,6 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed. # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false config.assets.compile = false
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server. # Enable serving of images, stylesheets, and JavaScripts from an asset server.
@ -41,6 +38,9 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Mount Action Cable outside main process or domain # Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil # config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable' # config.action_cable.url = 'wss://example.com/cable'
@ -62,6 +62,7 @@ Rails.application.configure do
# Use a real queuing backend for Active Job (and separate queues per environment) # Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "projekteuler_#{Rails.env}" # config.active_job.queue_name_prefix = "projekteuler_#{Rails.env}"
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors. # Ignore bad email addresses and do not raise email delivery errors.

View File

@ -15,7 +15,7 @@ Rails.application.configure do
# Configure public file server for tests with Cache-Control for performance. # Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true config.public_file_server.enabled = true
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
} }
# Show full error reports and disable caching. # Show full error reports and disable caching.
@ -27,6 +27,10 @@ Rails.application.configure do
# Disable request forgery protection in test environment. # Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = false
# Store uploaded files on the local file system in a temporary directory
config.active_storage.service = :test
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world. # Tell Action Mailer not to deliver emails to the real world.

View File

@ -0,0 +1,25 @@
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
# Rails.application.config.content_security_policy do |policy|
# policy.default_src :self, :https
# policy.font_src :self, :https, :data
# policy.img_src :self, :https, :data
# policy.object_src :none
# policy.script_src :self, :https
# policy.style_src :self, :https
# # Specify URI for violation reports
# # policy.report_uri "/csp-violation-report-endpoint"
# end
# If you are using UJS then enable automatic nonce generation
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
# Report CSP violations to a specified URI
# For further information see the following documentation:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
# Rails.application.config.content_security_policy_report_only = true

View File

@ -9,4 +9,16 @@ de:
update_problem_count: update_problem_count:
success_message: "Problem-Anzahl wurde erfolgreich aktualisiert!" success_message: "Problem-Anzahl wurde erfolgreich aktualisiert!"
failure_message: "Problem-Anzahl konnte nicht aktualisiert werden! Grund: %{error}" failure_message: "Problem-Anzahl konnte nicht aktualisiert werden! Grund: %{error}"
no_problem_count: "Keine Problem-Anzahl gegeben!" no_problem_count: "Keine Problem-Anzahl gegeben!"
translations:
must_be_pending: "Übersetzung muss ausstehend sein, um akzeptiert oder abgelehnt zu werden!"
show:
accept_translation: "Akzeptieren"
decline_translation: "Ablehnen"
visit_current_translation: "Aktuelle Übersetzung anschauen"
already_translated: "Dieses Problem wurde bereits übersetzt."
is_new_translation: "Dieses Problem hat bisher keine Übersetzung."
accept:
success_message: "Übersetzung wurde erfolgreich akzeptiert!"
decline:
success_message: "Übersetzung wurde erfolgreich abgelehnt!"

View File

@ -1,6 +1,9 @@
# ruby encoding: utf-8 # ruby encoding: utf-8
de: de:
attributes:
created_at: Erstellt
updated_at: Aktualisiert
application: application:
site_title: "Projekt Euler" site_title: "Projekt Euler"
sign_in: 'Einloggen' sign_in: 'Einloggen'
@ -8,4 +11,8 @@ de:
info: "Info" info: "Info"
legal: "Impressum" legal: "Impressum"
copyright: "Copyright-Informationen" copyright: "Copyright-Informationen"
bootstrap_html: 'Entworfen mit <a href="http://getbootstrap.com/">Bootstrap</a>' bootstrap_html: 'Entworfen mit <a href="http://getbootstrap.com/">Bootstrap</a>'
helpers:
submit:
translation:
create: "%{model} vorschlagen"

View File

@ -9,4 +9,4 @@ de:
new: new:
new_translation: Neue Übersetzung für Problem %{id} new_translation: Neue Übersetzung für Problem %{id}
notice: notice:
successfully_created: Übersetzung wurde erfolgreich erstellt. successfully_created: Der Übersetzungsvorschlag wurde eingereicht. Ein Organisator wird sich Ihren Vorschlag so bald wie möglich anschauen.

View File

@ -1,4 +1,12 @@
Rails.application.routes.draw do Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'about#index'
get 'about/index' get 'about/index'
get 'about/info' get 'about/info'
get 'about/copyright' get 'about/copyright'
@ -18,64 +26,10 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
get '', to: 'dashboard#index', as: 'dashboard_index' get '', to: 'dashboard#index', as: 'dashboard_index'
post '/update_problem_count', to: 'dashboard#update_problem_count', as: 'dashboard_update_problem_count' post '/update_problem_count', to: 'dashboard#update_problem_count', as: 'dashboard_update_problem_count'
resources :translations, only: [:index, :show] resources :translations, only: [:index] do
get '', to: 'translations#show', as: ''
post 'accept', to: 'translations#accept'
post 'decline', to: 'translations#decline'
end
end end
end
mathjax 'mathjax'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'about#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

34
config/storage.yml Normal file
View File

@ -0,0 +1,34 @@
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket
# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]

View File

@ -0,0 +1,15 @@
class AddStatusToTranslations < ActiveRecord::Migration[5.2]
def change
add_column :translations, :status, :integer, default: 0
reversible do |dir|
dir.up do
Problem.all.each do |problem|
if problem.is_translated?
problem.translation.in_use!
end
end
end
end
end
end

View File

@ -1,4 +1,3 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead # 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 # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
@ -11,42 +10,40 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150131103802) do ActiveRecord::Schema.define(version: 2019_02_02_113250) do
create_table "admins", force: :cascade do |t| create_table "admins", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["email"], name: "index_admins_on_email", unique: true
t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
end end
add_index "admins", ["email"], name: "index_admins_on_email", unique: true
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
create_table "problems", force: :cascade do |t| create_table "problems", force: :cascade do |t|
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "translation_id" t.integer "translation_id"
t.index ["translation_id"], name: "index_problems_on_translation_id"
end end
add_index "problems", ["translation_id"], name: "index_problems_on_translation_id"
create_table "translations", force: :cascade do |t| create_table "translations", force: :cascade do |t|
t.string "title" t.string "title"
t.text "content" t.text "content"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "problem_id" t.integer "problem_id"
t.integer "status", default: 0
t.index ["problem_id"], name: "index_translations_on_problem_id"
end end
add_index "translations", ["problem_id"], name: "index_translations_on_problem_id"
end end

View File

@ -27,7 +27,7 @@ for i in 1..10 do
) )
problem = Problem.find(i) problem = Problem.find(i)
problem.translation = translation problem.set_translation(translation)
problem.save! problem.save!
end end

View File

@ -6,6 +6,7 @@ class Admin::TranslationsControllerTest < ActionDispatch::IntegrationTest
setup do setup do
login login
@translation = translations(:translation_one) @translation = translations(:translation_one)
@translation_alternative = translations(:translation_two_alternative)
end end
test "should get index" do test "should get index" do
get admin_translations_url get admin_translations_url
@ -14,8 +15,19 @@ class Admin::TranslationsControllerTest < ActionDispatch::IntegrationTest
end end
test "should show translation" do test "should show translation" do
get admin_translation_url(id: @translation) get admin_translation_url(translation_id: @translation)
assert_response :success assert_response :success
end end
test "should accept translation" do
post admin_translation_accept_path(@translation_alternative)
assert_redirected_to problem_path(2)
assert_equal @translation_alternative, Problem.find(2).translation
end
test "should decline translation" do
post admin_translation_decline_path(@translation_alternative)
assert_redirected_to admin_translations_path
assert Translation.find(@translation_alternative.id).declined?
end
end end

View File

@ -4,8 +4,16 @@ translation_one:
problem_id: 1 problem_id: 1
title: First title title: First title
content: The content of the translation content: The content of the translation
status: 1
translation_two: translation_two:
problem_id: 2 problem_id: 2
title: Second title title: Second title
content: The content of the second translation content: The content of the second translation
status: 1
translation_two_alternative:
problem_id: 2
title: Second title
content: The changed content for the second problem
status: 0

View File

@ -14,6 +14,13 @@ class ProblemTest < ActiveSupport::TestCase
assert problems(:one).is_translated? assert problems(:one).is_translated?
end end
test "set_translation should modify status correctly" do
problems(:two).set_translation(translations(:translation_two_alternative))
assert translations(:translation_two).outdated?
assert translations(:translation_two_alternative).in_use?
assert_equal translations(:translation_two_alternative), problems(:two).translation
end
test "should have correct original url" do test "should have correct original url" do
assert_equal "https://projecteuler.net/problem=1", problems(:one).original_url assert_equal "https://projecteuler.net/problem=1", problems(:one).original_url
end end

View File

@ -36,5 +36,6 @@ class TranslationTest < ActiveSupport::TestCase
problem_id: 1 problem_id: 1
) )
assert translation.save assert translation.save
assert translation.pending?
end end
end end