Godwin
11 years ago
35 changed files with 711 additions and 194 deletions
@ -0,0 +1,24 @@ |
|||||
|
# A sample Guardfile |
||||
|
# More info at https://github.com/guard/guard#readme |
||||
|
|
||||
|
guard :rspec do |
||||
|
watch(%r{^spec/.+_spec\.rb$}) |
||||
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } |
||||
|
watch('spec/spec_helper.rb') { "spec" } |
||||
|
|
||||
|
# Rails example |
||||
|
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } |
||||
|
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } |
||||
|
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } |
||||
|
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } |
||||
|
watch('config/routes.rb') { "spec/routing" } |
||||
|
watch('app/controllers/application_controller.rb') { "spec/controllers" } |
||||
|
|
||||
|
# Capybara features specs |
||||
|
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } |
||||
|
|
||||
|
# Turnip features and steps |
||||
|
watch(%r{^spec/acceptance/(.+)\.feature$}) |
||||
|
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } |
||||
|
end |
||||
|
|
Binary file not shown.
@ -1,4 +1,4 @@ |
|||||
= form_tag user_sessions_path, :method => :post do |
= form_tag user_sessions_path, :method => :post do |
||||
= field :email, :email_field |
= field :email, :email_field |
||||
= field :password, :password_field_tag |
= field :password, :password_field_tag |
||||
= actions :sign_in |
= actions [:sign_in, :facebook_sign_in] |
||||
|
@ -0,0 +1,135 @@ |
|||||
|
require 'i18n/backend/active_record' |
||||
|
require 'yaml' |
||||
|
|
||||
|
class DevTranslation < Translation |
||||
|
self.table_name = 'translations' |
||||
|
establish_connection :development |
||||
|
end |
||||
|
|
||||
|
module I18n |
||||
|
class MissingTranslationExceptionHandler < ExceptionHandler |
||||
|
def self.lorem_ipsum(method, size) |
||||
|
options = {:random => true} |
||||
|
case method.to_s |
||||
|
when 'c', 'char', 'character', 'characters' |
||||
|
if size |
||||
|
return Forgery::LoremIpsum.characters size, options |
||||
|
end |
||||
|
return Forgery::LoremIpsum.character, options |
||||
|
when 'w', 'word', 'words' |
||||
|
if size |
||||
|
return Forgery::LoremIpsum.words size, options |
||||
|
end |
||||
|
#return'LOREM' |
||||
|
return Forgery::LoremIpsum.word options |
||||
|
when 's', 'sentence', 'sentences' |
||||
|
if size |
||||
|
return Forgery::LoremIpsum.sentences size, options |
||||
|
end |
||||
|
return Forgery::LoremIpsum.sentence options |
||||
|
when 'p', 'paragraph', 'paragraphs' |
||||
|
if size |
||||
|
return Forgery::LoremIpsum.paragraphs size, options.merge({:sentences => 10}) |
||||
|
end |
||||
|
return Forgery::LoremIpsum.sentences 10, options |
||||
|
when 't', 'title' |
||||
|
return Forgery::LoremIpsum.sentences 1, options |
||||
|
end |
||||
|
return nil |
||||
|
end |
||||
|
|
||||
|
def self.note(key, behavior = nil, behavior_size = nil) |
||||
|
I18n.backend.needs_translation(key) |
||||
|
if behavior |
||||
|
return self.lorem_ipsum(behavior, behavior_size) |
||||
|
end |
||||
|
key.to_s.gsub(/^world\..*\.(.+)\.name$/, '\1').gsub(/^.*\.(.+)?$/, '\1').gsub('_', ' ') |
||||
|
end |
||||
|
|
||||
|
def call(exception, locale, key, options) |
||||
|
if exception.is_a?(MissingTranslation) |
||||
|
I18n::MissingTranslationExceptionHandler.note(key, options[:behavior] || nil, options[:behavior_size] || nil) |
||||
|
else |
||||
|
super |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
module Backend |
||||
|
class BikeBike < I18n::Backend::ActiveRecord |
||||
|
@@needs_translation |
||||
|
|
||||
|
@@translations_file = 'config/locales/.translations.yml' |
||||
|
@@translation_cache_file = 'config/locales/.translation-cache.yml' |
||||
|
@@translation_cache |
||||
|
|
||||
|
def needs_translation(key) |
||||
|
@@needs_translation ||= Array.new |
||||
|
@@needs_translation << key |
||||
|
end |
||||
|
|
||||
|
def initialized? |
||||
|
begin |
||||
|
super |
||||
|
rescue |
||||
|
return false |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def initialize |
||||
|
if Rails.env.test? |
||||
|
File.open(@@translations_file, 'w+') |
||||
|
File.open(@@translation_cache_file, 'w+') |
||||
|
end |
||||
|
@@translation_cache = YAML.load(File.read(@@translation_cache_file)) || Hash.new |
||||
|
super |
||||
|
end |
||||
|
|
||||
|
protected |
||||
|
def lookup(locale, key, scope = [], options = {}) |
||||
|
result = nil |
||||
|
if @@translation_cache && @@translation_cache.has_key?(locale.to_s) && @@translation_cache[locale.to_s].has_key?(key.to_s) |
||||
|
result = @@translation_cache[locale.to_s][key.to_s] |
||||
|
end |
||||
|
if !result |
||||
|
result = super(locale, key, scope, options) |
||||
|
|
||||
|
if Rails.env.test? |
||||
|
if result |
||||
|
@@translation_cache[locale.to_s] ||= Hash.new |
||||
|
@@translation_cache[locale.to_s][key.to_s] = result |
||||
|
File.open(@@translation_cache_file, 'w') { |f| f.write @@translation_cache.to_yaml } |
||||
|
end |
||||
|
|
||||
|
translations = YAML.load_file(@@translations_file) |
||||
|
translations ||= Hash.new |
||||
|
translations[key.to_s] ||= Hash.new |
||||
|
translations[key.to_s]['langauges'] ||= Hash.new |
||||
|
if result != nil |
||||
|
translations[key.to_s]['langauges'][locale.to_s] = result |
||||
|
end |
||||
|
translations[key.to_s]['pages'] ||= Array.new |
||||
|
unless translations[key.to_s].has_key?('data') |
||||
|
translations[key.to_s]['data'] = Array.new |
||||
|
DevTranslation.where("key = '#{key.to_s}' OR key LIKE '#{key.to_s}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%'").each { |t| |
||||
|
translations[key.to_s]['data'] << t.becomes(Translation) |
||||
|
} |
||||
|
end |
||||
|
path = $page_info[:path] |
||||
|
unless translations[key.to_s]['pages'].include?(path) |
||||
|
translations[key.to_s]['pages'] << path |
||||
|
end |
||||
|
File.open(@@translations_file, 'w') { |f| f.write translations.to_yaml } |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
if Rails.env.test? |
||||
|
end |
||||
|
|
||||
|
result |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
I18n.exception_handler = I18n::MissingTranslationExceptionHandler.new |
@ -1,4 +1,4 @@ |
|||||
require 'i18n/backend/active_record' |
require 'i18n/backend/active_record' |
||||
I18n.backend = I18n::Backend::ActiveRecord.new |
I18n.backend = I18n::Backend::BikeBike.new |
||||
# I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize) |
# I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize) |
||||
# I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten) |
# I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten) |
||||
|
@ -0,0 +1,15 @@ |
|||||
|
module Rack |
||||
|
class MethodOverrideWithParams < Rack::MethodOverride |
||||
|
def call(env) |
||||
|
#puts "\n\nENV: " + env.to_json.to_s + "\n\n" |
||||
|
#puts "\n\nTT: " |
||||
|
#puts I18n::Backend::BikeBike.translations_file + "\n\n" |
||||
|
$request = Rack::Request.new(env) |
||||
|
#Rails.I18n.translations_file ||= 'config/locales/.translations.yml' |
||||
|
#if Rails.env.test? |
||||
|
# File.open(Rails.I18n.translations_file, 'w+')# { |f| f.write {}.to_yaml } |
||||
|
#end |
||||
|
super(env) |
||||
|
end |
||||
|
end |
||||
|
end |
@ -0,0 +1,78 @@ |
|||||
|
--- |
||||
|
nola_2013.about: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
home.its_awesome: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
Conferences: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
- "/login" |
||||
|
Organizations: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
- "/login" |
||||
|
Resources: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
- "/login" |
||||
|
Sign_In: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
- "/login" |
||||
|
missing.translation: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/" |
||||
|
- "/login" |
||||
|
form.Enter_your_email: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
email: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
password: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
sign_in: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
facebook_sign_in: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
user.Create_Account: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
user.why_register: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
form.Enter_your_username: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
username: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
password_confirmation: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
||||
|
register: |
||||
|
langauges: {} |
||||
|
pages: |
||||
|
- "/login" |
@ -0,0 +1,14 @@ |
|||||
|
namespace :translations do |
||||
|
desc "Migrates collected translations from the dev and testing environments" |
||||
|
task migrate: :environment do |
||||
|
#File.open('config/locales/.translations.yml', 'w') |
||||
|
#File.open('config/locales/.translation-cache.yml', 'w+') |
||||
|
|
||||
|
translations = YAML.load(File.read('config/locales/.translations.yml')) || Hash.new |
||||
|
translations.each { |k,t| |
||||
|
if t['data'] |
||||
|
t['data'].each { |tt| tt.save } |
||||
|
end |
||||
|
} |
||||
|
end |
||||
|
end |
@ -1,3 +1,3 @@ |
|||||
platform.active=Ruby |
platform.active=Ruby |
||||
rails.port=3000 |
rails.port=80 |
||||
source.encoding=UTF-8 |
source.encoding=UTF-8 |
||||
|
@ -0,0 +1,29 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe 'Home' do |
||||
|
it "has a title which is Bike!Bike!" do |
||||
|
visit root_path |
||||
|
expect(page).to have_link 'Bike!Bike!' |
||||
|
end |
||||
|
|
||||
|
it "has a link to login" do |
||||
|
visit root_path |
||||
|
expect(page).to have_link 'Sign In', :href => '/login' |
||||
|
end |
||||
|
|
||||
|
it "has a link to conferences" do |
||||
|
visit root_path |
||||
|
expect(find '.top-bar-section a[href$="/conferences"]').to have_text 'Conferences' |
||||
|
end |
||||
|
|
||||
|
it "has a link to organizations" do |
||||
|
visit root_path |
||||
|
expect(find '.top-bar-section a[href$="/organizations"]').to have_text 'Organizations' |
||||
|
end |
||||
|
|
||||
|
it "has a link to resources" do |
||||
|
visit root_path |
||||
|
expect(find '.top-bar-section a[href$="/resources"]').to have_text 'Resources' |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,72 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe 'Login' do |
||||
|
|
||||
|
it "has a title which is Bike!Bike!" do |
||||
|
visit login_path |
||||
|
expect(page).to have_link 'Bike!Bike!' |
||||
|
end |
||||
|
|
||||
|
it "has a link to login" do |
||||
|
visit login_path |
||||
|
expect(page).to have_link 'Sign In', :href => '/login' |
||||
|
end |
||||
|
|
||||
|
it "has a link to conferences" do |
||||
|
visit login_path |
||||
|
expect(find '.top-bar-section a[href$="/conferences"]').to have_text 'Conferences' |
||||
|
end |
||||
|
|
||||
|
it "has a link to organizations" do |
||||
|
visit login_path |
||||
|
expect(find '.top-bar-section a[href$="/organizations"]').to have_text 'Organizations' |
||||
|
end |
||||
|
|
||||
|
it "has a link to resources" do |
||||
|
visit login_path |
||||
|
expect(find '.top-bar-section a[href$="/resources"]').to have_text 'Resources' |
||||
|
end |
||||
|
|
||||
|
it "has a login form" do |
||||
|
visit login_path |
||||
|
form = find 'form[action$="/user_sessions"]' |
||||
|
expect(form).to have_button 'sign in' |
||||
|
expect(form).to have_field 'email_' |
||||
|
expect(form).to have_field 'password' |
||||
|
expect(form).to have_link 'facebook' |
||||
|
end |
||||
|
|
||||
|
it "has a register form" do |
||||
|
visit login_path |
||||
|
form = find 'form[action$="/users"]' |
||||
|
expect(form).to have_button 'register' |
||||
|
expect(form).to have_field 'user_username' |
||||
|
expect(form).to have_field 'user_email' |
||||
|
expect(form).to have_field 'user_password' |
||||
|
expect(form).to have_field 'user_password_confirmation' |
||||
|
end |
||||
|
|
||||
|
it "allows you to register" do |
||||
|
visit login_path |
||||
|
fill_in "user_username", :with => "John" |
||||
|
fill_in "user_email", :with => "johnsemail@example.com" |
||||
|
fill_in "user_password", :with => "johnspassword" |
||||
|
fill_in "user_password_confirmation", :with => "johnspassword" |
||||
|
click_button "register" |
||||
|
end |
||||
|
|
||||
|
describe "can actually happen" do |
||||
|
|
||||
|
let(:user) { FactoryGirl.create(:user) } |
||||
|
|
||||
|
it "allows you to login" do |
||||
|
visit login_path |
||||
|
form = find 'form[action$="/user_sessions"]' |
||||
|
form.find("#email_").set(user.email) |
||||
|
form.find("#password").set('secret') |
||||
|
click_button "sign_in" |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,21 @@ |
|||||
|
require 'spec_helper' |
||||
|
|
||||
|
describe 'Organization Registration' do |
||||
|
|
||||
|
let(:user) { FactoryGirl.create(:user) } |
||||
|
|
||||
|
before(:each) do |
||||
|
visit login_path |
||||
|
form = find 'form[action$="/user_sessions"]' |
||||
|
form.find("#email_").set(user.email) |
||||
|
form.find("#password").set('secret') |
||||
|
click_button "sign_in" |
||||
|
visit new_organization_path |
||||
|
end |
||||
|
|
||||
|
it "works as expected" do |
||||
|
fill_in 'organization_name', :with => 'Bike Kitchen' |
||||
|
fill_in 'organization_slug', :with => 'bike-kitchen' |
||||
|
fill_in 'organization_email_address', :with => 'bikekitchen@example.com' |
||||
|
end |
||||
|
end |
@ -1,6 +1,13 @@ |
|||||
# Read about factories at https://github.com/thoughtbot/factory_girl |
# Read about factories at https://github.com/thoughtbot/factory_girl |
||||
|
|
||||
FactoryGirl.define do |
FactoryGirl.define do |
||||
factory :user do |
sequence(:email) { |n| "person-#{n}@example.com" } |
||||
|
sequence(:username) { |n| "person-#{n}" } |
||||
|
|
||||
|
factory :user, class: User do |
||||
|
username |
||||
|
email |
||||
|
password "secret" |
||||
|
password_confirmation "secret" |
||||
end |
end |
||||
end |
end |
||||
|
Loading…
Reference in new issue