This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
include AASM | |
aasm do | |
state :newone, initial: true | |
state :activated | |
state :blocked | |
state :deleted | |
event :activate do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const usersCreate = data => (dispatch) => { | |
dispatch(usersCreateStart()); | |
postUser(data) | |
.then( | |
(res) => { | |
dispatch(usersCreateSuccess()); | |
dispatch(push(`/admin/users/${res.user.id}`)); | |
dispatch(showSuccess('user_create')); | |
}, | |
(err) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Формула по умолчанию | |
ОКРУГЛИТЬ(СРЕДНЕЕ_ЗНАЧЕНИЕ(все_оценки)) | |
# У оценок можно поставить тег. Т.е. может быть стандартная оценка, а может быть экамен, экскурсия и т.д. | |
# Отдельно считаем все оценки по журналу, отдельно по экзамену и равнозначно их высчитываем, округляем в ближайщую сторону | |
ОКРУГЛИТЬ((СРЕДНЕЕ_ЗНАЧЕНИЕ(обычная_оценка) + СРЕДНЕЕ_ЗНАЧЕНИЕ(экзамен)) / 2 ) | |
# есть разные типы оценок (5-бальная, 100-бальная, зачет/незачет и т.д.), могут встречаться прямо в одном журнале, в одном уроке и даже в одной ячейке при комбинированных оценках. 5/79 (на одном уроке 5 за диктант, 79 за тест по грамматике). | |
# Тут мы берем в расчет только оценки пятибальные, игнорируем все остальные | |
ОКРУГЛИТЬ(СРЕДНЕЕ_ЗНАЧЕНИЕ(ВЫБРАТЬ_ПЯТИБАЛЬНЫЕ(все_оценки))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DestroyUser | |
include Dry::Transaction | |
include Dry::Transaction(container: Containers::RecordOperations) | |
step :find, with: 'operations.find' | |
step :destroy, with: 'operations.destroy' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# SPECS | |
# | |
it 'validates presence of iin' do | |
form.validate(iin: '') | |
expect(form.errors[:iin]).to include('must be filled') | |
end | |
it 'validates length of iin to be 12' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Form from 'admin/components/Form' | |
class StudyGroupForm extends React.Component { | |
render() { | |
const schema = { | |
name: 'StudyGroup', | |
fields: [ | |
{ name: 'level', placeholder: '1', required: true }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BulkPeriodValidator(array_of_periods) | |
@array_of_periods = array_of_periods | |
def valid? | |
values = value.map { |elem| [elem.endless, elem.trial] } | |
values.size == values.uniq.size | |
end | |
end | |
period_validator = BulkPeriodValidator.new(your_array_of_periods) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry-validation' | |
class BulkPeriodValidator(array_of_periods) | |
@array_of_periods = array_of_periods | |
@schema = Dry::Validation.Schema do | |
key(:array).required(:array?, :unique_by_endless_and_trial?) | |
configure do | |
# http://dry-rb.org/gems/dry-validation/error-messages/ | |
def self.messages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe '#fetch_from_kinopoisk(kinopoisk_id)' do | |
context 'when movie with such kinopoisk_id exist' do | |
it 'updates movie with fresh data' do | |
stub_kinopoisk_get_film(1) | |
movie = create(:movie, kinopoisk_id: 1) | |
Movie.fetch_from_kinopoisk(movie.kinopoisk_id) | |
expect(Movie.find(movie.id).title_en).to eq('Star Wars: Episode VII - The Force Awakens') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def apply_on_set(arr, set_size, &block) | |
arr.each_cons(set_size).map { |set| yield(set) } | |
end | |
apply_on_set([1, 2, 3, 4], 2) { |set| set.reduce(:+) } #=> [3, 4, 7] | |
apply_on_set([1, 2, 3, 4], 3) { |set| set.reduce(:+) } #=> [6, 9] | |
apply_on_set([1, 2, 3, 4], 2) { |set| set.map(&:to_f) } #=> [[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]] |