source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | chikamichi/amb | https://github.com/chikamichi/amb | examples/02_multiple_constraints.rb | Ruby | mit | 46 | master | 511 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.expand_path("../_shared.rb", __FILE__)
# a valid solution exists (first-match: x=3, y=2)
@amb = Ambiguous.new
x = @amb.choose(1,2,3,4)
y = @amb.choose(1,2,3,4)
@amb.assert x + y == 5
@amb.assert x - y == 1
puts "x = #{x}, y = #{y}"
# no ... |
github | chikamichi/amb | https://github.com/chikamichi/amb | examples/04_kalotan.rb | Ruby | mit | 46 | master | 3,209 | # Copyright 2006 by Jim Weirich
#
# The Kalotans are a tribe with a peculiar quirk. Their males always
# tell the truth. Their females never make two consecutive true
# statements, or two consecutive untrue statements.
#
# An anthropologist (let's call him Worf) has begun to study
# them. Worf does not yet know the Kal... |
github | chikamichi/amb | https://github.com/chikamichi/amb | examples/03_magic_square.rb | Ruby | mit | 46 | master | 2,854 | # Ruby Quiz # 70 -- Constraint Solving
# Copyright 2006 by Jim Weirich
#
# Again, using Amb to solve the magic square constraint problem. The
# key to getting this to run half-way efficiently is to do the
# assertions as soon as possible, before additional choices have been
# made. This minimizes the amount of backtrac... |
github | chikamichi/amb | https://github.com/chikamichi/amb | examples/01_simple_constraints.rb | Ruby | mit | 46 | master | 606 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.expand_path("../_shared.rb", __FILE__)
class Ambiguous
include Amb
end
# Constraint as an argument
@amb = Ambiguous.new
x = @amb.choose(1,2,3,4)
@amb.assert((x % 2) == 0)
puts x # 2
# Constraint with no valid execution path => raise
@... |
github | chikamichi/amb | https://github.com/chikamichi/amb | examples/05_crooks.rb | Ruby | mit | 46 | master | 4,576 | # Copyright 2006 by Jim Weirich
#
# Two thieves have being working together for years. Nobody knows their
# identities, but one is known to be a Liar and the other a Knave. The
# local sheriff gets a tip that the bandits are about to commit another
# crime. When the sheriff arrives at the scene of the crime, he finds
#... |
github | chikamichi/amb | https://github.com/chikamichi/amb | spec/amb_spec.rb | Ruby | mit | 46 | master | 1,764 | require 'minitest/autorun'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.expand_path("../../lib/amb.rb", __FILE__)
class Ambiguous
include Amb
end
class TestAmb < MiniTest::Unit::TestCase
def setup
@amb = Ambiguous.new
end
def test_public_api
assert_respond_to Amb, ... |
github | chikamichi/amb | https://github.com/chikamichi/amb | lib/amb/amb_operator.rb | Ruby | mit | 46 | master | 2,041 | # By Eric Kidd.
# See http://www.randomhacks.net/articles/2005/10/11/amb-operator.
module Amb
# Use the ambiguous computation pattern as a stand-alone operator.
module Operator
require 'continuation'
# A list of places we can "rewind" to if we encounter amb with no arguments.
$backtrack_points = []
... |
github | chikamichi/amb | https://github.com/chikamichi/amb | lib/amb/amb.rb | Ruby | mit | 46 | master | 4,926 | # Copyright 2006 by Jim Weirich <jim@weirichhouse.org>. All rights reserved.
# Permission is granted for use, modification and distribution as
# long as the above copyright notice is included.
# Modified by Jean-Denis Vauguet <jd@vauguet.fr> for Amb gem release.
# Amb is an ambiguous choice maker. You can ask an Amb o... |
github | viode/viode | https://github.com/viode/viode | Guardfile | Ruby | bsd-2-clause | 46 | master | 1,649 | # frozen_string_literal: true
notification :tmux,
display_message: true,
timeout: 10,
default_message_format: '%s >> %s',
line_separator: ' > ',
color_location: 'status-left-bg'
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%... |
github | viode/viode | https://github.com/viode/viode | Gemfile | Ruby | bsd-2-clause | 46 | master | 1,200 | # frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '>= 2.3.0', '< 2.6.0'
gem 'rails', '~> 5.2.0'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.7'
gem 'devise'
gem 'pundit'
gem 'kaminari'
gem 'stringex'
gem 'slim-rails'
gem 'carrierwave'... |
github | viode/viode | https://github.com/viode/viode | spec/rails_helper.rb | Ruby | bsd-2-clause | 46 | master | 905 | # frozen_string_literal: true
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema... |
github | viode/viode | https://github.com/viode/viode | spec/spec_helper.rb | Ruby | bsd-2-clause | 46 | master | 449 | # frozen_string_literal: true
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.color = true
config.order = :random
... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/questions_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 4,482 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe QuestionsController, type: :controller do
let(:user) { Fabricate :confirmed_user }
let(:category) { Fabricate :category }
let(:question) { Fabricate :question, author: user }
describe 'GET #index' do
it 'returns http success' do
... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/tags_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 404 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe TagsController, type: :controller do
let(:user) { Fabricate :confirmed_user }
let(:question) { Fabricate :question, author: user }
describe 'GET #show' do
it 'returns http success' do
tag = question.tags.sample
get :show, p... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/users_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 672 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe UsersController, type: :controller do
let(:user) { Fabricate :confirmed_user }
describe 'GET #show' do
it 'returns http success' do
get :show, params: { username: user.username }
expect(response).to be_successful
end
end
... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/categories_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 2,197 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe CategoriesController, type: :controller do
let(:category) { Fabricate :category }
let(:user) { Fabricate :confirmed_user }
describe 'GET #index' do
it 'returns http success' do
get :index
expect(response).to be_successful
... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/search_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 475 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe SearchController, type: :controller do
describe 'GET #index' do
context 'without query params' do
it 'returns http success' do
get :index
expect(response).to be_successful
end
end
context 'with query params'... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/answers_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 2,826 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnswersController, type: :controller do
let(:user) { Fabricate :confirmed_user }
let(:question) { Fabricate :question, author: user }
let(:answer) { Fabricate :answer, question: question, author: user }
describe 'GET #new' do
conte... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/settings/accounts_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 1,259 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Settings::AccountsController, type: :controller do
let(:user) { Fabricate :confirmed_user }
describe 'GET #show' do
context 'when not signed in' do
it 'redirects to sign in page' do
get :show
expect(response).to redirec... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/settings/profiles_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 1,156 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Settings::ProfilesController, type: :controller do
let(:user) { Fabricate :confirmed_user }
describe 'GET #show' do
context 'when not signed in' do
it 'redirects to sign in page' do
get :show
expect(response).to redirec... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/settings/passwords_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 1,293 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Settings::PasswordsController, type: :controller do
let(:user) { Fabricate :confirmed_user }
describe 'GET #show' do
context 'when not signed in' do
it 'redirects to sign in page' do
get :show
expect(response).to redire... |
github | viode/viode | https://github.com/viode/viode | spec/controllers/admin/dashboard_controller_spec.rb | Ruby | bsd-2-clause | 46 | master | 794 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::DashboardController, type: :controller do
let(:user) { Fabricate :confirmed_user }
describe 'GET #show' do
context 'when not signed in' do
it 'redirects to sign in page' do
get :show
expect(response).to redirect_... |
github | viode/viode | https://github.com/viode/viode | spec/fabricators/question_fabricator.rb | Ruby | bsd-2-clause | 46 | master | 372 | # frozen_string_literal: true
Fabricator(:question) do
author
category
title { Faker::Lorem.sentence.tr('.', '?') }
body { Faker::Lorem.paragraph(2) }
views { rand(0..20) }
tag_list { Faker::Lorem.words.join(',') }
permalink { Faker::Lorem.word }
anonymous false
end
Fabricator(:anonymous... |
github | viode/viode | https://github.com/viode/viode | spec/fabricators/answer_fabricator.rb | Ruby | bsd-2-clause | 46 | master | 203 | # frozen_string_literal: true
Fabricator(:answer) do
author
question
body { Faker::Lorem.paragraph(5) }
anonymous false
end
Fabricator(:anonymous_answer, from: :answer) do
anonymous true
end |
github | viode/viode | https://github.com/viode/viode | spec/fabricators/user_fabricator.rb | Ruby | bsd-2-clause | 46 | master | 545 | # frozen_string_literal: true
Fabricator(:user, aliases: %i[author subscriber]) do
fullname { Faker::Name.name }
bio { Faker::Job.title }
email { Faker::Internet.safe_email }
username { Faker::Internet.user_name(3..20).tr('.-', '_') }
password 'mysecret'
avatar { File.open('spec/fixtures/250.gif'... |
github | viode/viode | https://github.com/viode/viode | spec/helpers/questions_helper_spec.rb | Ruby | bsd-2-clause | 46 | master | 4,815 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe QuestionsHelper, type: :helper do
let(:user) { Fabricate :confirmed_user }
let(:question) { Fabricate :question, author: user, id: 777 }
let(:anonymous_question) { Fabricate :anonymous_question, author: user }
describe '#link_to_question... |
github | viode/viode | https://github.com/viode/viode | spec/helpers/answers_helper_spec.rb | Ruby | bsd-2-clause | 46 | master | 3,475 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnswersHelper, type: :helper do
let(:user) { Fabricate :confirmed_user }
let(:answer) { Fabricate :answer, author: user, id: 777 }
let(:anonymous_answer) { Fabricate :anonymous_answer, author: user }
describe '#link_to_answer_upvote' do
... |
github | viode/viode | https://github.com/viode/viode | spec/system/question_closed_spec.rb | Ruby | bsd-2-clause | 46 | master | 858 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Question closed', type: :system do
let(:user) { Fabricate :confirmed_user }
let(:question) { Fabricate :question, author: user }
scenario 'A question that is not closed' do
visit new_user_session_path
fill_in 'Login', with: user... |
github | viode/viode | https://github.com/viode/viode | spec/system/user_auth_spec.rb | Ruby | bsd-2-clause | 46 | master | 932 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'User Auth', type: :system do
let(:user) { Fabricate :confirmed_user }
scenario 'User sign up' do
visit new_user_registration_path
expect(current_path).to eq '/register'
fill_in 'Username', with: 'user'
fill_in 'Email', with: 'u... |
github | viode/viode | https://github.com/viode/viode | spec/models/subscription_spec.rb | Ruby | bsd-2-clause | 46 | master | 255 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Subscription, type: :model do
describe 'relations' do
it { is_expected.to belong_to(:subscriber).class_name('User') }
it { is_expected.to belong_to(:subscribable) }
end
end |
github | viode/viode | https://github.com/viode/viode | spec/models/question_spec.rb | Ruby | bsd-2-clause | 46 | master | 3,660 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Question, type: :model do
let(:user) { Fabricate :confirmed_user }
let(:question) { Fabricate :question, author: user }
describe 'relations' do
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to belong_... |
github | viode/viode | https://github.com/viode/viode | spec/models/answer_spec.rb | Ruby | bsd-2-clause | 46 | master | 2,678 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Answer, type: :model do
let(:user) { Fabricate :confirmed_user }
let!(:question) { Fabricate :question, closed: false }
let(:answer) { Fabricate :answer, author: user, question: question }
describe 'relations' do
it { is_ex... |
github | viode/viode | https://github.com/viode/viode | spec/models/category_spec.rb | Ruby | bsd-2-clause | 46 | master | 701 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe Category, type: :model do
let(:user) { Fabricate :confirmed_user }
describe 'relations' do
it { is_expected.to have_many(:questions).dependent(:destroy) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:name)... |
github | viode/viode | https://github.com/viode/viode | spec/models/user_spec.rb | Ruby | bsd-2-clause | 46 | master | 2,883 | # frozen_string_literal: true
require 'rails_helper'
RSpec.describe User, type: :model do
let(:user) { Fabricate :confirmed_user }
let(:category) { Fabricate :category }
let(:question) { Fabricate :question, author: user }
describe 'relations' do
it {
is_expected.to have_many(:answers).conditio... |
github | viode/viode | https://github.com/viode/viode | config/schedule.rb | Ruby | bsd-2-clause | 46 | master | 576 | # frozen_string_literal: true
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
# command "/usr/bin/some_great_comm... |
github | viode/viode | https://github.com/viode/viode | config/application.rb | Ruby | bsd-2-clause | 46 | master | 1,167 | # frozen_string_literal: true
require_relative 'boot'
require 'rails'
# Pick the frameworks you want:
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
# require "active_storage/engine"
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/r... |
github | viode/viode | https://github.com/viode/viode | config/routes.rb | Ruby | bsd-2-clause | 46 | master | 1,746 | # frozen_string_literal: true
Rails.application.routes.draw do
root 'questions#index'
devise_for :users, skip: %i[sessions registrations]
devise_scope :user do
get 'login' => 'devise/sessions#new', as: :new_user_session
post 'login' => 'devise/sessions#create', as: :user_session
delete... |
github | viode/viode | https://github.com/viode/viode | config/puma.rb | Ruby | bsd-2-clause | 46 | master | 2,333 | # frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for mini... |
github | viode/viode | https://github.com/viode/viode | config/initializers/devise.rb | Ruby | bsd-2-clause | 46 | master | 13,606 | # Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmat... |
github | viode/viode | https://github.com/viode/viode | config/environments/development.rb | Ruby | bsd-2-clause | 46 | master | 2,213 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don... |
github | viode/viode | https://github.com/viode/viode | config/environments/production.rb | Ruby | bsd-2-clause | 46 | master | 3,586 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, a... |
github | viode/viode | https://github.com/viode/viode | config/environments/test.rb | Ruby | bsd-2-clause | 46 | master | 1,870 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "s... |
github | viode/viode | https://github.com/viode/viode | app/uploaders/avatar_uploader.rb | Ruby | bsd-2-clause | 46 | master | 1,379 | # frozen_string_literal: true
require 'carrierwave/processing/mini_magick'
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
MiniMagick.processor = :gm if ViodeSettings.image_processor == 'GraphicsMagick'
storage :file
def store_dir
"uploads/#{model.class.to_s.underscor... |
github | viode/viode | https://github.com/viode/viode | app/helpers/categories_helper.rb | Ruby | bsd-2-clause | 46 | master | 517 | # frozen_string_literal: true
module CategoriesHelper
def link_to_category_subscription(category)
return link_to('subscribe', new_user_session_path) unless user_signed_in?
if current_user.subscribed_to? category
title = 'unsubscribe'
path = unsubscribe_category_path(category)
else
titl... |
github | viode/viode | https://github.com/viode/viode | app/helpers/questions_helper.rb | Ruby | bsd-2-clause | 46 | master | 1,929 | # frozen_string_literal: true
module QuestionsHelper
def link_to_question_star(question)
return '' unless user_signed_in?
if question.starred_by?(current_user)
icon_klass = 'fa-star'
title = 'Unstar this question'
else
icon_klass = 'fa-star-o'
title = 'Star this question'
end... |
github | viode/viode | https://github.com/viode/viode | app/helpers/answers_helper.rb | Ruby | bsd-2-clause | 46 | master | 1,430 | # frozen_string_literal: true
module AnswersHelper
def link_to_answer_upvote(answer)
if user_signed_in?
klass = answer.upvoted_by?(current_user) ? 'active' : ''
link_to upvote_answer_path(answer), method: :post, remote: true,
class: "#{klass} js-answer-upvot... |
github | viode/viode | https://github.com/viode/viode | app/helpers/application_helper.rb | Ruby | bsd-2-clause | 46 | master | 1,195 | # frozen_string_literal: true
module ApplicationHelper
def flash_class(type)
case type
when 'alert' then 'alert-warning'
when 'error' then 'alert-danger'
when 'notice' then 'alert-info'
when 'success' then 'alert-success'
else type
end
end
def author_avatar(post)
if post.author.a... |
github | viode/viode | https://github.com/viode/viode | app/controllers/search_controller.rb | Ruby | bsd-2-clause | 46 | master | 450 | # frozen_string_literal: true
class SearchController < ApplicationController
def index
if params[:query] && params[:query].size > 1
tags = ActsAsTaggableOn::Tag.arel_table
@tags = ActsAsTaggableOn::Tag.where tags[:name].matches("%#{params[:query]}%")
@questions = Question.search(params[:query])... |
github | viode/viode | https://github.com/viode/viode | app/controllers/application_controller.rb | Ruby | bsd-2-clause | 46 | master | 612 | # frozen_string_literal: true
class ApplicationController < ActionController::Base
include Pundit
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: %i... |
github | viode/viode | https://github.com/viode/viode | app/controllers/answers_controller.rb | Ruby | bsd-2-clause | 46 | master | 996 | # frozen_string_literal: true
class AnswersController < ApplicationController
before_action :authenticate_user!
before_action :find_answer, only: %i[upvote downvote]
def new
@answer = Answer.new
set_answer_question
end
def create
@answer = current_user.answers.new(answer_params)
set_answer_... |
github | viode/viode | https://github.com/viode/viode | app/controllers/tags_controller.rb | Ruby | bsd-2-clause | 46 | master | 243 | # frozen_string_literal: true
class TagsController < ApplicationController
def show
@tag = ActsAsTaggableOn::Tag.find_by! name: params[:name]
@questions = Question.tagged_with(@tag.name).recent.page(params[:page]).per(20)
end
end |
github | viode/viode | https://github.com/viode/viode | app/controllers/questions_controller.rb | Ruby | bsd-2-clause | 46 | master | 1,625 | # frozen_string_literal: true
class QuestionsController < ApplicationController
before_action :authenticate_user!, only: %i[new create upvote downvote star]
before_action :find_question, only: %i[show upvote downvote star]
def index
@top_categories = Category.popular.limit(5)
@labels = ActsAsTaggableOn:... |
github | viode/viode | https://github.com/viode/viode | app/controllers/users_controller.rb | Ruby | bsd-2-clause | 46 | master | 389 | # frozen_string_literal: true
class UsersController < ApplicationController
before_action :find_user
def show; end
def answers
@answers = @user.answers.recent.page(params[:page]).per(20)
end
def questions
@questions = @user.questions.recent.page(params[:page]).per(20)
end
private
def find_... |
github | viode/viode | https://github.com/viode/viode | app/controllers/categories_controller.rb | Ruby | bsd-2-clause | 46 | master | 827 | # frozen_string_literal: true
class CategoriesController < ApplicationController
before_action :authenticate_user!, only: %i[subscribe unsubscribe]
before_action :find_category, only: %i[show subscribe unsubscribe]
def index
@categories = Category.order(:name)
end
def show
@questions = @category.qu... |
github | viode/viode | https://github.com/viode/viode | app/controllers/admin/base_controller.rb | Ruby | bsd-2-clause | 46 | master | 268 | # frozen_string_literal: true
module Admin
class BaseController < ApplicationController
before_action :authenticate_user!, :check_admin_rights
private
def check_admin_rights
render status: :not_found unless current_user.admin?
end
end
end |
github | viode/viode | https://github.com/viode/viode | app/controllers/settings/passwords_controller.rb | Ruby | bsd-2-clause | 46 | master | 729 | # frozen_string_literal: true
module Settings
class PasswordsController < ApplicationController
before_action :authenticate_user!
def show; end
def update
# TODO: validate password confirmation
if current_user.valid_password? params[:user][:current_password]
if current_user.update(u... |
github | viode/viode | https://github.com/viode/viode | app/controllers/settings/profiles_controller.rb | Ruby | bsd-2-clause | 46 | master | 491 | # frozen_string_literal: true
module Settings
class ProfilesController < ApplicationController
before_action :authenticate_user!
def show; end
def update
if current_user.update(user_params)
flash[:success] = 'Settings successfully saved.'
redirect_to settings_profile_path
el... |
github | viode/viode | https://github.com/viode/viode | app/controllers/settings/accounts_controller.rb | Ruby | bsd-2-clause | 46 | master | 639 | # frozen_string_literal: true
module Settings
class AccountsController < ApplicationController
before_action :authenticate_user!
def show; end
def update
if current_user.valid_password? params[:user][:current_password]
if current_user.update(user_params)
flash[:success] = 'Setti... |
github | viode/viode | https://github.com/viode/viode | app/models/question.rb | Ruby | bsd-2-clause | 46 | master | 1,455 | # frozen_string_literal: true
class Question < ApplicationRecord
include Votable
acts_as_taggable
acts_as_url :title, url_attribute: :permalink
belongs_to :author, class_name: 'User'
belongs_to :category
has_many :answers, dependent: :destroy
has_reputation :stars, source: :user,
... |
github | viode/viode | https://github.com/viode/viode | app/models/answer.rb | Ruby | bsd-2-clause | 46 | master | 671 | # frozen_string_literal: true
class Answer < ApplicationRecord
include Votable
belongs_to :author, class_name: 'User'
belongs_to :question, counter_cache: true
has_reputation :votes, source: :user,
source_of: { reputation: :answer_points, of: :author }
validates :body, :question_i... |
github | viode/viode | https://github.com/viode/viode | app/models/user.rb | Ruby | bsd-2-clause | 46 | master | 2,535 | # frozen_string_literal: true
class User < ApplicationRecord
mount_uploader :avatar, AvatarUploader
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessor :login
enum role: %i[user admin moderator banned]
has_many :answers... |
github | viode/viode | https://github.com/viode/viode | app/models/category.rb | Ruby | bsd-2-clause | 46 | master | 427 | # frozen_string_literal: true
class Category < ApplicationRecord
acts_as_url :name, url_attribute: :permalink
has_many :questions, dependent: :destroy
has_many :subscriptions, as: :subscribable, dependent: :destroy
validates :name, presence: true
def self.popular
joins(:questions)
.group('catego... |
github | viode/viode | https://github.com/viode/viode | app/models/concerns/votable.rb | Ruby | bsd-2-clause | 46 | master | 578 | # frozen_string_literal: true
module Votable
extend ActiveSupport::Concern
UPVOTE_VALUE = ViodeSettings.votes.upvote_value
DOWNVOTE_VALUE = ViodeSettings.votes.downvote_value
def votes
reputation_for(:votes).to_i
end
def upvote_by(user)
add_or_update_evaluation(:votes, UPVOTE_VALUE, user)
en... |
github | viode/viode | https://github.com/viode/viode | db/seeds.rb | Ruby | bsd-2-clause | 46 | master | 596 | # frozen_string_literal: true
AvatarUploader.enable_processing = false
unless User.exists?(username: 'admin')
admin = Fabricate :admin
warn "\nCreated a user with credentials: #{admin.username}/#{admin.password}"
end
Fabricate.times(5, :confirmed_user)
Fabricate.times(36, :category)
Category.first(3).each do |c... |
github | viode/viode | https://github.com/viode/viode | db/schema.rb | Ruby | bsd-2-clause | 46 | master | 7,045 | # 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
# dat... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211531_change_evaluations_index_to_unique.rb | Ruby | bsd-2-clause | 46 | master | 1,282 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211528_add_reputations_index.rb | Ruby | bsd-2-clause | 46 | master | 923 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211533_change_reputations_index_to_unique.rb | Ruby | bsd-2-clause | 46 | master | 1,186 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211530_add_reputation_messages_index.rb | Ruby | bsd-2-clause | 46 | master | 950 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150318220607_create_questions.rb | Ruby | bsd-2-clause | 46 | master | 248 | class CreateQuestions < ActiveRecord::Migration
def change
create_table :questions do |t|
t.string :title
t.text :body
t.integer :user_id
t.timestamps null: false
end
add_index :questions, :user_id
end
end |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211532_change_reputation_messages_index_to_unique.rb | Ruby | bsd-2-clause | 46 | master | 1,234 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150319113144_create_answers.rb | Ruby | bsd-2-clause | 46 | master | 286 | class CreateAnswers < ActiveRecord::Migration
def change
create_table :answers do |t|
t.text :body
t.integer :user_id
t.integer :question_id
t.timestamps null: false
end
add_index :answers, :user_id
add_index :answers, :question_id
end
end |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150404104806_create_subscriptions.rb | Ruby | bsd-2-clause | 46 | master | 366 | class CreateSubscriptions < ActiveRecord::Migration
def change
create_table :subscriptions do |t|
t.integer :subscribable_id
t.string :subscribable_type
t.integer :subscriber_id
t.timestamps null: false
end
add_index :subscriptions, :subscriber_id
add_index :subscriptions, [:s... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20180503175447_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb | Ruby | bsd-2-clause | 46 | master | 1,083 | # This migration comes from acts_as_taggable_on_engine (originally 6)
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end
else
class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end
end
AddMissingIndexesOnTaggings.class_eval do
def... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150318204935_devise_create_users.rb | Ruby | bsd-2-clause | 46 | master | 1,334 | class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211529_add_evaluations_index.rb | Ruby | bsd-2-clause | 46 | master | 971 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | viode/viode | https://github.com/viode/viode | db/migrate/20150322211527_create_reputation_system.rb | Ruby | bsd-2-clause | 46 | master | 1,909 | ##
# Copyright 2012 Twitter, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in wri... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | Gemfile | Ruby | mit | 46 | master | 790 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.3"
gem "rails", "~> 7"
gem "active_hash"
gem "activerecord-postgis-adapter"
gem "geocoder"
gem "jbuilder"
gem "pg"
gem "puma"
gem "redis"
gem "sentry-raven"
gem "turbolinks", "~> 5"
gem "yamllint"
gem "importmap-... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | db/schema.rb | Ruby | mit | 46 | master | 1,620 | # 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.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | db/migrate/20190324164517_create_locations.rb | Ruby | mit | 46 | master | 258 | class CreateLocations < ActiveRecord::Migration[5.2]
def change
create_table :locations do |t|
t.string :address
t.references :organization, foreign_key: true
t.st_point :coords, geographic: true
t.timestamps
end
end
end |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | spec/rails_helper.rb | Ruby | mit | 46 | master | 1,963 | # This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rail... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | spec/controllers/locations_controller_spec.rb | Ruby | mit | 46 | master | 214 | require 'rails_helper'
RSpec.describe LocationsController do
describe "GET #index" do
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
end
end |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | spec/support/utensils.rb | Ruby | mit | 46 | master | 364 | # require 'utensils/capybara_extensions'
# require 'utensils/capybara_javascript'
# require 'utensils/capybara_screenshot'
require 'utensils/json'
# require 'utensils/database_cleaner'
# require 'utensils/email'
# require 'utensils/factory_bot'
# require 'utensils/omniauth'
# require 'utensils/timecop'
# require 'utens... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | spec/models/location_spec.rb | Ruby | mit | 46 | master | 409 | require 'rails_helper'
RSpec.describe Location, type: :model do
let(:location) { create(:location) }
describe "callbacks" do
it "adds entropy to coordinates to prevent collisions" do
allow(Geocoder).to receive(:search).and_return([double(coordinates: [1.123456, 2.123456])])
expect(location.coords... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | spec/models/seeds/organization_spec.rb | Ruby | mit | 46 | master | 390 | require 'rails_helper'
RSpec.describe Seeds::Organization do
before do
allow(Geocoder).to receive(:search).and_return([double(coordinates: [0, 0])])
end
describe '.import' do
it "imports organizations" do
Seeds::Organization.import
expect(Organization.all).to include an_object_having_attribu... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | test/test_helper.rb | Ruby | mit | 46 | master | 290 | ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | config/application.rb | Ruby | mit | 46 | master | 750 | require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Rubymap
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails v... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | config/environments/production.rb | Ruby | mit | 46 | master | 3,582 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web serve... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | config/environments/test.rb | Ruby | mit | 46 | master | 1,876 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suit... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | config/environments/development.rb | Ruby | mit | 46 | master | 2,181 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web serv... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | config/initializers/geocoder.rb | Ruby | mit | 46 | master | 1,121 | Geocoder.configure(
# Geocoding options
# timeout: 3, # geocoding service timeout (secs)
lookup: :google, # name of geocoding service (symbol)
# ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol)
# language: :en, # ISO-639 language code
# us... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | app/models/location.rb | Ruby | mit | 46 | master | 634 | class Location < ApplicationRecord
belongs_to :organization
validates :coords, presence: true
before_validation :geocode_address
def self.import(organization:, address:)
new(organization: organization, address: address).save!
end
private
def geocode_address
return if geocoded_coords.blank?
... |
github | lewispb/rubymap | https://github.com/lewispb/rubymap | app/models/seeds/organization.rb | Ruby | mit | 46 | master | 557 | module Seeds
class Organization < ActiveYaml::Base
set_root_path "data"
def self.import
all.each(&:import)
end
def import
locations.each do |location|
Location.import(organization: organization, address: location["address"])
end
end
private
def organization
... |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | modular_routes.gemspec | Ruby | apache-2.0 | 46 | main | 1,829 | # frozen_string_literal: true
require_relative "lib/modular_routes/version"
Gem::Specification.new do |spec|
spec.name = "modular_routes"
spec.version = ModularRoutes::VERSION
spec.authors = ["Vítor Avelino"]
spec.email = ["contact@vitoravelino.me"]
spec.summary = "Dedica... |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/route_mapping_spec.rb | Ruby | apache-2.0 | 46 | main | 7,554 | # frozen_string_literal: true
RSpec.describe "Route Mapping", type: :routing do
context "when plural resource" do
it "maps restful routes" do
expect(get: "/users").to route_to("users/index#call")
expect(post: "/users").to route_to("users/create#call")
expect(get: "/users/new").to route_to("user... |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/spec_helper.rb | Ruby | apache-2.0 | 46 | main | 491 | # frozen_string_literal: true
require "bundler"
require "support/coverage"
Bundler.require :default, :development
Combustion.initialize!(:all)
require "rspec/rails"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
... |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/controller_spec.rb | Ruby | apache-2.0 | 46 | main | 304 | # frozen_string_literal: true
RSpec.describe "Controllers", type: :request do
it "raises error (violated constraint)" do
expect { account_path("d") }.to raise_error(ActionController::UrlGenerationError)
expect { paper_path("d") }.to raise_error(ActionController::UrlGenerationError)
end
end |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/modular_routes/builder_spec.rb | Ruby | apache-2.0 | 46 | main | 512 | # frozen_string_literal: true
RSpec.describe ModularRoutes::Builder do
subject(:builder) { described_class.new(api_only: false) }
describe "#concerns" do
it "raises SyntaxError" do
expect { builder.concerns(:whatever) }.to raise_error(SyntaxError)
end
end
describe "#root" do
it "raises Synt... |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/modular_routes/scopable_spec.rb | Ruby | apache-2.0 | 46 | main | 239 | # frozen_string_literal: true
RSpec.describe ModularRoutes::Scopable do
subject(:scopable) { described_class }
it "raises NotImplementedError" do
expect { scopable.for(:inexistent) }.to raise_error(NotImplementedError)
end
end |
github | vitoravelino/modular_routes | https://github.com/vitoravelino/modular_routes | spec/modular_routes/routable_spec.rb | Ruby | apache-2.0 | 46 | main | 239 | # frozen_string_literal: true
RSpec.describe ModularRoutes::Routable do
subject(:routable) { described_class }
it "raises NotImplementedError" do
expect { routable.for(:inexistent) }.to raise_error(NotImplementedError)
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.