diff --git a/README.mkdn b/README.mkdn index ccde9ef..d36b0b0 100644 --- a/README.mkdn +++ b/README.mkdn @@ -5,6 +5,7 @@

Feature list:

All writes will be sent to master, and the read queries will be sent to the slaves. unless you have a transaction, so , all queries will be sent to master.

+

The application have two different models: Client and User. User is a replicated model, and Client isn't replicated. So, when you create a new User, you will see a exception, because you don't have configuration for replication and Rails tries to read the user from a slave database, and the write query have been sent to master (Default behaviour when using replication). When you create a new client, everything should works fine, it will read and write in the master database.

Setup:

You will need two commands to setup the application:

diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000..f9b859b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,4 @@ +class WelcomeController < ApplicationController + def index + end +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000..eeead45 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000..3eeb1b4 --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,6 @@ +

Welcome to Octopus Replication Example!

+

Replicated Model:

+<%= link_to "Users", users_path%> +

Non-Replicated Model:

+<%= link_to "Clients", clients_path%> + diff --git a/config/routes.rb b/config/routes.rb index 253af7d..5bfc6be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,8 @@ OctopusReplicationExample::Application.routes.draw do |map| + get "welcome/index" resources :clients - resources :users - + root :to => "welcome#index" # The priority is based upon order of creation: # first created -> highest priority. @@ -49,10 +49,8 @@ # # (app/controllers/admin/products_controller.rb) # resources :products # end - # You can have the root of your site routed with "root" # just remember to delete public/index.html. - # root :to => "welcome#index" # See how all your routes lay out with "rake routes" diff --git a/db/schema.rb b/db/schema.rb index 3640ea3..65e7bef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,16 @@ ActiveRecord::Schema.define(:version => 20100623041305) do - create_table "clients", :force => true do |t| + create_table "clients", :id => false, :force => true do |t| + t.integer "id", :null => false t.string "name" t.date "birthday" t.datetime "created_at" t.datetime "updated_at" end - create_table "users", :force => true do |t| + create_table "users", :id => false, :force => true do |t| + t.integer "id", :null => false t.string "name" t.date "birthday" t.datetime "created_at" diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 9fb304a..0000000 --- a/public/index.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - Ruby on Rails: Welcome aboard - - - - -
- - -
- - - - -
-

Getting started

-

Here’s how to get rolling:

- -
    -
  1. -

    Use rails generate to create your models and controllers

    -

    To see all available options, run it without parameters.

    -
  2. - -
  3. -

    Set up a default route and remove or rename this file

    -

    Routes are set up in config/routes.rb.

    -
  4. - -
  5. -

    Create your database

    -

    Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

    -
  6. -
-
-
- - -
- - diff --git a/spec/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb new file mode 100644 index 0000000..5f95e34 --- /dev/null +++ b/spec/controllers/welcome_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe WelcomeController do + + describe "GET 'index'" do + it "should be successful" do + get 'index' + response.should be_success + end + end + +end diff --git a/spec/helpers/welcome_helper_spec.rb b/spec/helpers/welcome_helper_spec.rb new file mode 100644 index 0000000..350a5d3 --- /dev/null +++ b/spec/helpers/welcome_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the WelcomeHelper. For example: +# +# describe WelcomeHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe WelcomeHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/welcome/index.html.erb_spec.rb b/spec/views/welcome/index.html.erb_spec.rb new file mode 100644 index 0000000..7eead28 --- /dev/null +++ b/spec/views/welcome/index.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "welcome/index.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end