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 | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/api-examples/initializer_example.rb | Ruby | mit | 47 | master | 1,422 | require "dnn"
require "dnn/datasets/mnist"
include DNN::Models
include DNN::Layers
include DNN::Initializers
include DNN::Optimizers
include DNN::Losses
EPOCHS = 3
BATCH_SIZE = 128
x_train, y_train = DNN::MNIST.load_train
x_test, y_test = DNN::MNIST.load_test
x_train = x_train.reshape(x_train.shape[0], 784)
x_test ... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/pix2pix/imgen.rb | Ruby | mit | 47 | master | 629 | require "dnn"
require "dnn/image"
require "dnn/datasets/cifar10"
require_relative "dcgan"
def load_dataset
x, y = DNN::CIFAR10.load_test
x_out = Numo::SFloat.cast(x)
x_in = x_out.mean(axis: 3, keepdims: true)
x_in = (x_in / 127.5) - 1
x_out = (x_out / 127.5) - 1
[x_in, x_out]
end
batch_size = 100
dcgan =... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/pix2pix/train.rb | Ruby | mit | 47 | master | 2,315 | # This example converts a CIFAR10 grayscale image to a color image.
require "dnn"
require "dnn/datasets/cifar10"
require_relative "dcgan"
include DNN::Optimizers
include DNN::Losses
class Pix2pixIterator < DNN::BaseIterator
def initialize(x, y)
super(last_round_down: true)
@iter1 = DNN::Iterator.new(x, y, ... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/pix2pix/dcgan.rb | Ruby | mit | 47 | master | 3,771 | include DNN::Models
include DNN::Layers
class Generator < Model
def initialize(input_shape, base_num_filters)
super()
@input_shape = input_shape
@cv1 = Conv2D.new(base_num_filters, 4, padding: true)
@cv2 = Conv2D.new(base_num_filters, 4, strides: 2, padding: true)
@cv3 = Conv2D.new(base_num_filte... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/dcgan/train.rb | Ruby | mit | 47 | master | 1,515 | require "dnn"
require "dnn/datasets/mnist"
require_relative "dcgan"
include DNN::Optimizers
include DNN::Losses
include DNN::Callbacks
class DCGANTrainer < DNN::Trainer
def on_train_step(x_batch, y_batch, need_accuracy: false)
batch_size = x_batch.shape[0]
noise = Numo::SFloat.new(batch_size, 20).rand(-1, 1... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/dcgan/imgen.rb | Ruby | mit | 47 | master | 464 | require "dnn"
require "dnn/image"
require_relative "dcgan"
include DNN::Loaders
Image = DNN::Image
batch_size = 100
dcgan = DCGAN.load("trained/dcgan_model_epoch20.marshal")
gen = dcgan.gen
Numo::SFloat.srand(rand(1 << 31))
noise = Numo::SFloat.new(batch_size, 20).rand(-1, 1)
images = gen.predict(noise)
batch_siz... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/dcgan/dcgan.rb | Ruby | mit | 47 | master | 2,442 | include DNN::Models
include DNN::Layers
class Generator < Model
def initialize
super
@d1 = Dense.new(1024)
@d2 = Dense.new(7 * 7 * 64)
@cv1 = Conv2D.new(64, 4, padding: true)
@cvt1 = Conv2DTranspose.new(64, 4, strides: 2, padding: true)
@cvt2 = Conv2DTranspose.new(32, 4, strides: 2, padding: ... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/judge-number/mnist_predict.rb | Ruby | mit | 47 | master | 558 | require "dnn"
require "dnn/image"
require_relative "convnet8"
def load_model
return if $model
$model = ConvNet.create([28, 28, 1])
$model.predict1(Numo::SFloat.zeros(28, 28, 1))
$model.load_params("trained_mnist_params.marshal")
end
def mnist_predict(img, width, height)
load_model
img = DNN::Image.from_bi... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/judge-number/convnet8.rb | Ruby | mit | 47 | master | 1,523 | require "dnn"
require "numo/linalg/autoloader"
include DNN::Models
include DNN::Layers
include DNN::Optimizers
include DNN::Losses
class ConvNet < Model
def self.create(input_shape)
convnet = ConvNet.new(input_shape, 32)
convnet.setup(Adam.new, SoftmaxCrossEntropy.new)
convnet
end
def initialize(in... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/judge-number/server.rb | Ruby | mit | 47 | master | 425 | require "sinatra"
require "sinatra/reloader"
require "json"
require "base64"
require_relative "mnist_predict"
get "/" do
erb :index
end
post "/predict" do
json = request.body.read
params = JSON.parse(json, symbolize_names: true)
img = Base64.decode64(params[:img])
width = params[:width].to_i
height = para... |
github | unagiootoro/ruby-dnn | https://github.com/unagiootoro/ruby-dnn | examples/judge-number/mnist_train.rb | Ruby | mit | 47 | master | 571 | require "dnn"
require "dnn/datasets/mnist"
require_relative "convnet8"
include DNN::Callbacks
x_train, y_train = DNN::MNIST.load_train
x_test, y_test = DNN::MNIST.load_test
x_train = Numo::SFloat.cast(x_train) / 255
x_test = Numo::SFloat.cast(x_test) / 255
y_train = DNN::Utils.to_categorical(y_train, 10, Numo::SFlo... |
github | kavu/carrierwave-webp | https://github.com/kavu/carrierwave-webp | carrierwave-webp.gemspec | Ruby | mit | 47 | master | 969 | # encoding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'carrierwave/webp/version'
Gem::Specification.new do |spec|
spec.name = 'carrierwave-webp'
spec.version = Carrierwave::Webp::VERSION
spec.authors = ['Max Riveiro']
... |
github | kavu/carrierwave-webp | https://github.com/kavu/carrierwave-webp | lib/carrierwave/webp/converter.rb | Ruby | mit | 47 | master | 873 | # encoding: utf-8
require 'webp-ffi'
module CarrierWave
module WebP
module Converter
def convert_to_webp(options = {})
manipulate! do |img|
img = yield(img) if block_given?
webp_path = "#{img.path}.webp"
old_filename = filename
::WebP.encode(img... |
github | creditario/nopassword | https://github.com/creditario/nopassword | Gemfile | Ruby | mit | 47 | main | 419 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Specify your gem's dependencies in no_password.gemspec.
gemspec
# To use puma
gem "puma"
gem "sqlite3", "> 2.0"
gem "propshaft"
gem "turbo-rails"
gem "tailwindcss-rails"
gem "stimulus-rails"
gem "importmap-rails"
# To use... |
github | creditario/nopassword | https://github.com/creditario/nopassword | Rakefile | Ruby | mit | 47 | main | 342 | require "bundler/setup"
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end... |
github | creditario/nopassword | https://github.com/creditario/nopassword | no_password.gemspec | Ruby | mit | 47 | main | 1,542 | # frozen_string_literal: true
$LOAD_PATH << File.expand_path("lib", __dir__)
require_relative "lib/no_password/version"
Gem::Specification.new do |spec|
spec.name = "no_password_auth"
spec.version = NoPassword::VERSION
spec.authors = ["Mario Alberto Chávez", "Armando Escalier", "Juan Bojorges"]
spec.homepage ... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/test_helper.rb | Ruby | mit | 47 | main | 881 | # Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
require "rails/test_help"
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/controllers/no_password/sessions_controller_test.rb | Ruby | mit | 47 | main | 2,040 | # frozen_string_literal: true
require "test_helper"
module NoPassword
class SessionsControllerTest < ActionDispatch::IntegrationTest
test "it creates a session with nil referer_path if return_to path is engine's new_session_path" do
get no_password.new_session_url
post no_password.session_path(retur... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/controllers/no_password/session_confirmations_controller_test.rb | Ruby | mit | 47 | main | 5,118 | # frozen_string_literal: true
require "test_helper"
class CustomSessionConfirmationsController < NoPassword::SessionConfirmationsController
def after_sign_in!(current_session, by_url)
# Do something else
main_app.root_path
end
end
module NoPassword
class SessionConfirmationsControllerTest < ActionDispa... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/controllers/no_password/concerns/web_tokens_test.rb | Ruby | mit | 47 | main | 1,481 | require "test_helper"
module NoPassword
class WebTokensTest < ActionDispatch::IntegrationTest
def setup
@sample ||= SampleController.new
end
test "it verifies token" do
session = no_password_sessions(:session_unclaimed)
signed_token = @sample.sign_token(session.token)
verified_t... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/controllers/no_password/concerns/controller_helpers_test.rb | Ruby | mit | 47 | main | 1,786 | # frozen_string_literal: true
require "test_helper"
module NoPassword
class ControllerHelpersTest < ActionDispatch::IntegrationTest
test "it checks for current session when logging in" do
post no_password.session_path, params: {session: {email: "ana@example.com"}}, headers: {HTTP_USER_AGENT: "Mozilla/5.0"... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/use_cases/no_password/session_manager_test.rb | Ruby | mit | 47 | main | 2,458 | require "test_helper"
module NoPassword
class SessionManagerTest < ActiveSupport::TestCase
REMOTE_ADDR = "127.0.0.1"
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15"
test "it creates a new session" do
email = "user... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/support/print_routes.rb | Ruby | mit | 47 | main | 356 | # frozen_string_literal: true
module PrintRoutes
def print_routes
puts "ROUTES ----------------------"
Rails.application.routes.routes.each do |r|
route = {alias: r.name, path: r.path.spec.to_s, controller: r.defaults[:controller], action: r.defaults[:action]}
puts route
end
puts "------... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/models/no_password/session_test.rb | Ruby | mit | 47 | main | 660 | require "test_helper"
module NoPassword
class SessionTest < ActiveSupport::TestCase
test "is valid" do
subject = Session.new(model_params)
assert subject.valid?
end
test "is invalid without token" do
subject = Session.new(model_params({token: nil}))
refute subject.valid?
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/mailers/no_password/sessions_mailer_test.rb | Ruby | mit | 47 | main | 369 | # frozen_string_literal: true
require "test_helper"
module NoPassword
class SessionsMailerTest < ActionMailer::TestCase
test "it sends email with token" do
session = no_password_sessions(:session_unclaimed)
subject = SessionsMailer.with(session: session).send_token
assert_emails 1 do
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/mailer_previews/sessions_mailer_preview.rb | Ruby | mit | 47 | main | 361 | # frozen_string_literal: true
# Preview all emails at http://localhost:3000/rails/mailers/sessions_mailer
class SessionsMailerPreview < ActionMailer::Preview
def send_token
current_session = NoPassword::SessionManager.new.create("Preview", "test@mail.com", "127.0.0.1")
NoPassword::SessionsMailer.with(sessio... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/dummy/db/schema.rb | Ruby | mit | 47 | main | 1,157 | # 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 | creditario/nopassword | https://github.com/creditario/nopassword | test/dummy/config/application.rb | Ruby | mit | 47 | main | 753 | 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)
require "no_password"
module Dummy
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/dummy/config/environments/test.rb | Ruby | mit | 47 | main | 2,437 | require "active_support/core_ext/integer/time"
# 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 suite and is wiped
# and recreated between test runs. Don't rely on the data the... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/dummy/config/environments/development.rb | Ruby | mit | 47 | main | 3,182 | require "active_support/core_ext/integer/time"
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 any time
# it changes. This slows down response time but is perfect for developme... |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/dummy/app/controllers/home_controller.rb | Ruby | mit | 47 | main | 211 | # frozen_string_literal: true
class HomeController < ApplicationController
include NoPassword::ControllerHelpers
before_action :authenticate_session!, only: [:show]
def index
end
def show
end
end |
github | creditario/nopassword | https://github.com/creditario/nopassword | test/integration/navigation_test.rb | Ruby | mit | 47 | main | 1,221 | # frozen_string_literal: true
require "test_helper"
class NavigationTest < ActionDispatch::IntegrationTest
test "it redirects to start new session" do
path = main_app.secure_area_path
get path
assert_redirected_to no_password.new_session_path(return_to: CGI.escape(path))
end
test "it shows no acti... |
github | creditario/nopassword | https://github.com/creditario/nopassword | config/routes.rb | Ruby | mit | 47 | main | 353 | NoPassword::Engine.routes.draw do
resource :session, only: [:new, :create, :destroy]
get "/confirmations/:token", to: "session_confirmations#edit", as: :session_confirmation
get "/confirmations", to: "session_confirmations#edit", as: :edit_session_confirmations
resource :session_confirmations, path: :confirmat... |
github | creditario/nopassword | https://github.com/creditario/nopassword | config/initializers/importmap.rb | Ruby | mit | 47 | main | 746 | # frozen_string_literal: true
require "no_password"
NoPassword.configuration.importmap.draw do
# Stimulus & Turbo
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: ... |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/no_password.rb | Ruby | mit | 47 | main | 1,026 | # frozen_string_literal: true
require "no_password/version"
require "no_password/engine"
require "no_password/railtie"
require "importmap-rails"
module NoPassword
class << self
attr_accessor :configuration
end
class Configuration
attr_accessor :session_expiration, :token_expiration, :secret_key, :tailw... |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/generators/no_password/install_generator.rb | Ruby | mit | 47 | main | 783 | module NoPassword
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
def create_initializer_file
template "config/initializers/no_password.rb"
end
def add_route
return if Rails.application.routes.routes.detect { |route| route.app.app =... |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/generators/no_password/tailwind_config_generator.rb | Ruby | mit | 47 | main | 256 | module NoPassword
class TailwindConfigGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
def create_tailwind_config_file
template "app/assets/config/no_password/tailwind.config.js"
end
end
end |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/generators/no_password/install_templates_generator.rb | Ruby | mit | 47 | main | 776 | module NoPassword
class InstallTemplatesGenerator < Rails::Generators::Base
source_root File.expand_path("../../../app/views", __FILE__)
def copy_layout
empty_directory "app/views/layouts/no_password"
directory File.join(engine_views_path, "layouts", "no_password"),
File.join(app_views_pa... |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/generators/no_password/templates/config/initializers/no_password.rb | Ruby | mit | 47 | main | 280 | NoPassword.configure do |config|
# Session expiration time
# config.session_expiration = 2.hours
#
# Token expiration time
# config.token_expiration = 15.minutes
#
# Secret key to cypher tokens, if none, then Rails secret key is used
# config.secret_key = nil
end |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/no_password/engine.rb | Ruby | mit | 47 | main | 289 | require "importmap-rails"
module NoPassword
class Engine < ::Rails::Engine
isolate_namespace NoPassword
initializer "no_password.importmap", before: "importmap" do |app|
app.config.importmap.paths << Engine.root.join("config/initializers/importmap.rb")
end
end
end |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/tasks/install.rake | Ruby | mit | 47 | main | 520 | namespace :no_password do
desc "Install No Password"
task install: :environment do
ActiveRecord::Base.connection
rescue ActiveRecord::NoDatabaseError
puts "ERROR: database does not exist, run 'rails db:create' first"
else
Rails::Command.invoke :generate, ["no_password:install"]
end
namespace :i... |
github | creditario/nopassword | https://github.com/creditario/nopassword | lib/tasks/tailwind.rake | Ruby | mit | 47 | main | 981 | require "tailwindcss-rails"
require "rails/generators"
NO_PASSWORD_TAILWIND_COMPILE_COMMAND = "#{Tailwindcss::Engine.root.join("exe/tailwindcss")} -i #{NoPassword::Engine.root.join("app/assets/stylesheets/no_password/application.tailwind.css")} -o #{Rails.root.join("app/assets/builds", "no_password/tailwind.css")} -c ... |
github | creditario/nopassword | https://github.com/creditario/nopassword | db/migrate/20211202211706_create_no_password_sessions.rb | Ruby | mit | 47 | main | 418 | class CreateNoPasswordSessions < ActiveRecord::Migration[7.0]
def change
create_table :no_password_sessions, if_not_exists: true do |t|
t.timestamp :expires_at
t.timestamp :claimed_at
t.string :token, null: false
t.string :user_agent, null: false
t.string :remote_addr, null: false
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/helpers/no_password/no_password_helper.rb | Ruby | mit | 47 | main | 403 | module NoPassword
module NoPasswordHelper
def no_password_importmap_tags(entry_point = "application")
safe_join [
javascript_inline_importmap_tag(NoPassword.configuration.importmap.to_json(resolver: self)),
javascript_importmap_module_preload_tags(NoPassword.configuration.importmap),
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/controllers/no_password/sessions_controller.rb | Ruby | mit | 47 | main | 1,314 | # frozen_string_literal: true
module NoPassword
class SessionsController < ApplicationController
include NoPassword::ControllerHelpers
def new
@return_to = params[:return_to].to_s
@resource = Session.new
end
def create
return_to = params[:return_to].to_s
current_session = Se... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/controllers/no_password/session_confirmations_controller.rb | Ruby | mit | 47 | main | 1,489 | # frozen_string_literal: true
module NoPassword
class SessionConfirmationsController < ApplicationController
include NoPassword::ControllerHelpers
include NoPassword::WebTokens
def edit
return unless params[:token].present?
token = verify_token(params[:token])
redirect_url = sign_in_s... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/controllers/concerns/no_password/web_tokens.rb | Ruby | mit | 47 | main | 924 | # frozen_string_literal: true
require "active_support/concern"
module NoPassword
module WebTokens
extend ActiveSupport::Concern
included do
def sign_token(data)
secret_key = NoPassword.configuration.secret_key || Rails.application.secret_key_base
verifier = ActiveSupport::MessageVerif... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/controllers/concerns/no_password/controller_helpers.rb | Ruby | mit | 47 | main | 1,088 | # frozen_string_literal: true
module NoPassword
module ControllerHelpers
extend ActiveSupport::Concern
included do
def current_session
@session ||= begin
session_id = session[session_key]
return nil if session_id.blank?
current_session = find_session(session_id)
... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/models/no_password/session.rb | Ruby | mit | 47 | main | 366 | # frozen_string_literal: true
module NoPassword
class Session < ApplicationRecord
validates :token, :user_agent, :remote_addr, :email, presence: true
def claimed?
claimed_at.present?
end
def expired?
current_time = Time.zone.now
expires_at <= current_time
end
def invalid?... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/use_cases/no_password/session_manager.rb | Ruby | mit | 47 | main | 1,192 | # frozen_string_literal: true
module NoPassword
class SessionManager
def create(user_agent, email, remote_addr, return_url = nil)
expire_unclaimed_session(email)
Session.create(
user_agent: user_agent,
email: email,
expires_at: NoPassword.configuration.session_expiration.from... |
github | creditario/nopassword | https://github.com/creditario/nopassword | app/mailers/no_password/sessions_mailer.rb | Ruby | mit | 47 | main | 422 | # frozen_string_literal: true
module NoPassword
class SessionsMailer < ApplicationMailer
include NoPassword::WebTokens
def send_token
@session = params[:session]
@title = t("mailers.send_token.subject")
@friendly_token = @session.token
@signed_token = token_to_url(sign_token(@friendl... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | Gemfile | Ruby | mit | 47 | develop | 2,305 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "~> 8.1"
# The modern frontend packages for Rails
gem "propshaft"
gem "cssbundling-rails"
gem "jsbundling-rails"
gem "stimulus-rails"
gem "turbo-rails"
# NOTE: date-select helper to support other locales other ... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/factories.rb | Ruby | mit | 47 | develop | 6,164 | FactoryBot.define do
sequence(:phone_number, "855972345678")
sequence :email do |n|
"user#{n}@example.com"
end
sequence :auth_token do
SecureRandom.alphanumeric(43)
end
sequence :somleng_account_sid do
SecureRandom.uuid
end
factory :broadcast do
account
voice
pending
tra... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/rails_helper.rb | Ruby | mit | 47 | develop | 2,731 | # 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 | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/spec_helper.rb | Ruby | mit | 47 | develop | 5,532 | if ENV.key?("CI")
require "simplecov"
SimpleCov.start do
enable_coverage_for_eval
end
require "simplecov-cobertura"
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
end
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` ... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/metadata_request_schema_spec.rb | Ruby | mit | 47 | develop | 1,152 | require "rails_helper"
RSpec.describe MetadataRequestSchema, type: :request_schema do
it "validates the metadata" do
expect(validate_schema(input_params: { metadata: nil })).not_to have_valid_field(:metadata)
expect(validate_schema(input_params: {})).to have_valid_field(:metadata)
expect(
validate_... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/jsonapi_request_schema_spec.rb | Ruby | mit | 47 | develop | 936 | require "rails_helper"
module V1
RSpec.describe JSONAPIRequestSchema, type: :request_schema do
it "validates the resource id" do
resource = create(:beneficiary)
schema = Class.new(JSONAPIRequestSchema) do
params do
required(:data).value(:hash).schema do
required(:type).... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/update_broadcast_request_schema_spec.rb | Ruby | mit | 47 | develop | 11,286 | require "rails_helper"
module V1
RSpec.describe UpdateBroadcastRequestSchema, type: :request_schema do
it "validates the audio_url" do
broadcast = create(:broadcast, :pending, :voice)
started_broadcast = create(:broadcast, :running, :voice)
stopped_broadcast = create(:broadcast, :stopped, :voic... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/beneficiary_stats_request_schema_spec.rb | Ruby | mit | 47 | develop | 1,961 | require "rails_helper"
module V1
RSpec.describe BeneficiaryStatsRequestSchema, type: :request_schema do
it "validates the address" do
expect(
validate_schema(input_params: { group_by: [ "address.administrative_division_level_2_code" ] })
).not_to have_valid_field(:group_by)
expect(
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/beneficiary_address_request_schema_spec.rb | Ruby | mit | 47 | develop | 848 | require "rails_helper"
module V1
RSpec.describe BeneficiaryAddressRequestSchema, type: :request_schema do
it "validates the address" do
expect(
validate_schema(input_params: { data: { attributes: { iso_region_code: "KH-1", administrative_division_level_2_code: "0101", administrative_division_level_... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/beneficiary_request_schema_spec.rb | Ruby | mit | 47 | develop | 7,662 | require "rails_helper"
module V1
RSpec.describe BeneficiaryRequestSchema, type: :request_schema do
it "validates the phone_number" do
beneficiary = create(:beneficiary)
expect(
validate_schema(input_params: { data: { attributes: { phone_number: nil } } })
).not_to have_valid_field(:dat... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/broadcast_request_schema_spec.rb | Ruby | mit | 47 | develop | 5,265 | require "rails_helper"
module V1
RSpec.describe BroadcastRequestSchema, type: :request_schema do
it "validates the channel" do
account = create(:account, :supported_channels => ["voice"])
expect(
validate_schema(
input_params: {
data: {
attributes: {
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/update_beneficiary_request_schema_spec.rb | Ruby | mit | 47 | develop | 2,069 | require "rails_helper"
module V1
RSpec.describe UpdateBeneficiaryRequestSchema, type: :request_schema do
it "validates phone number" do
account = create(:account)
beneficiary = create(:beneficiary, account:)
other_beneficiary = create(:beneficiary, account:)
expect(
validate_sche... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/request_schemas/v1/beneficiary_group_member_request_schema_spec.rb | Ruby | mit | 47 | develop | 1,618 | require "rails_helper"
module V1
RSpec.describe BeneficiaryGroupMemberRequestSchema, type: :request_schema do
it "validates the beneficiary_id" do
account = create(:account)
beneficiary = create(:beneficiary, account:)
other_beneficiary = create(:beneficiary)
group = create(:beneficiary_g... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/validators/email_uniqueness_validator_spec.rb | Ruby | mit | 47 | develop | 519 | require "rails_helper"
RSpec.describe EmailUniquenessValidator do
it "validates the email format" do
validatable_klass = Class.new do
include ActiveModel::Model
include ActiveModel::Attributes
attribute :email
validates :email, email_uniqueness: true
end
create(:user, email: "j... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/validators/email_format_validator_spec.rb | Ruby | mit | 47 | develop | 521 | require "rails_helper"
RSpec.describe EmailFormatValidator do
it "validates the email uniqueness" do
validatable_klass = Class.new do
include ActiveModel::Model
include ActiveModel::Attributes
attribute :email
validates :email, email_format: true
end
expect(validatable_klass.ne... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/validators/subdomain_validator_spec.rb | Ruby | mit | 47 | develop | 640 | require "rails_helper"
RSpec.describe SubdomainValidator do
it "validates a subdomain" do
validatable_klass = Struct.new(:subdomain) do
include ActiveModel::Validations
def self.model_name
ActiveModel::Name.new(self, nil, "temp")
end
validates :subdomain, subdomain: true
end... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/validators/phone_number_type_validator_spec.rb | Ruby | mit | 47 | develop | 903 | require "rails_helper"
RSpec.describe PhoneNumberTypeValidator do
it "validates the phone number" do
validatable_klass = Class.new do
include ActiveModel::Model
include ActiveModel::Attributes
attribute :phone_number
validates :phone_number, phone_number_type: true
end
expect(v... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/mailers/devise_mailer_spec.rb | Ruby | mit | 47 | develop | 527 | require "rails_helper"
RSpec.describe DeviseMailer, type: :mailer do
describe "#confirmation_instructions" do
it "handles normal domains" do
account = create(:account, subdomain: "example")
user = create(:user, account:)
mail = DeviseMailer.confirmation_instructions(user, "abc")
mail_bo... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/mailers/forgot_subdomain_mailer_spec.rb | Ruby | mit | 47 | develop | 593 | require "rails_helper"
RSpec.describe ForgotSubdomainMailer, type: :mailer do
describe "#forgot_subdomain" do
it "handles multiple domains" do
account = create(:account, name: "NCDM")
user = create(:user, account:, name: "Bob Chann")
mail = ForgotSubdomainMailer.forgot_subdomain(user)
m... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/broadcasts_spec.rb | Ruby | mit | 47 | develop | 16,757 | require "rails_helper"
RSpec.resource "Broadcasts" do
get "/v1/broadcasts" do
FieldDefinitions::BroadcastFields.each do |field|
with_options scope: [ :filter, field.path.to_sym ] do
parameter("$operator", field.description, required: false, method: :_disabled)
end
end
example "List ... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/beneficiaries_spec.rb | Ruby | mit | 47 | develop | 24,778 | require "rails_helper"
RSpec.resource "Beneficiaries" do
get "/v1/beneficiaries" do
FieldDefinitions::BeneficiaryFields.each do |field|
with_options scope: [ :filter, field.path.to_sym ] do
parameter("$operator", field.description, required: false, method: :_disabled)
end
end
exampl... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/jsonapi_spec.rb | Ruby | mit | 47 | develop | 1,072 | require "rails_helper"
RSpec.resource "JSONAPI", document: false do
get "/v1/beneficiaries/:id" do
it "supports include for related resources" do
beneficiary = create(:beneficiary)
create(:beneficiary_address, beneficiary:)
set_authorization_header_for(beneficiary.account)
do_request(id... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/accounts_spec.rb | Ruby | mit | 47 | develop | 660 | require "rails_helper"
RSpec.resource "Accounts" do
get "/v1/account" do
example "Fetch account settings" do
explanation <<~HEREDOC
This endpoint can be used to return account settings for the authorized account.
HEREDOC
account = create(:account)
set_authorization_header_for(a... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/beneficiary_groups_spec.rb | Ruby | mit | 47 | develop | 13,692 | require "rails_helper"
RSpec.resource "Beneficiary Groups" do
explanation <<~HEREDOC
The Beneficiary Groups endpoint allows developers to programmatically organize beneficiaries into logical groups for targeted message delivery.
This is particularly useful when building workflows that require sending notifi... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/events_spec.rb | Ruby | mit | 47 | develop | 4,764 | require "rails_helper"
RSpec.resource "Events" do
explanation <<~HEREDOC
The Events API provides a structured way to track and respond to significant changes within the OpenEWS system.
An event represents something that has occurred—such as the creation, update, or deletion of a key resource like a benefici... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/v1/broadcasts/notifications_spec.rb | Ruby | mit | 47 | develop | 8,311 | require "rails_helper"
RSpec.resource "Notifications" do
explanation <<~HEREDOC
The **Notifications API** allows you to view and analyze the individual notifications that are sent to beneficiaries as part of a broadcast.
A **Notification** represents a planned message to a single beneficiary, linked to a sp... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/somleng_webhooks/message_status_callback_spec.rb | Ruby | mit | 47 | develop | 1,983 | require "rails_helper"
RSpec.describe "Message Status Callbacks" do
it "Handles message status callbacks" do
account = create(:account, somleng_account_sid: "account-sid", somleng_auth_token: "auth-token")
broadcast = create(:broadcast, :running, :sms, account:)
notification = create(:notification, :pend... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/requests/somleng_webhooks/call_status_callback_spec.rb | Ruby | mit | 47 | develop | 2,950 | require "rails_helper"
RSpec.describe "Call Status Callbacks" do
it "Handles call status callbacks" do
account = create(:account, somleng_account_sid: "account-sid", somleng_auth_token: "auth-token")
broadcast = create(:broadcast, :running, account:)
notification = create(:notification, :pending, broadca... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/serializers/simple_serializer_spec.rb | Ruby | mit | 47 | develop | 2,121 | require "rails_helper"
RSpec.describe SimpleSerializer do
serializer_class = Class.new do
include SimpleSerializer
has_associations :foo, :bar
has_associations :baz
attributes :name, :email, :created_at, :updated_at
timestamp_attributes :created_at
attribute :updated_at do |object|
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/serializers/csv_serializers/beneficiary_group_membership_serializer_spec.rb | Ruby | mit | 47 | develop | 721 | require "rails_helper"
module CSVSerializers
RSpec.describe BeneficiaryGroupMembershipSerializer do
it "serializes the beneficiary group membership attributes" do
account = create(:account)
beneficiary = create(:beneficiary, phone_number: "85510555123", account:)
beneficiary_group = create(:ben... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/serializers/csv_serializers/beneficiary_serializer_spec.rb | Ruby | mit | 47 | develop | 2,159 | require "rails_helper"
module CSVSerializers
RSpec.describe BeneficiarySerializer do
it "serializes the beneficiary attributes" do
beneficiary = create(
:beneficiary,
phone_number: "85510555123",
gender: "F",
status: "active",
disability_status: "none",
iso_l... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/serializers/csv_serializers/broadcast_serializer_spec.rb | Ruby | mit | 47 | develop | 477 | require "rails_helper"
module CSVSerializers
RSpec.describe BroadcastSerializer do
it "serializes a broadcast" do
expect(
BroadcastSerializer.new(
create(
:broadcast,
channel: :voice,
audio_url: "https://www.example.com/test.mp3",
)
).... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/errors_spec.rb | Ruby | mit | 47 | develop | 527 | require "rails_helper"
RSpec.describe "Errors", type: :system do
it "renders the error page" do
visit "/500"
expect(page).to have_content("The server encountered an internal error.")
expect(page).to have_link("Take me home", href: dashboard_root_path)
end
it "renders the outdated browser page" do
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/user_profile_spec.rb | Ruby | mit | 47 | develop | 2,214 | require "rails_helper"
RSpec.describe "User profile" do
it "updates the users profile" do
user = create(:user, name: "John Doe")
account_sign_in(user)
visit dashboard_root_path
navigate_to_user_profile_settings_for(user, section: "Profile")
fill_in("Name", with: "Bob Chann")
select("ខ្មែរ",... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/beneficiaries_spec.rb | Ruby | mit | 47 | develop | 5,294 | require "rails_helper"
RSpec.describe "Beneficiaries" do
it "lists all beneficiaries", :js do
user = create(:user)
_active_beneficiary = create(:beneficiary, phone_number: "85516789111", status: :active, account: user.account)
_disabled_beneficiary = create(:beneficiary, phone_number: "85510888888", stat... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/home_spec.rb | Ruby | mit | 47 | develop | 1,800 | require "rails_helper"
RSpec.describe "Home" do
it "renders the dashboard" do
account = create(:account)
user = create(:user, account:)
completed_broadcast = create(:broadcast, :completed, account:)
running_broadcast = create(:broadcast, :running, account:)
create_list(:notification, 10, broadca... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/broadcasts_spec.rb | Ruby | mit | 47 | develop | 10,519 | require "rails_helper"
RSpec.describe "Broadcasts" do
it "list broadcasts", :js do
user = create(:user)
pending_broadcast = create(
:broadcast,
:pending,
name: "My broadcast 1",
account: user.account
)
completed_broadcast = create(
:broadcast,
:completed,
nam... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/beneficiary_groups_spec.rb | Ruby | mit | 47 | develop | 3,041 | require "rails_helper"
RSpec.describe "Beneficiary Groups" do
it "lists all beneficiary groups", :js do
user = create(:user)
create(:beneficiary_group, name: "My group 1", account: user.account)
create(:beneficiary_group, name: "My group 2", account: user.account)
create(:beneficiary_group, name: "My... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/exports_spec.rb | Ruby | mit | 47 | develop | 1,630 | require "rails_helper"
RSpec.describe "Exports" do
it "exports a resource type" do
user = create(:user)
pending_broadcast = create(
:broadcast,
:pending,
account: user.account
)
completed_broadcast = create(
:broadcast,
:completed,
account: user.account
)
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/alerts_spec.rb | Ruby | mit | 47 | develop | 498 | require "rails_helper"
RSpec.describe "Alerts" do
it "lists alerts" do
user = create(:user, id: 1)
account_sign_in(user)
visit dashboard_alerts_path
expect(page).to have_title("Alerts")
expect(page).to have_content("Flood")
end
it "create a new alert" do
user = create(:user, id: 1)
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/forgot_subdomain_spec.rb | Ruby | mit | 47 | develop | 792 | require "rails_helper"
RSpec.describe "Forgot subdomain" do
it "Handles forgotten subdomains" do
account = create(:account, :with_logo, name: "My Alerting Authority", subdomain: "my-alerting-authority")
create(:user, account:, email: "johndoe@example.com")
visit(app_root_path)
fill_in("Email", with... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/imports_spec.rb | Ruby | mit | 47 | develop | 587 | require "rails_helper"
RSpec.describe "Imports" do
it "list imports" do
user = create(:user, name: "John Doe")
import = create(:import, :beneficiaries, user:, status: :processing)
create(:import, :beneficiaries, user:, status: :failed)
create(:import, :beneficiaries, user:, status: :succeeded)
a... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/authentication_spec.rb | Ruby | mit | 47 | develop | 2,445 | require "rails_helper"
RSpec.describe "Dashboard Authentication", type: :system do
it "sign in with valid OTP" do
account = create(:account)
user = create(:user, email: "user@example.com", password: "password123", account:, otp_required_for_login: true)
set_app_host(account)
visit(new_user_session_p... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/notifications_spec.rb | Ruby | mit | 47 | develop | 2,308 | require "rails_helper"
RSpec.describe "Notifications" do
it "can list all notifications for a broadcast", :js do
user = create(:user)
broadcast = create(:broadcast, :completed, account: user.account)
pending_notification = create(:notification, :pending, broadcast:)
failed_notification = create(:noti... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/settings/users_spec.rb | Ruby | mit | 47 | develop | 2,027 | require "rails_helper"
RSpec.describe "Users" do
it "can list all users" do
user = create(:user)
other_user = create(:user, account: user.account)
account_sign_in(user)
visit dashboard_settings_users_path
expect(page).to have_link(
other_user.name,
href: dashboard_settings_user_path... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/settings/accounts_spec.rb | Ruby | mit | 47 | develop | 1,879 | require "rails_helper"
RSpec.describe "Account Settings" do
it "updates the account settings" do
account = create(:account)
user = create(:user, account:, name: "John Doe")
somleng_account_sid = generate(:somleng_account_sid)
somleng_auth_token = generate(:auth_token)
account_sign_in(user)
v... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/dashboard/settings/developers_spec.rb | Ruby | mit | 47 | develop | 355 | require "rails_helper"
RSpec.describe "Developer Settings" do
it "can view the developer settings" do
account = create(:account)
create(:access_token, account:)
user = create(:user, account:)
account_sign_in(user)
visit(dashboard_settings_developer_path)
expect(page).to have_field("API key"... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/users/invitations_spec.rb | Ruby | mit | 47 | develop | 731 | require "rails_helper"
RSpec.describe "Invitations" do
it "accepts an invitation" do
account = create(:account, :with_logo, name: "My Alerting Authority")
perform_enqueued_jobs do
User.invite!(
account:,
email: "johndoe@example.com",
name: "John Doe"
)
end
open_em... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | spec/system/users/confirmations_spec.rb | Ruby | mit | 47 | develop | 924 | require "rails_helper"
RSpec.describe "Confirmations" do
it "resends confirmation instructions" do
user = create(:user, email: "user@example.com", confirmed_at: nil, password: "password123", otp_required_for_login: false)
set_app_host(user.account)
visit(new_user_session_path)
click_on "Didn't rece... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.