repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
kronus/angular-ruby-2014-example
config/routes.rb
<reponame>kronus/angular-ruby-2014-example CafeTownsendAngularRails::Application.routes.draw do get 'login', to: 'sessions#create', as: :login resources :sessions resources :employees root to: 'sessions#create' end
kronus/angular-ruby-2014-example
app/views/employees/index.json.jbuilder
json.array!(@employees) do |employee| json.cache! employee do json.extract! employee, :id, :first_name, :last_name, :email, :start_date end end
kronus/angular-ruby-2014-example
app/models/user.rb
<reponame>kronus/angular-ruby-2014-example class User < ActiveRecord::Base has_secure_password validates_presence_of :password, on: :create end
kronus/angular-ruby-2014-example
spec/factories/users.rb
<filename>spec/factories/users.rb require 'faker' FactoryGirl.define do fake_password = <PASSWORD>(5) factory :user do name { Faker::Name.first_name } password <PASSWORD> password_confirmation <PASSWORD> end end
kronus/angular-ruby-2014-example
spec/factories/employees.rb
<gh_stars>10-100 require 'faker' FactoryGirl.define do factory :employee do first_name { Faker::Name.first_name } last_name { Faker::Name.last_name } email { Faker::Internet.email } start_date { Date.today-rand(10_000) } end end
kronus/angular-ruby-2014-example
spec/support/controller_macros.rb
module ControllerMacros def login_user(user) session[:user_id] = user.id end end
kronus/angular-ruby-2014-example
spec/models/user_spec.rb
<reponame>kronus/angular-ruby-2014-example<filename>spec/models/user_spec.rb require'spec_helper' describe 'User' do context "valid params" do it 'build an user' do expect(build(:user)).to be_valid end end context "invalid params" do it "without a password" do expect(build(:user, passwor...
kronus/angular-ruby-2014-example
config/initializers/session_store.rb
# Be sure to restart your server when you modify this file. CafeTownsendAngularRails::Application.config.session_store :cookie_store, key: '_CafeTownsend-Angular-Rails_session'
kronus/angular-ruby-2014-example
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_filter :render_single_page private def ensure_authenticated if session[:user_id].blank? render :json => { authorized: false } end end def render_single_page render 'layouts/application' if ...
kronus/angular-ruby-2014-example
spec/controllers/sessions_controller_spec.rb
<reponame>kronus/angular-ruby-2014-example require 'spec_helper' describe SessionsController do let!(:user_created) { create(:user) } # saved in db before :each do # avoid rendering html of single page app (RSpec only) request.env["HTTP_ACCEPT"] = "application/json" end # create # ----------------...
kronus/angular-ruby-2014-example
spec/models/employee_spec.rb
<filename>spec/models/employee_spec.rb require'spec_helper' describe 'Employee' do it 'should be valid' do expect(build(:employee)).to be_valid end it "should invalid without a first name" do expect(build(:employee, first_name: '')).to_not be_valid end it "should invalid without a last name" do ...
kronus/angular-ruby-2014-example
app/controllers/sessions_controller.rb
<reponame>kronus/angular-ruby-2014-example class SessionsController < ApplicationController respond_to :json # POST /sessions def create user = User.find_by(name: params[:name]) if user && user.authenticate(params[:password]) session[:user_id] = user.id render json: { user: user, authorized:...
kronus/angular-ruby-2014-example
config/initializers/formtastic.rb
<reponame>kronus/angular-ruby-2014-example module Formtastic module DatePicker protected def datepicker_input(method, options = {}) format = options[:format] || ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] || '%d %b %Y' string_input(method, datepicker_options(format, ...
kronus/angular-ruby-2014-example
app/controllers/employees_controller.rb
<filename>app/controllers/employees_controller.rb<gh_stars>0 class EmployeesController < ApplicationController before_filter :ensure_authenticated before_filter :set_employee, :except => [:index, :create] respond_to :json # GET /employees # GET /employees.json def index @employees = Employee.all en...
noisegaze/cli_project
lib/list.rb
require 'net/http' require 'open-uri' require 'json' #require 'open-ssl' require 'pry' class List attr_accessor :city, :state @@all = [] def initialize(city,state) @city = city @state = state #save end def location(location_endpoint_url) location_query = @city + "," ...
noisegaze/cli_project
lib/reference.rb
require 'uri' require 'net/http' require 'openssl' url = URI("https://worldwide-restaurants.p.rapidapi.com/search") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request["x-rapidapi-host"] = 'worldwide-restaurants.p.rapida...
lryndavis/ruby_recipes
lib/recipe.rb
class Recipe < ActiveRecord::Base has_and_belongs_to_many(:tags) has_and_belongs_to_many(:ingredients) validates(:recipe_name, :presence => true) before_save(:titleize_recipe_name) private define_method(:titleize_recipe_name) do self.recipe_name=(recipe_name().titleize()) end end
lryndavis/ruby_recipes
spec/ingredient_spec.rb
<reponame>lryndavis/ruby_recipes require('spec_helper') describe(Ingredient) do it("converts the ingredient entry to titlecase") do ingredient = Ingredient.create({:ingredient_name => "pepper"}) expect(ingredient.ingredient_name()).to(eq("Pepper")) end end
lryndavis/ruby_recipes
spec/tag_spec.rb
require('spec_helper') describe(Tag) do it("converts the tag to titlecase") do tag = Tag.create({:category => "vegan"}) expect(tag.category()).to(eq("Vegan")) end it("validates presence of a tag entry") do tag = Tag.new({:category => ""}) expect(tag.save()).to(eq(false)) end end
lryndavis/ruby_recipes
lib/tag.rb
<filename>lib/tag.rb class Tag < ActiveRecord::Base has_and_belongs_to_many(:recipes) validates(:category, :presence => true) before_save(:titleize_category) private define_method(:titleize_category) do self.category=(category().titleize()) end end
lryndavis/ruby_recipes
spec/recipe_integration_spec.rb
<reponame>lryndavis/ruby_recipes<filename>spec/recipe_integration_spec.rb require('spec_helper') describe('ability to add a new recipe to the application', {:type => :feature}) do it('allows a user to add a new recipe to the list of recipes') do visit('/') fill_in('recipe_name', :with => "<NAME>") ...
lryndavis/ruby_recipes
spec/recipe_spec.rb
require('spec_helper') describe(Recipe) do it("converts the recipe name to titlecase") do recipe = Recipe.create({:recipe_name => "potato soup"}) expect(recipe.recipe_name()).to(eq("Potato Soup")) end it("validates presence of a recipe name entry") do recipe = Recipe.new({:recipe_name => ""}) expect(r...
lryndavis/ruby_recipes
lib/ingredient.rb
<filename>lib/ingredient.rb class Ingredient < ActiveRecord::Base has_and_belongs_to_many(:recipes) before_save(:titleize_ingredient_name) private define_method(:titleize_ingredient_name) do self.ingredient_name=(ingredient_name().titleize()) end end
ankane/toucan
toucan.rb
require "redis" class Toucan def initialize @redis = Redis.new @prefix = "toucan" end def add_event(timestamp, category, key, value, properties = {}, properties_with_counts = {}) timestamp = timestamp.to_i pairs = {} begin pairs[key.join(".")] = value end while key.pop and !key.em...
ankane/toucan
examples.rb
require "rubygems" require "bundler/setup" require "pp" require_relative "toucan" toucan = Toucan.new toucan.add_event(Time.now, "url", ["com", "amazon", "music"], 1) toucan.add_event(Time.now, "url", ["com", "facebook", "www"], 1) puts "minute - com" pp toucan.minute_counts("url", ["com"]) puts puts "hour - amazon...
ankane/toucan
benchmark.rb
<reponame>ankane/toucan<filename>benchmark.rb require "rubygems" require "bundler/setup" require "benchmark" require_relative "toucan" toucan = Toucan.new bm = Benchmark.measure do # 12x incr (= 12000 incr/sec) # can get 30000 incr/sec with node 1000.times do toucan.add_event(Time.now.to_i, "url", ["com", "...
hkleindl/list-app-backend
app/models/user.rb
<gh_stars>0 class User < ApplicationRecord has_secure_password has_many :lists validates :username, presence: true end
hkleindl/list-app-backend
db/seeds.rb
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Ch...
hkleindl/list-app-backend
app/controllers/api/v1/lists_controller.rb
<reponame>hkleindl/list-app-backend<filename>app/controllers/api/v1/lists_controller.rb class Api::V1::ListsController < ApplicationController before_action :set_list, only: [:show, :update, :destroy] # GET /lists def index if logged_in? @lists = current_user.lists render json: ListSerializer.new...
hkleindl/list-app-backend
app/serializers/item_serializer.rb
class ItemSerializer include FastJsonapi::ObjectSerializer attributes :content, :is_complete # belongs_to :list, record_type: :list end
hkleindl/list-app-backend
app/models/list.rb
<reponame>hkleindl/list-app-backend<filename>app/models/list.rb class List < ApplicationRecord belongs_to :user has_many :items end
hkleindl/list-app-backend
app/serializers/list_serializer.rb
class ListSerializer include FastJsonapi::ObjectSerializer attributes :name, :items # belongs_to :user, record_type: :user # has_many :items end
kbredemeier/elastic_adatper
spec/unit/document_type_spec.rb
<reponame>kbredemeier/elastic_adatper require "spec_helper" module ElasticAdapter describe DocumentType do let(:mappings) do { name: { type: "string", index_analyzer: "shingle_analyzer" } } end let(:name) { "test_index" } let(:subject) { DocumentType....
kbredemeier/elastic_adatper
elastic_adapter.gemspec
<filename>elastic_adapter.gemspec # coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'elastic_adapter/version' Gem::Specification.new do |spec| spec.name = "elastic_adapter" spec.version = ElasticAdapter::VERSION spec.authors ...
kbredemeier/elastic_adatper
spec/integration/index/suggest_spec.rb
<reponame>kbredemeier/elastic_adatper<filename>spec/integration/index/suggest_spec.rb<gh_stars>0 require_relative"./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#suggest", :vcr do before :all do create_test_index doc1 = {id: 1, fo...
kbredemeier/elastic_adatper
examples/basic_usage.rb
<filename>examples/basic_usage.rb require "elastic_adapter" mappings = { product: { properties: { name: { type: "string", index_analyzer: "simple", search_analyzer: "simple" }, name_suggest: { type: "completion" }, price: { type: "float", ...
kbredemeier/elastic_adatper
spec/integration/index/count_spec.rb
require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#count", :vcr do context "empty index" do before :all do create_test_index end after :all do delete_test_index end befo...
kbredemeier/elastic_adatper
spec/integration/index/shared_context.rb
<gh_stars>0 require "spec_helper" RSpec.shared_context "index context" do let(:name) { "test_index" } let(:mappings) do { test_index: { properties: { foo: { type: "string", foo_suggest: { type: "completion" } } } } } end let(:docum...
kbredemeier/elastic_adatper
spec/unit/elastic_adapter_spec.rb
require "spec_helper" module ElasticAdapter end
kbredemeier/elastic_adatper
lib/elastic_adapter/document_type.rb
<reponame>kbredemeier/elastic_adatper<gh_stars>0 # rubocop:disable Metrics/LineLength module ElasticAdapter # This class is intended to hold information about # a document in an elasticsearch index # # @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html Elasticsearch Mappings...
kbredemeier/elastic_adatper
spec/integration/index/unit_spec.rb
<filename>spec/integration/index/unit_spec.rb require_relative "./shared_context.rb" module ElasticAdapter describe Index do describe "unit specs" do include_context "index context" describe "#initialize" do it "assigns the name" do expect(subject.instance_variable_get('@name')).to...
kbredemeier/elastic_adatper
spec/support/index_helper.rb
<reponame>kbredemeier/elastic_adatper module IndexHelper WAIT_TIME = 3 def test_index(name = "test_index", options = {}) params = { name: name, url: "http://localhost:9200", log: true, settings: {}, document_type: OpenStruct.new( name: "test_doc", mappings: { ...
kbredemeier/elastic_adatper
lib/elastic_adapter/index.rb
module ElasticAdapter # This class encapsulates the access to a Elasticsearch::Transport::Client # and provides an implementation of the repository pattern # # @attr_reader [String] name the name of the index # @attr_reader [Hash] settings the index settings # @attr_reader [DocumentType] document_type a Doc...
kbredemeier/elastic_adatper
spec/integration/index/validate_spec.rb
require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#validate", :vcr do before :all do create_test_index end after :all do delete_test_index end context "invalid query" do let(:query)...
kbredemeier/elastic_adatper
spec/integration/index/search_spec.rb
require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#search", :vcr do before :all do create_test_index index_documents(id: 1, foo: "bar", foo_suggest: {input: "bar"}) index_documents(id: 2, foo: "zoo", foo_sug...
kbredemeier/elastic_adatper
spec/integration/index/aggregation_spec.rb
<filename>spec/integration/index/aggregation_spec.rb require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#aggregate", :vcr do before :all do create_test_index index_documents foo: "bar", group: "A" index_docum...
kbredemeier/elastic_adatper
lib/elastic_adapter.rb
<gh_stars>0 require "elasticsearch" require "elastic_adapter/version" require "elastic_adapter/document_type" require "elastic_adapter/index" begin require "pry" rescue LoadError end module ElasticAdapter end
kbredemeier/elastic_adatper
spec/integration/index/get_spec.rb
<reponame>kbredemeier/elastic_adatper<filename>spec/integration/index/get_spec.rb require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#get", :vcr do context "document exists" do let(:document) { {id: "1", foo: "bar"} } ...
kbredemeier/elastic_adatper
lib/elastic_adapter/version.rb
module ElasticAdapter VERSION = "0.2.0" end
kbredemeier/elastic_adatper
spec/integration/index/index_spec.rb
require_relative "./shared_context.rb" module ElasticAdapter describe Index do include_context "index context" describe "#index", :vcr do context "new document" do let(:document) { { foo: "bar" } } before :all do create_test_index end after :all do ...
kbredemeier/elastic_adatper
spec/unit/index_spec.rb
require "spec_helper" module ElasticAdapter describe Index do let(:name) { "test_index" } let(:mappings) do { test_index: { properties: { foo: { type: "string", foo_suggest: { type: "completion" } } } } } ...
beplus/fastlane-plugin-versioning-ios
lib/fastlane/plugin/versioning_ios/helper/versioning_ios_helper.rb
module Fastlane module Helper class VersioningIosHelper require "shellwords" XCODEPROJ_TEST = "/tmp/fastlane/tests/versioning/Project.xcodeproj" def self.get_xcodeproj(xcodeproj) return Helper.test? ? XCODEPROJ_TEST : xcodeproj end def self.get_xcodeproj_path(xcodeproj) ...
beplus/fastlane-plugin-versioning-ios
spec/versioning_ios_helper_spec.rb
<reponame>beplus/fastlane-plugin-versioning-ios<filename>spec/versioning_ios_helper_spec.rb require 'spec_helper' describe Fastlane::Helper::VersioningIosHelper do describe "Versioning iOS Helper" do it "should return path to Xcode project" do result = Fastlane::Helper::VersioningIosHelper.get_xcodeproj(ni...
beplus/fastlane-plugin-versioning-ios
spec/ios_set_build_number_action_spec.rb
require 'spec_helper' describe Fastlane::Actions::IosSetBuildNumberAction do describe "Set Build Number" do before do copy_project_files_fixture end it "should increment Build Number and return its new value" do result = Fastlane::FastFile.new.parse('lane :test do ios_set_build_numbe...
beplus/fastlane-plugin-versioning-ios
lib/fastlane/plugin/versioning_ios/version.rb
module Fastlane module VersioningIos VERSION = "0.1.0" end end
beplus/fastlane-plugin-versioning-ios
lib/fastlane/plugin/versioning_ios/actions/ios_set_version.rb
module Fastlane module Actions module SharedValues IOS_NEW_VERSION = :IOS_NEW_VERSION end class IosSetVersionAction < Action # More information about how to set up your project and how it works: # https://developer.apple.com/library/ios/qa/qa1827/_index.html # Attention: This is N...
beplus/fastlane-plugin-versioning-ios
spec/spec_helper.rb
<filename>spec/spec_helper.rb $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'simplecov' # SimpleCov.minimum_coverage 95 SimpleCov.start # This module is only used to check the environment is currently a testing env module SpecHelper end require 'fastlane' # to import the Action super class requ...
beplus/fastlane-plugin-versioning-ios
lib/fastlane/plugin/versioning_ios/actions/ios_get_version.rb
<reponame>beplus/fastlane-plugin-versioning-ios module Fastlane module Actions module SharedValues IOS_VERSION = :IOS_VERSION end class IosGetVersionAction < Action # More information about how to set up your project and how it works: # https://developer.apple.com/library/ios/qa/qa1827/...
beplus/fastlane-plugin-versioning-ios
lib/fastlane/plugin/versioning_ios/actions/ios_set_build_number.rb
module Fastlane module Actions module SharedValues IOS_NEW_BUILD_NUMBER = :IOS_NEW_BUILD_NUMBER end class IosSetBuildNumberAction < Action # More information about how to set up your project and how it works: # https://developer.apple.com/library/ios/qa/qa1827/_index.html # Attent...
beplus/fastlane-plugin-versioning-ios
spec/ios_get_build_number_action_spec.rb
require 'spec_helper' describe Fastlane::Actions::IosGetBuildNumberAction do describe "Get Build Number" do before do copy_project_files_fixture end it "should return Build Number from Xcode project file" do result = Fastlane::FastFile.new.parse('lane :test do ios_get_build_number ...
beplus/fastlane-plugin-versioning-ios
spec/ios_set_version_action_spec.rb
require 'spec_helper' describe Fastlane::Actions::IosSetVersionAction do describe "Set Version" do before do copy_project_files_fixture end it "should set Version to specific value" do result = Fastlane::FastFile.new.parse('lane :test do ios_set_version(version: "2.34.5") end')...
takamario/imgix-rails
lib/imgix/rails/tag.rb
require "imgix/rails/url_helper" require "action_view" class Imgix::Rails::Tag include Imgix::Rails::UrlHelper include ActionView::Helpers def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_options: {}) @path = path @source = source @tag_options = tag_options @url_params =...
takamario/imgix-rails
lib/imgix/rails/url_helper.rb
module Imgix module Rails class ConfigurationError < StandardError; end module UrlHelper def ix_image_url(*args) validate_configuration! case args.size when 1 path = args[0] source = nil params = {} when 2 if args[0].is_a?(String)...
railsrumble/r13-team-46
app/helpers/tasks_helper.rb
<filename>app/helpers/tasks_helper.rb module TasksHelper def task_summary(task) result = [ task.time_expression, "I want to", task.action ].join(" ") truncate(result, length: 50) end def task_scheduled_class(task) 'not-scheduled' unless task.recurrence.try(:next_at) end end
railsrumble/r13-team-46
lib/tasks/guest.rake
<filename>lib/tasks/guest.rake namespace :guest do desc "Setup Guest User" task reset: :environment do User.where(is_guest: true).destroy_all guest = User.create( email: "<EMAIL>", password: "<PASSWORD>", is_guest: true ) CreateTask.create({ user_id: guest.id, time_exp...
railsrumble/r13-team-46
spec/models/task_spec.rb
<reponame>railsrumble/r13-team-46 require 'model_spec_helper' describe Task do it { should validate_presence_of(:action) } it { should validate_presence_of(:time_expression) } it { should validate_presence_of(:user_id) } context "using repository" do let(:attributes) { build_attributes_for(:task) } c...
railsrumble/r13-team-46
app/services/handle_recurrences.rb
class HandleRecurrences def self.perform new.perform end def recurrences Recurrence.ready end def perform recurrences.each do |recurrence| handle_recurrence(recurrence) end end def handle_recurrence(recurrence) recurrence_hooks.each do |hook| send(hook, recurrence) e...
railsrumble/r13-team-46
app/helpers/recurrences_helper.rb
<filename>app/helpers/recurrences_helper.rb module RecurrencesHelper def recurrence_human_next_at(recurrence) recurrence_human_date(recurrence, :next_at, "Not planned yet") end def recurrence_human_last_at(recurrence) recurrence_human_date(recurrence, :last_at, "Not reminded yet") end def recurrence...
railsrumble/r13-team-46
app/repositories/create_repository.rb
class CreateRepository class << self %w( create create! ).each do |sym| define_method sym do |*args| new.send(sym, *args) end end end def klass self.class.name.gsub(/^Create/, '').constantize end %w( create create! ).each do |sym| define_method sym do |hash| sanitiz...
railsrumble/r13-team-46
app/models/ability.rb
class Ability include CanCan::Ability def initialize(user) user ||= User.new cannot :manage, Task can :manage, Task, user_id: user.id end end
railsrumble/r13-team-46
spec/support/devise.rb
<filename>spec/support/devise.rb RSpec.configure do |config| config.include Devise::TestHelpers, type: :controller end module DeviseHelperMethods include Warden::Test::Helpers def sign_in(user) login_as user, scope: :user end end RSpec.configuration.include DeviseHelperMethods, type: :feature
railsrumble/r13-team-46
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, :omniauthable, :recoverable, :rememberable, :trackabl...
railsrumble/r13-team-46
spec/model_spec_helper.rb
require 'unit_spec_helper' require 'active_record' require 'devise' db_yml_file = File.expand_path('config/database.yml') template = ERB.new(File.new(db_yml_file).read, nil, "%") db_config = YAML.load(template.result(binding)) ActiveRecord::Base.establish_connection(db_config['test']) require File.join(RAILS_ROOT, "c...
railsrumble/r13-team-46
app/repositories/update_task.rb
class UpdateTask < Struct.new(:task) def perform(attributes) if task.update_attributes(attributes) SyncTaskRecurrence.new(task).perform end end end
railsrumble/r13-team-46
spec/factories/recurrences.rb
FactoryGirl.define do factory :recurrence do task auto_schedule false expression "day" next_at "2013-10-19 10:56:03" starting_at "2013-10-19 10:56:03" until_at "2013-10-21 10:56:03" end end
railsrumble/r13-team-46
spec/factories/tasks.rb
FactoryGirl.define do factory :task do user action "code hard" time_expression "every day" end end
railsrumble/r13-team-46
spec/support/capybara.rb
require 'capybara/rspec' Capybara.javascript_driver = :webkit class WarningSuppressor WARNINGS = [ /content-type missing in HTTP POST/, /QNetworkReplyImplPrivate::error/ ] def self.write(message) puts(message) unless WARNINGS.any? { |w| message =~ w } return 0 end end Capybara.register_drive...
railsrumble/r13-team-46
spec/repositories/update_task_spec.rb
<reponame>railsrumble/r13-team-46<filename>spec/repositories/update_task_spec.rb require 'unit_spec_helper' describe UpdateTask do let(:task) { stub } let(:service) { stub } let(:attributes) { stub } let(:repository) { UpdateTask.new(task) } before do task.stubs(:update_attributes).with(attributes).retu...
railsrumble/r13-team-46
app/helpers/devise_helper.rb
<reponame>railsrumble/r13-team-46 module DeviseHelper def devise_error_messages! flash[:alert] ||= [] resource.errors.full_messages.map { |msg| flash[:alert] << content_tag(:p, msg) }.join end end
railsrumble/r13-team-46
lib/tasks/handle_recurrences.rake
namespace :handle_recurrences do desc "Send mail for every passed recurrence" task perform: :environment do HandleRecurrences.perform end task daemon: :environment do while true sleep 10 HandleRecurrences.perform end end end
railsrumble/r13-team-46
db/migrate/20131019232453_add_last_at_on_recurrences.rb
class AddLastAtOnRecurrences < ActiveRecord::Migration def change add_column :recurrences, :last_at, :datetime end end
railsrumble/r13-team-46
spec/repositories/create_task_spec.rb
<reponame>railsrumble/r13-team-46<gh_stars>0 require 'unit_spec_helper' describe CreateTask do let(:repository) { CreateTask.new } let(:attributes) { stub } let(:task) { stub(persisted?: true) } before do repository.stubs(:after_create_hooks).returns([]) end it 'should delegate creation' do Task....
railsrumble/r13-team-46
db/migrate/20131019085947_rename_recurrence_fields.rb
<reponame>railsrumble/r13-team-46 class RenameRecurrenceFields < ActiveRecord::Migration def change rename_column :recurrences, :next, :next_at rename_column :recurrences, :starting, :starting_at rename_column :recurrences, :until, :until_at end end
railsrumble/r13-team-46
app/concerns/active_record_helpers.rb
module ActiveRecordHelpers def self.included(base) base.extend ClassMethods end module ClassMethods def find_for_oauth(auth) record = where(provider: auth.provider, uid: auth.uid.to_s).first record || ( if existing_user = where(email: auth.info.email).first existing_user.t...
railsrumble/r13-team-46
spec/support/factory_girl.rb
module FactoryGirlHelpers def build_attributes_for(*args) obj = FactoryGirl.build(*args) obj.attributes.each_with_object({}) do |(key, _), result| sym = key.to_sym result[sym] = obj.send(sym) end end end RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.incl...
railsrumble/r13-team-46
spec/models/recurrence_spec.rb
require 'spec_helper' describe Recurrence do end
railsrumble/r13-team-46
app/services/sync_task_recurrence.rb
class SyncTaskRecurrence < Struct.new(:task) def user task.user end def perform if result = Tickle.parse(task.time_expression) result = OpenStruct.new(result) Recurrence.sync_with_task(task.id, { expression: result.expression, starting_at: moment_with_timezone(result.starting...
railsrumble/r13-team-46
spec/mailers/recurrence_mailer_spec.rb
require "spec_helper" describe RecurrenceMailer do end
railsrumble/r13-team-46
spec/support/rspec_config.rb
<gh_stars>0 require 'bourne' RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end config.mock_with :mocha config.order = "random" if defined?(Rails) config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = false config.infer_bas...
railsrumble/r13-team-46
config/initializers/session_store.rb
# Be sure to restart your server when you modify this file. ActiveRecord::SessionStore::Session.attr_accessible :data, :session_id Evry::Application.config.session_store :active_record_store
railsrumble/r13-team-46
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_filter :save_user_time_zone, if: :current_user around_filter :set_user_time_zone, if: :current_user rescue_from CanCan::AccessDenied do |exception| flash[:alert] = "You are not allowed to see that" redire...
railsrumble/r13-team-46
app/models/recurrence.rb
<filename>app/models/recurrence.rb class Recurrence < ActiveRecord::Base belongs_to :task attr_accessible :task_id, :expression, :starting_at, :next_at, :until_at, :last_at delegate :user, to: :task scope :ready, -> { where('recurrences.next_at <= ?', Time.now) } def self.sync_with_task(task_id, attribute...
railsrumble/r13-team-46
app/services/time_zone_converter.rb
class TimeZoneConverter def self.convert(moment, user) offset = Time.use_zone(user.time_zone) do Time.zone.now.utc_offset end moment.advance(seconds: -1 * offset) if moment end end
railsrumble/r13-team-46
app/helpers/application_helper.rb
module ApplicationHelper def ui_button(title, link, button_options, options = {}) link_to title, link, options.merge(class: "ui #{button_options} button") end def ui_icon_button(title, css_class, link, button_options, options = {}) link_to link, options.merge(class: "ui " + button_options + " button") d...
railsrumble/r13-team-46
spec/factories/users.rb
<filename>spec/factories/users.rb FactoryGirl.define do factory :user do sequence(:email) { |n| "<EMAIL>" } password '<PASSWORD>' time_zone 'Europe/Rome' end end
railsrumble/r13-team-46
config/routes.rb
<reponame>railsrumble/r13-team-46<gh_stars>0 Evry::Application.routes.draw do root to: "static#welcome" get '/static/welcome' => 'static#welcome' get '/static/logged' => 'static#logged' get '/static/new' => 'static#new' get '/static/list' => 'static#list' get '/static/edit' => 'static#edit' devise_for :...
railsrumble/r13-team-46
spec/services/handle_recurrences_spec.rb
require 'unit_spec_helper' describe HandleRecurrences do let(:service) { HandleRecurrences.new } context "#recurrences" do it 'fetches all recurrences' do Recurrence.expects(:ready) service.recurrences end end context "#perform" do before do service.stubs(:recurrences).returns(r...
railsrumble/r13-team-46
spec/support/timecop.rb
module TimecopHelperMethods def back_to_future(options) now = Time.now Timecop.travel(now.advance(options)) end end RSpec.configuration.include TimecopHelperMethods, type: :feature
railsrumble/r13-team-46
spec/services/sync_task_recurrence_spec.rb
require 'unit_spec_helper' describe SyncTaskRecurrence do context "add recurrence" do let(:task) { stub(id: 666, user: user, time_expression: 'time expression', errors: errors) } let(:user) { stub(time_zone: 'Europe/Rome') } let(:errors) { stub } let(:result) { stub_everything } let(:service) { S...
railsrumble/r13-team-46
app/controllers/static_controller.rb
class StaticController < ApplicationController def welcome if user_signed_in? redirect_to tasks_url else render 'welcome', layout: 'homepage' end end def logged end def new end def list end def edit end end