code
stringlengths
1
1.73M
language
stringclasses
1 value
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirect...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run BuffaloKids::Application
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', ...
Ruby
# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use yo...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
Ruby
# Be sure to restart your server when you modify this file. BuffaloKids::Application.config.session_store :cookie_store, key: '_buffalo_kids_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.ac...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the we...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the tes...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application BuffaloKids::Application.initialize!
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
BuffaloKids::Application.routes.draw do get "books/index" => "books#index" post "book_reservations/new/:book_id" => "book_reservations#new" post "book_reservations/delete/:book_reservation_id" => "book_reservations#delete" get "book_reservations/index/:page" => "book_reservations#index" get "book_reserva...
Ruby
module ApplicationHelper end
Ruby
module UserHelper end
Ruby
class BookInstance < ActiveRecord::Base attr_accessible :book_instance_code, :user_id, :book_id, :photo_registration_id, :book_reservation_id belongs_to :book belongs_to :book_reservation belongs_to :photo_registration validates_presence_of :book_instance_code; validates_uniqueness_of :book_instance_code; ...
Ruby
class PhotoRegistration < ActiveRecord::Base attr_accessible :user_id, :finish_date, :quantity belongs_to :user has_one :book_instance has_one :book, :through => :book_instance self.per_page = 12 end
Ruby
class Book < ActiveRecord::Base attr_accessible :title, :book_code, :description, :author, :image_url, :release_date, :rating validates_uniqueness_of :title, :book_code validates_presence_of :title, :book_code before_validation :default_image_url ...
Ruby
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, :confirmable # Setup acc...
Ruby
class BookReservation < ActiveRecord::Base attr_accessible :user_id, :start_date, :due_date, :extention_days belongs_to :user has_one :book_instance has_one :book, :through => :book_instance self.per_page = 12 end
Ruby
class Notice < ActiveRecord::Base attr_accessible :title, :content, :user_id validates :title, :content, :presence => true belongs_to :user self.per_page = 12 def short_content self.content.truncate(90) end end
Ruby
class BookReservationsController < ApplicationController before_filter :authenticate_user!, :except => [:home] def home @books = Book.paginate(:page => params[:page]) end def new book = Book.find_by_id(params[:book_id]) if current_user.book_reservations.map{ |a| a.book }.include? book #send...
Ruby
class PhotoRegistrationsController < ApplicationController before_filter :authenticate_user!, :except => [:home] def home @books = Book.paginate(:page => params[:page]) end def new book = Book.find_by_id(params[:book_id]) if current_user.photo_registrations.map{ |a| a.book }.include? book #s...
Ruby
class EtcsController < ApplicationController def faq end def contact end def set_en if current_user.nil? session[:lang] = "en" else current_user.locale = "en" current_user.save end redirect_to params[:path] end def set_vi if current_user.nil? session[:lang] =...
Ruby
class BooksController < ApplicationController # phan cua Viet before_filter :authenticate_user! before_filter :authorized_user?, :except => [:show] def authorized_user? redirect_to(root_path) unless current_user && (current_user.librarian? || current_user.admin?) end def index @books = Boo...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale def set_locale if current_user.nil? I18n.locale = session[:lang].nil? ? "en" : session[:lang] else I18n.locale = current_user.locale end end def after_sign_in_path_for(resource_or_scope) case...
Ruby
class BookInstancesController < ApplicationController before_filter :authenticate_user!,:authorized_user? def authorized_user? redirect_to(root_path) unless current_user && (current_user.librarian? || current_user.admin?) end def index @book = Book.find(params[:book_id]) if @book.nil? # send er...
Ruby
class NoticesController < ApplicationController before_filter :authenticate_user! def authorized_user? redirect_to(root_path) unless current_user && (current_user.librarian? || current_user.admin?) end def index @notices = Notice.paginate(:page => params[:page]) end def show @notice = Not...
Ruby
class UsersController < ApplicationController before_filter :authenticate_user!,:authorized_user? def authorized_user? redirect_to(root_path) unless current_user && current_user.admin? end def index @users = User.paginate(:page => params[:page]) end def show @user = User.find_by_id(params[:user_id]) end...
Ruby
#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) BuffaloKids::Application.load_tasks
Ruby
#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) BuffaloKids::Application.load_tasks
Ruby
source 'https://rubygems.org' gem 'rails', '3.2.8' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' group :development, :test do gem 'mysql2' end # group :production do # gem 'pg' # end gem "mysql2" gem 'haml', '3.1.7' gem 'devise', '2.1.2' gem 'jquery-rails', '2.1.2' gem ...
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_to...
Ruby
class CreateBooks < ActiveRecord::Migration def change create_table :books do |t| t.string :title t.string :book_code t.text :description t.string :author t.string :category t.date :release_date t.string :image_url t.string :rating t.boolean :available ...
Ruby
class CreateNotices < ActiveRecord::Migration def change create_table :notices do |t| t.string :title t.text :content t.integer :user_id t.timestamps end end end
Ruby
class CreatePhotoRegistrations < ActiveRecord::Migration def change create_table :photo_registrations do |t| t.integer :user_id t.date :finish_date t.string :quantity t.timestamps end end end
Ruby
class CreateBookReservations < ActiveRecord::Migration def change create_table :book_reservations do |t| t.integer :user_id t.date :start_date t.date :due_date t.integer :extention_days t.timestamps end end end
Ruby
class CreateBookInstances < ActiveRecord::Migration def change create_table :book_instances do |t| t.string :book_instance_code t.integer :book_id t.integer :book_reservation_id t.integer :photo_registration_id t.timestamps end end end
Ruby
# encoding: UTF-8 User.delete_all Notice.delete_all Book.delete_all BookInstance.delete_all BookReservation.delete_all PhotoRegistration.delete_all user1 = User.create(:email => "user1@vit.com", :password => "123456", :password_confirmation => "123456", :remember_me => "true", :username => "user1", :role => "user", :...
Ruby
FactoryGirl.define do factory :book do sequence(:title) {|n| "book#{n}" } sequence(:book_code) {|n| "book_code#{n}" } end end
Ruby
FactoryGirl.define do factory :book_instance do sequence(:book_instance_code) {|n| "book_instance_code#{n}" } end end
Ruby
FactoryGirl.define do factory :user do sequence(:email) {|n| "email#{n}@example.com" } sequence(:username) {|n| "username#{n}" } password "123456" password_confirmation "123456" end factory :unconfirmed_user, :parent => :user do confirmation_token "confirmation_token" end fac...
Ruby
FactoryGirl.define do factory :book_reservation do start_date Date.today due_date Date.today + 3 end end
Ruby
FactoryGirl.define do factory :photo_registration do finish_date Date.today + 3 end end
Ruby
FactoryGirl.define do factory :notice do sequence(:title) {|n| "Title#{n}" } sequence(:content) {|n| "Content#{n}" } end end
Ruby
require 'simplecov' SimpleCov.start # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc...
Ruby
RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller end
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run BuffaloKids::Application
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', ...
Ruby
# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use yo...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
Ruby
# Be sure to restart your server when you modify this file. BuffaloKids::Application.config.session_store :cookie_store, key: '_buffalo_kids_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.ac...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the we...
Ruby
BuffaloKids::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the tes...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application BuffaloKids::Application.initialize!
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
BuffaloKids::Application.routes.draw do get "books/index" => "books#index" post "book_reservations/new/:book_id" => "book_reservations#new" post "book_reservations/delete/:book_reservation_id" => "book_reservations#delete" get "book_reservations/index/:page" => "book_reservations#index" get "book_reserva...
Ruby
module ApplicationHelper end
Ruby
module UserHelper end
Ruby
class BookInstance < ActiveRecord::Base attr_accessible :book_instance_code, :user_id, :book_id, :photo_registration_id, :book_reservation_id belongs_to :book belongs_to :book_reservation belongs_to :photo_registration validates_presence_of :book_instance_code; validates_uniqueness_of :book_instance_code; ...
Ruby
class PhotoRegistration < ActiveRecord::Base attr_accessible :user_id, :finish_date, :quantity belongs_to :user has_one :book_instance has_one :book, :through => :book_instance self.per_page = 12 end
Ruby
class Book < ActiveRecord::Base attr_accessible :title, :book_code, :description, :author, :image_url, :release_date, :rating validates_uniqueness_of :title, :book_code validates_presence_of :title, :book_code before_validation :default_image_url ...
Ruby
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, :confirmable # Setup acc...
Ruby
class BookReservation < ActiveRecord::Base attr_accessible :user_id, :start_date, :due_date, :extention_days belongs_to :user has_one :book_instance has_one :book, :through => :book_instance self.per_page = 12 end
Ruby
class Notice < ActiveRecord::Base attr_accessible :title, :content, :user_id validates :title, :content, :presence => true belongs_to :user self.per_page = 12 def short_content self.content.truncate(30) end end
Ruby
class BookReservationsController < ApplicationController before_filter :authenticate_user! def home @books = Book.paginate(:page => params[:page]) end def new book = Book.find_by_id(params[:book_id]) if current_user.book_reservations.map{ |a| a.book }.include? book #send some error message ...
Ruby
class PhotoRegistrationsController < ApplicationController before_filter :authenticate_user! def home @books = Book.paginate(:page => params[:page]) end def new book = Book.find_by_id(params[:book_id]) if current_user.photo_registrations.map{ |a| a.book }.include? book #send some error message...
Ruby
class EtcsController < ApplicationController def faq end def contact end def set_en if current_user.nil? session[:lang] = "en" else current_user.locale = "en" current_user.save end redirect_to "/" end def set_vi if current_user.nil? session[:lang] = "vi" e...
Ruby
class BooksController < ApplicationController # phan cua Viet before_filter :authenticate_user! def index @books = Book.paginate(:page => params[:page]) end def show @book = Book.find_by_id(params[:book_id]) end def edit @book = Book.find_by_id(params[:book_id]) end def upd...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale def set_locale if current_user.nil? I18n.locale = session[:lang].nil? ? "en" : session[:lang] else I18n.locale = current_user.locale end end def after_sign_in_path_for(resource_or_scope) case...
Ruby
class BookInstancesController < ApplicationController def index @book = Book.find(params[:book_id]) if @book.nil? # send error message else @book_instances = @book.book_instances.paginate(:page => params[:page]) if @book_instances.empty? # error message redirect_to "/books/show/#{param...
Ruby
class NoticesController < ApplicationController before_filter :authenticate_user! def index @notices = Notice.paginate(:page => params[:page]) end def show @notice = Notice.find_by_id(params[:notice_id]) end def edit @notice = Notice.find_by_id(params[:notice_id]) end def update @n...
Ruby
class UsersController < ApplicationController before_filter :authenticate_user! def index @users = User.paginate(:page => params[:page]) end def show @user = User.find_by_id(params[:user_id]) end def new @user = User.new end def edit @user = User.find_by_id(params[:user_id]) end def update @use...
Ruby
#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) BuffaloKids::Application.load_tasks
Ruby
#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) BuffaloKids::Application.load_tasks
Ruby
source 'https://rubygems.org' gem 'rails', '3.2.8' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' group :development, :test do gem 'mysql2' end # group :production do # gem 'pg' # end gem "mysql2" gem 'haml', '3.1.7' gem 'devise', '2.1.2' gem 'jquery-rails', '2.1.2' gem ...
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_to...
Ruby
class CreateBooks < ActiveRecord::Migration def change create_table :books do |t| t.string :title t.string :book_code t.string :description t.string :author t.string :category t.date :release_date t.string :image_url t.string :rating t.boolean :available ...
Ruby
class CreateNotices < ActiveRecord::Migration def change create_table :notices do |t| t.string :title t.string :content t.integer :user_id t.timestamps end end end
Ruby
class CreatePhotoRegistrations < ActiveRecord::Migration def change create_table :photo_registrations do |t| t.integer :user_id t.date :finish_date t.string :quantity t.timestamps end end end
Ruby
class CreateBookReservations < ActiveRecord::Migration def change create_table :book_reservations do |t| t.integer :user_id t.date :start_date t.date :due_date t.integer :extention_days t.timestamps end end end
Ruby
class CreateBookInstances < ActiveRecord::Migration def change create_table :book_instances do |t| t.string :book_instance_code t.integer :book_id t.integer :book_reservation_id t.integer :photo_registration_id t.timestamps end end end
Ruby
# encoding: UTF-8 User.delete_all Notice.delete_all Book.delete_all BookInstance.delete_all BookReservation.delete_all PhotoRegistration.delete_all user1 = User.create(:email => "user1@vit.com", :password => "123456", :username => "user1", :confirmed_at => Time.now) user2 = User.create(:email => "user2@vit.com", :pass...
Ruby
FactoryGirl.define do factory :book do sequence(:title) {|n| "book#{n}" } sequence(:book_code) {|n| "book_code#{n}" } end end
Ruby
FactoryGirl.define do factory :book_instance do sequence(:book_instance_code) {|n| "book_instance_code#{n}" } end end
Ruby
FactoryGirl.define do factory :user do sequence(:email) {|n| "email#{n}@example.com" } sequence(:username) {|n| "username#{n}" } password "123456" password_confirmation "123456" end factory :unconfirmed_user, :parent => :user do confirmation_token "confirmation_token" end fac...
Ruby
FactoryGirl.define do factory :book_reservation do start_date Date.today due_date Date.today + 3 end end
Ruby
FactoryGirl.define do factory :photo_registration do finish_date Date.today + 3 end end
Ruby
FactoryGirl.define do factory :notice do sequence(:title) {|n| "Title#{n}" } sequence(:content) {|n| "Content#{n}" } end end
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirect...
Ruby