repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
remi/rackbox
lib/rackbox/rackbox.rb
<filename>lib/rackbox/rackbox.rb # To add blackbox testing to a Rails app, # in your spec_helper.rb # # require 'rackbox' # # Spec::Runner.configure do |config| # config.use_blackbox = true # end # class RackBox # i am an rdoc comment on RackBox's eigenclass class << self # to turn on some verbosit...
remi/rackbox
examples/.shared_specs/spec_helper.rb
ENV["RAILS_ENV"] = "test" begin require File.expand_path(File.dirname(__FILE__) + "/../config/environment") rescue LoadError # this isn't a rails project end require 'spec' if defined? RAILS_ENV require 'spec/rails' if defined?RAILS_ENV end require File.expand_path(File.dirname(__FILE__) + "/../../../lib/rack...
remi/rackbox
lib/rackbox/spec/configuration.rb
# Extend the RSpec configuration class with a use_blackbox option # # To add blackbox testing to a Rails app, # in your spec_helper.rb # # require 'rackbox' # # Spec::Runner.configure do |config| # config.use_blackbox = true # end # spec_configuration_class = nil spec_configuration_class = Spec::Example::Con...
remi/rackbox
spec/rackbox_build_query_spec.rb
<filename>spec/rackbox_build_query_spec.rb require File.dirname(__FILE__) + '/spec_helper' # add String#unescape to make spec more readable # 'user[name]=bob' is more readable than 'user%5Bname%5D=bob' class String def unescape Rack::Utils.unescape self end end describe RackBox, 'build_query' do it 'should...
remi/rackbox
examples/.shared_specs/blackbox/home_page_spec.rb
require File.dirname(__FILE__) + '/../spec_helper' describe 'Home Page' do it 'should say something by itself' do req( '/' ).body.should include('You said nothing') # this works, but you should probably be careful using # 'request' and 'response' in Rails specs ... ? request( '/' ).body.should in...
remi/rackbox
spec/posting_data_spec.rb
require File.dirname(__FILE__) + '/spec_helper' describe RackBox, 'POSTing data' do before do @rack_app1 = lambda {|env| [ 200, { }, "you POSTed data: #{ env['rack.input'].read }" ] } @rack_app2 = lambda {|env| req = Rack::Request.new env [ 200, { }, "you POSTed data: #{ req.body.read }" ] ...
remi/rackbox
lib/rackbox/spec/helpers.rb
class RackBox # Helper methods to include in specs that want to use blackbox testing # # TODO For backwards compatibility, I would like to keep a SpecHelpers # module, but this needs to be renamed because this isn't spec # specific at all! it needs to be easy to RackBox::App.new(rack_app).request...
remi/rackbox
spec/request_method_spec.rb
<gh_stars>1-10 require File.dirname(__FILE__) + '/spec_helper' describe RackBox, '#request' do before do @rack_app = lambda {|env| [ 200, { }, "you requested path #{ env['PATH_INFO'] }" ] } end it 'should be easy to run the #request method against any Rack app' do RackBox::App.new(@rack_app).request(...
remi/rackbox
rails_generators/blackbox_spec/blackbox_spec_generator.rb
<gh_stars>1-10 # This generator creates a new 'blackbox' spec, using RackBox class BlackboxSpecGenerator < Rails::Generator::Base attr_accessor :name_of_spec_to_create, :name_of_spec_file_to_create # `./script/generate blackbox_spec foo` will result in: # # runtime_args: ['foo'] # runtime_options: {:qui...
remi/rackbox
examples/rails/config/routes.rb
ActionController::Routing::Routes.draw do |map| map.print_method 'print-method', :controller => 'welcome', :action => 'print_method' map.print_session 'print-session', :controller => 'welcome', :action => 'print_session' map.redirect 'redirect', :controller => 'welcome', :action => 'redirect' map.s...
jasonkolodziej/dms
app/controllers/forms_controller.rb
<gh_stars>1-10 class FormsController < ApplicationController def general @page_title = 'Forms_General' end def advanced @page_title = 'Forms_Advanced' end def editors @page_title = 'Forms_Editors' end end
jasonkolodziej/dms
app/controllers/tables_controller.rb
<reponame>jasonkolodziej/dms class TablesController < ApplicationController def simple @page_title = 'Tables_Simple' end def data @page_title = 'Tables_Data' end end
jasonkolodziej/dms
app/controllers/calendar_controller.rb
<reponame>jasonkolodziej/dms class CalendarController < ApplicationController def index @page_title = 'Calendar' end end
jasonkolodziej/dms
config/initializers/assets.rb
<filename>config/initializers/assets.rb # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emo...
jasonkolodziej/dms
app/controllers/widgets_controller.rb
<reponame>jasonkolodziej/dms class WidgetsController < ApplicationController def index @page_title = 'Widgets' end end
jasonkolodziej/dms
app/controllers/dashboard_controller.rb
<filename>app/controllers/dashboard_controller.rb<gh_stars>0 class DashboardController < ApplicationController def version1 @page_title = 'Dashboard v1' end def version2 @page_title = 'Dashboard v2' end end
jasonkolodziej/dms
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :get_adminlte_config private # -Please configure AdminLTE in the AdminLteConfig class and do not ...
jasonkolodziej/dms
app/controllers/examples_controller.rb
class ExamplesController < ApplicationController def invoice @page_title = 'Invoice' end def invoice_print @page_title = 'Invoice' render :layout => false end def profile @page_title = 'Profile' end def login @page_title = 'Login' render :layout => false end def register ...
jasonkolodziej/dms
app/controllers/mailbox_controller.rb
<reponame>jasonkolodziej/dms class MailboxController < ApplicationController def inbox @page_title = 'Mailbox_Inbox' end def compose @page_title = 'Mailbox_Compose' end def read @page_title = 'Mailbox_Read' end end
jasonkolodziej/dms
app/controllers/charts_controller.rb
class ChartsController < ApplicationController def chartjs @page_title = 'Charts_ChartJS' end def morris @page_title = 'Charts_Morris' end def flot @page_title = 'Charts_Flot' end def inline @page_title = 'Charts_Inline' end end
jasonkolodziej/dms
app/controllers/uielements_controller.rb
<gh_stars>1-10 class UielementsController < ApplicationController def general @page_title = 'UI_Elements_General' end def icons @page_title = 'UI_Elements_Icons' end def buttons @page_title = 'UI_Elements_Buttons' end def sliders @page_title = 'UI_Elements_Sliders' end def timelin...
MattMencel/ruby-sysaid
lib/sysaid/user.rb
class SysAid::User attr_accessor :username, :display_name, :email, :phone, :first_name, :last_name, :admin, :agreement, :building, :car_number, :cellphone, :company, :cubic, :cust_int1, :cust_int2, :cust_list1, :cust_list2, :cust_notes, :cust_text1, :cust_text2, :department, :disable, ...
MattMencel/ruby-sysaid
lib/sysaid/ticket.rb
<filename>lib/sysaid/ticket.rb<gh_stars>0 require 'date' class SysAid::Ticket attr_accessor :agreement, :assign_counter, :assigned_to, :ciid, :category, :current_support_level, :cust_int1, :cust_int2, :cust_list1, :cust_list2, :description, :escalation, :id, :location, :max_support_level, ...
MattMencel/ruby-sysaid
sysaid.gemspec
<reponame>MattMencel/ruby-sysaid<gh_stars>0 Gem::Specification.new do |s| s.name = 'sysaid' s.version = '0.3.5' s.date = '2015-12-07' s.summary = "ruby-sysaid" s.description = "Wrapper for the SysAid SOAP API" s.authors = ["<NAME>"] s.email = '<EMAIL>' s.license = 'MI...
MattMencel/ruby-sysaid
lib/sysaid/task.rb
require 'date' class SysAid::Task attr_accessor :category, :ciid, :cust_date1, :cust_date2, :cust_int1, :cust_int2, :cust_list1, :cust_list2, :cust_notes, :custom_date_fields, :custom_fields, :cust_text1, :cust_text2, :description, :end_time, :estimation, :id, :notes, :progress, :proj...
MattMencel/ruby-sysaid
lib/sysaid.rb
<gh_stars>0 require 'savon' # Custom error class used for throwing exceptions to this gem's user class SysAidException < StandardError end # The main SysAid class class SysAid @@logged_in = false @@server_settings = { account: nil, username: nil, password: <PASSWORD>, wsdl_uri: nil, debug: false } # Accessor f...
MattMencel/ruby-sysaid
lib/sysaid/activity.rb
require 'date' class SysAid::Activity attr_accessor :ciid, :cust_int1, :cust_int2, :cust_int3, :cust_int4, :cust_list1, :cust_list2, :description, :from_time, :id, :sr_id, :to_time, :user def initialize reset_all_attributes end # Needed by both initialize and delete (to empty out the object when deleted)...
MattMencel/ruby-sysaid
lib/sysaid/project.rb
require 'date' class SysAid::Project attr_accessor :assigned_group, :category, :company, :cust_date1, :cust_date2, :cust_int1, :cust_int2, :cust_list1, :cust_list2, :cust_notes, :custom_date_fields, :custom_fields, :cust_text1, :cust_text2, :description, :end_time, :id, :incident_titl...
defus/ansible-monit
test/integration/default/serverspec/monit_spec.rb
<reponame>defus/ansible-monit<filename>test/integration/default/serverspec/monit_spec.rb require 'spec_helper' describe 'Monit' do describe service('monit') do it { should be_enabled } it { should be_running } end # describe port(2812) do # it { should be_listening.on('0.0.0.0').with('tcp') } # en...
matthewrudy/workling
lib/workling/rudeq.rb
<reponame>matthewrudy/workling module Workling module Rudeq def self.config @@config ||= {:queue_class => "RudeQueue"} end end end
matthewrudy/workling
test/rudeq_client_test.rb
<gh_stars>1-10 require File.dirname(__FILE__) + '/test_helper' context "The Rudeq client" do specify "should by default set a RudeQueue as its :queue" do client = Workling::Rudeq::Client.new client.queue.should == RudeQueue end specify "should user Rudeq.config[:queue_class] as the class" do befor...
matthewrudy/workling
lib/workling/rudeq/client.rb
<filename>lib/workling/rudeq/client.rb require 'workling/rudeq' module Workling module Rudeq class Client attr_reader :queue def initialize @queue = Workling::Rudeq.config[:queue_class].constantize end def method_missing(method, *args) @queue.send(method, *a...
matthewrudy/workling
test/test_helper.rb
<gh_stars>1-10 plugin_test = File.dirname(__FILE__) plugin_root = File.join plugin_test, '..' plugin_lib = File.join plugin_root, 'lib' require 'rubygems' require 'active_support' require 'test/spec' require 'mocha' gem 'memcache-client' require 'memcache' $:.unshift plugin_lib, plugin_test require "mocks/spawn" req...
matthewrudy/workling
lib/workling/remote/runners/rudeq_runner.rb
<reponame>matthewrudy/workling require 'workling/remote/runners/base' module Workling module Remote module Runners class RudeqRunner < Workling::Remote::Runners::Base cattr_accessor :routing cattr_accessor :client def initialize RudeqRunner.client = Workling::Rude...
matthewrudy/workling
lib/workling/return/store/rudeq_return_store.rb
<gh_stars>1-10 require 'workling/return/store/base' require 'workling/rudeq/client' module Workling module Return module Store class RudeqReturnStore < Base cattr_accessor :client def initialize self.class.client = Workling::Rudeq::Client.new end ...
matthewrudy/workling
test/rudeq_runner_test.rb
require File.dirname(__FILE__) + '/test_helper.rb' context "the RudeQ runner" do setup do @before = Workling::Remote.dispatcher end specify "should set up a RudeQ client" do Workling::Remote.dispatcher = Workling::Remote::Runners::RudeqRunner.new Workling::Remote.dispatcher.client.should.not.equal...
matthewrudy/workling
lib/workling/rudeq/poller.rb
require 'workling/rudeq' module Workling module Rudeq class Poller cattr_accessor :sleep_time # Seconds to sleep before looping cattr_accessor :reset_time # Seconds to wait while resetting connection def initialize(routing) Poller.sleep_time = Workling::Rudeq.config[:sleep_...
matthewrudy/workling
test/rudeq_return_store_test.rb
require File.dirname(__FILE__) + '/test_helper' context "the RudeQ return store" do def get_store Workling::Return::Store::RudeqReturnStore.new end specify "should defer :get to the RudeQueue" do RudeQueue.expects(:get).with(:abc) store = get_store store.get(:abc) end specify "should d...
matthewrudy/workling
test/rudeq_poller_test.rb
<reponame>matthewrudy/workling require File.dirname(__FILE__) + '/test_helper.rb' context "the RudeQ poller" do setup do routing = Workling::Starling::Routing::ClassAndMethodRouting.new @client = Workling::Rudeq::Poller.new(routing) end specify "should invoke Util.echo with the arg 'hello' if the stri...
incominghq/incoming-ruby
spec/incoming_spec.rb
<reponame>incominghq/incoming-ruby<filename>spec/incoming_spec.rb require 'spec_helper' describe Incoming do it 'has a version number' do expect(Incoming::VERSION).not_to be nil end end
incominghq/incoming-ruby
lib/incoming/instruction_set_converter.rb
require 'json' module Incoming class InstructionSetLoader def initialize @tasks = [] end def method_missing(name, args) raise InvalidArgumentError, "Arguments should be named" unless args.kind_of?(Hash) task = {name: name, options: args} if block_given? l = InstructionSe...
incominghq/incoming-ruby
lib/incoming.rb
<reponame>incominghq/incoming-ruby require "incoming/version" require 'apiture' module Incoming Client = Apiture.load_api(File.join(File.dirname(__FILE__), 'incominghq.yml')) end
incominghq/incoming-ruby
spec/instruction_set_converter_spec.rb
<filename>spec/instruction_set_converter_spec.rb<gh_stars>0 require 'spec_helper' require 'incoming/instruction_set_converter' describe Incoming::InstructionSetConverter do subject { described_class } def ins_file(name) File.join(File.dirname(__FILE__), 'fixtures', 'files', 'instruction_set', "#{name}.ins") ...
sevenc-nanashi/brainfuck-extended
brainfuck-extended.gemspec
Gem::Specification.new do |s| s.name = "brainfuck-extended" s.version = "1.0.1" s.summary = "An extended BrainFuck." s.description = <<-EOF An extended BrainFuck. You can use random, you can use 2D data, you can use temp data. EOF s.authors = ["sevenc-nanashi"] s.email = "<EMAIL>" s.files = Dir["mai...
sevenc-nanashi/brainfuck-extended
main.rb
<filename>main.rb require "io/console" require 'io/console/size' require "colorize" require "tty-cursor" require 'optparse' opt = OptionParser.new visible = false debug = false opt.on('-v', "--verbose", "Run with verbose mode") { |v| visible = v } opt.on('-d', "--debug", "Run with debug mode") {|v| debug = v if ...
bmarsha72/musical-api
controllers/account_controller.rb
class AccountController < ApplicationController @username = "" get '/' do #login /registration page erb :login end post '/register' do #accept the params from a post to create a user (bcrypt) @username = params[:username] @password = params[:password] @email = params[:email] if ...
bmarsha72/musical-api
config.ru
require 'sinatra/base' #controllers require './controllers/application_controller' require './controllers/account_controller' require './controllers/artist_controller' require './controllers/song_controller' #models require './models/artist' require './models/song' require './models/account' #map controllers to rout...
bmarsha72/musical-api
models/account.rb
class Account < ActiveRecord::Base end
bmarsha72/musical-api
db/migrate/20170119202252_songs.rb
<gh_stars>0 class Songs < ActiveRecord::Migration[5.0] def change create_table :songs do |tbl| tbl.string :name tbl.string :artist tbl.string :duration end end end
bmarsha72/musical-api
controllers/song_controller.rb
<reponame>bmarsha72/musical-api<filename>controllers/song_controller.rb class SongController < ApplicationController end
bmarsha72/musical-api
controllers/application_controller.rb
class ApplicationController < Sinatra::Base @account_message = "" @username = "" require 'bundler' Bundler.require ActiveRecord::Base.establish_connection( :adapter => 'mysql2', :database => 'musical_api2' ) set :public_folder, File.expand_path('../../public', __FILE__) set :views, File.expa...
bmarsha72/musical-api
controllers/artist_controller.rb
<reponame>bmarsha72/musical-api class ArtistController < ApplicationController end
fjuan/padel
test/unit/helpers/my_account_helper_test.rb
<filename>test/unit/helpers/my_account_helper_test.rb require 'test_helper' class MyAccountHelperTest < ActionView::TestCase end
fjuan/padel
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate_user! before_filter :set_locale private def set_locale I18n.locale = :es end end
fjuan/padel
app/controllers/calendars_controller.rb
class CalendarsController < ApplicationController def show @users_by_availability = User.by_availability @weekdays = %w(monday tuesday wednesday thursday friday saturday sunday) @date = params[:date] && Date.parse(params[:date]) || Date.today @beginning_of_week = @date.beginning_of_week @end_of_...
fjuan/padel
app/models/user.rb
<filename>app/models/user.rb class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable...
fjuan/padel
app/controllers/my_accounts_controller.rb
<reponame>fjuan/padel class MyAccountsController < ApplicationController def show @user = current_user @weekdays = %w(monday tuesday wednesday thursday friday saturday sunday) unless @user.has_name_and_phone? flash[:notice] = 'Please add your name and phone number' end end end
fjuan/padel
db/migrate/20130605185715_add_availability_fields_to_user.rb
class AddAvailabilityFieldsToUser < ActiveRecord::Migration def change weekdays = %w(monday tuesday wednesday thursday friday saturday sunday) (10..22).each do |hour| weekdays.each do |day| add_column :users, "#{day}_#{hour}", :boolean, default: false end end end end
fjuan/padel
db/schema.rb
<reponame>fjuan/padel # encoding: UTF-8 # 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...
fjuan/padel
app/controllers/users_controller.rb
class UsersController < ApplicationController def update @user = current_user respond_to do |format| if @user.update_attributes(params[:user]) format.json { respond_with_bip(@user) } else format.json { render json: @user.errors, status: :unprocessable_entity } end end ...
bugkingK/RxPagingKit
RxPagingKit.podspec
# # Be sure to run `pod lib lint StringStylizer.podspec' to ensure this is a # valid spec before submitting. # # Any lines starting with a # are optional, but their use is encouraged # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html # Pod::Spec.new do |s| s.name = "RxPag...
avinashtag/ZZPings
ZZPings.podspec
<reponame>avinashtag/ZZPings<filename>ZZPings.podspec Pod::Spec.new do |s| s.name = 'ZZPings' s.version = '1.0' s.summary = 'ZZPings return rtt and ttl for you and you are able to tell him the count of packets to send .' #s.description = 'simple ping return rtt' s.homepage ...
allred/augur
app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController http_basic_authenticate_with name: "augur", password: "<PASSWORD>" def index tc = TwitterClient.new @message_error = '' @client = tc.client if params[:mark_read] begin tweet = Tweet.find(params[:mark_read]) tweet.read = 1 ...
allred/augur
app/models/tweet.rb
class Tweet < ApplicationRecord end
allred/augur
lib/twitter_client.rb
<filename>lib/twitter_client.rb require 'twitter' class TwitterClient attr_accessor :client def initialize() @client = Twitter::REST::Client.new do |config| config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] || 'jZFm6u2gUshTozg8VRdLtNq3M' config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] ...
jayhendren/omnibus-software
config/software/curl.rb
# # Copyright 2012-2018 Chef Software, 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 ...
RKelln/riemann-ruby-client
lib/riemann/client/tcp.rb
require 'monitor' require 'riemann/client/tcp_socket' module Riemann class Client class TCP < Client attr_accessor :host, :port, :socket # Public: Set a socket factory -- an object responding # to #call(options) that returns a Socket object def self.socket_factory=(factory) @sock...
RKelln/riemann-ruby-client
lib/riemann/client/udp.rb
<reponame>RKelln/riemann-ruby-client<gh_stars>0 module Riemann class Client class UDP < Client MAX_SIZE = 16384 attr_accessor :host, :port, :socket, :max_size def initialize(opts = {}) @host = opts[:host] || HOST @port = opts[:port] || PORT @max_size = opts[:max_size] |...
t9md/atom-open-this
spec/fixtures/top.rb
# dir1/dir1 require "./dir1/dir1" # dir1/file1 # dir1/file2
icco/elb_processor
download.rb
require "rubygems" require "bundler" Bundler.require(:default, ENV["RACK_ENV"] || :development) require 'fileutils' def percentile(values, percentile) raise "Percentile must be < 1." if percentile > 1 values_sorted = values.sort k = (percentile*(values_sorted.length-1)+1).floor - 1 f = (percentile*(values_so...
yanske1/DramaNow
server/app/services/create_watch_list_service.rb
class CreateWatchListService def initialize(user) @user = user end def create watched_dramas = @user.user_dramas.eager_load(:drama, :watching_events).to_a # Get latest user_drama per drama latest_user_dramas_by_drama = watched_dramas.each_with_object({}) do |user_drama, hash| drama = user_...
yanske1/DramaNow
server/test/models/drama_test.rb
require 'test_helper' class DramaTest < ActiveSupport::TestCase test "drama can only be created on supported sites" do invalid_site = "not_a_site_dot_com" refute_includes Drama::ACCEPTED_SITES, invalid_site drama_one = dramas(:one) drama_one.site = invalid_site refute drama_one.save asse...
yanske1/DramaNow
server/db/migrate/20180817033842_set_null_to_dramas.rb
class SetNullToDramas < ActiveRecord::Migration[5.1] def change change_column :dramas, :title, :string, :null => false change_column :dramas, :site, :string, :null => false change_column :dramas, :link, :string, :null => false change_column :dramas, :latest_episode, :integer, :default => 0 end end
yanske1/DramaNow
server/config/routes.rb
Rails.application.routes.draw do resources :users, only: :create, constraints: { format: 'json' } do get 'valid', on: :collection get 'watch_list', on: :member resources :watching_events, only: :create end end
yanske1/DramaNow
server/app/services/create_watching_event_service.rb
class CreateWatchingEventService def initialize(params) @user_key = params[:user_id] @url = params[:url] @title = params[:title] @site = params[:site] @thumbnail = params[:thumbnail] @current_episode = params[:currentEpisode] @current_time = params[:currentTime] @episode_length = param...
yanske1/DramaNow
server/db/migrate/20180812205125_set_null_to_key.rb
class SetNullToKey < ActiveRecord::Migration[5.1] def change change_column :users, :key, :string, :null => false end end
yanske1/DramaNow
server/test/controllers/users_controller_test.rb
require 'test_helper' class UsersControllerTest < ActionDispatch::IntegrationTest setup do @stub_list_response = [{ title: "slug-me", episode: 2, link: "https://www.dramafever.com/drama/123/2/slug-me/", img: "www.img.com", timestamp: 10, }] end test "create does not respond...
yanske1/DramaNow
server/app/models/watching_event.rb
class WatchingEvent < ApplicationRecord belongs_to :user_drama validates :user_drama, presence: true validates :duration, presence: true, numericality: { only_integer: true } default_scope { order(duration: :asc) } def still_watching? return user_drama.episode_length - duration > 5.minutes.to_i end e...
yanske1/DramaNow
server/app/controllers/watching_events_controller.rb
<reponame>yanske1/DramaNow class WatchingEventsController < ApplicationController # POST /users/:user_id/watching_events.json def create create_watching_event = CreateWatchingEventService.new(watching_event_params) respond_to do |format| if create_watching_event.create format.json { render jso...
yanske1/DramaNow
server/test/services/create_watch_list_service_test.rb
<gh_stars>0 require 'test_helper' class CreateWatchListServiceTest < ActiveSupport::TestCase setup do @user = User.create! @service = CreateWatchListService.new(@user) @watching_event_service_params_episode_one = { user_id: @user.key, url: "https://www.dramafever.com/drama/123/1/slug-me/", ...
yanske1/DramaNow
server/db/schema.rb
<filename>server/db/schema.rb # 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 autho...
yanske1/DramaNow
server/app/models/user.rb
class User < ApplicationRecord has_many :user_dramas, dependent: :destroy validates :key, presence: true, uniqueness: true, length: { is: 6 } after_initialize :intialize_unique_key private def intialize_unique_key # While not unqiue, re-initialize while self.key.nil? key = SecureRandom.urlsa...
yanske1/DramaNow
server/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery with: :null_session before_action :destroy_session def destroy_session request.session_options[:skip] = true end end
yanske1/DramaNow
server/test/models/user_drama_test.rb
<reponame>yanske1/DramaNow<gh_stars>0 require 'test_helper' class UserDramaTest < ActiveSupport::TestCase test "user drama must belong to an existing user" do user_dramas(:one).user.destroy! userdrama = user_dramas(:one).dup refute userdrama.save assert_includes userdrama.errors.full_messages, "User...
yanske1/DramaNow
server/test/jobs/scrape_dramas_job_test.rb
require 'test_helper' class ScrapeDramasJobTest < ActiveJob::TestCase setup do @drama = dramas(:one).dup Drama.destroy_all end test "scrapes dramafever sites" do @drama.site = Drama::DRAMAFEVER @drama.latest_episode = 1 @drama.link = "https://www.dramafever.com/drama/5195/28/legend-of-fuyao-...
yanske1/DramaNow
server/app/jobs/scrape_dramas_job.rb
require 'nokogiri' require "watir" class ScrapeDramasJob < ApplicationJob queue_as :default def perform(*args) active_dramas = Drama.active active_dramas.each do |drama| doc = open_browser(drama.link) case drama.site when Drama::DRAMAFEVER latest_episode = parse_dramafever_site...
yanske1/DramaNow
server/test/services/create_watching_event_service_test.rb
require 'test_helper' class CreateWatchingEventServiceTest < ActiveSupport::TestCase setup do @user = users(:one) @drama = dramas(:one) @userdrama = user_dramas(:one) @create_watching_event_params = { user_id: @user.key, url: "www.dummy.link", title: @drama.title, site: @dr...
yanske1/DramaNow
server/db/migrate/20180817033552_create_dramas.rb
<gh_stars>0 class CreateDramas < ActiveRecord::Migration[5.1] def change create_table :dramas do |t| t.string :title t.string :site t.integer :latest_episode t.timestamp :latest_episode_update t.string :link t.string :thumbnail t.timestamps end add_index :dramas...
yanske1/DramaNow
server/app/controllers/users_controller.rb
class UsersController < ApplicationController # POST /users.json def create @user = User.new respond_to do |format| if @user.save format.json { render json: @user.key, status: :created } else format.json { render json: @user.errors, status: :unprocessable_entity } end ...
yanske1/DramaNow
server/db/migrate/20180817153935_create_user_dramas.rb
class CreateUserDramas < ActiveRecord::Migration[5.1] def change create_table :user_dramas do |t| t.references :user, foreign_key: true, null: false t.references :drama, foreign_key: true, null: false t.integer :episode_number, null: false t.integer :episode_length, null: false t.ti...
yanske1/DramaNow
server/test/models/user_test.rb
<gh_stars>0 require 'test_helper' class UserTest < ActiveSupport::TestCase test "should intialize user with key length 6" do user = User.new assert_predicate user.key, :present? assert_equal user.key.length, 6 user.save! end test "should not create user with non unique key" do user_one = Use...
yanske1/DramaNow
server/test/controllers/watching_events_controller_test.rb
require 'test_helper' class WatchingEventsControllerTest < ActionDispatch::IntegrationTest test "create does not respond to html" do assert_raise ActionController::UnknownFormat do post user_watching_events_url("123"), params: { format: :html } end end test "return created if watching event create...
yanske1/DramaNow
server/config/initializers/scheduler.rb
<filename>server/config/initializers/scheduler.rb require 'rufus-scheduler' scheduler = Rufus::Scheduler.singleton scheduler.every '4h' do ScrapeDramasJob.perform_now end
yanske1/DramaNow
server/app/models/user_drama.rb
<filename>server/app/models/user_drama.rb class UserDrama < ApplicationRecord # Represents an episode that a user is watching belongs_to :user belongs_to :drama has_many :watching_events, dependent: :destroy validates :user, presence: true validates :drama, presence: true validates :episode_number, prese...
yanske1/DramaNow
server/app/models/drama.rb
<reponame>yanske1/DramaNow class Drama < ApplicationRecord include ActiveModel::Dirty has_many :user_dramas, dependent: :destroy DRAMAFEVER = 'dramafever' ACCEPTED_SITES = [DRAMAFEVER].freeze validates :title, presence: true, format: { with: /\A[a-zA-Z0-9-]+\Z/ } validates :site, presence: true, inclusio...
yanske1/DramaNow
server/test/models/watching_event_test.rb
require 'test_helper' class WatchingEventTest < ActiveSupport::TestCase test "watching event must belong to existing user drama" do watching_event = watching_events(:one).dup watching_event.user_drama_id = 0 refute watching_event.save assert_includes watching_event.errors.full_messages, "User drama ...
twp88/primus
spec/primus_spec.rb
<gh_stars>0 require 'spec_helper' describe Hashify do subject { Hashify } context 'when passing primus a long hash' do let(:long_hash) do { 'a' => 'This', 'b' => 'is', 'c' => 'a', 'd' => 'longish', 'e' => 'hash', 'f' => 'for', 'g' => 'testing', ...
twp88/primus
no_new.rb
<gh_stars>0 require './lib/primus' include Primus hash = { 'a' => 1, 'b' => 2, 'c' => 3 } puts call(hash)
twp88/primus
lib/primus.rb
# frozen_string_literal: true require 'primus/version' # Takes a hash and returns string of reverse order odd keys class Hashify def self.call(hash) raise 'This hash is empty' if hash.empty? array = hash.each_with_index.map { |(key), index| key.upcase if index.odd? }.compact array.sort.reverse.join('') ...
vicki29644/Super_hero_cli
lib/cli.rb
Class Cli def run puts "Cli class loaded" end end