Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

done a lot and didnt commit often

  • Loading branch information...
commit 9a6033c2dfe548d7d4bd4a4224dbcf2aebe685df 1 parent c6f6b1b
@drapergeek authored
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
5 :w
@@ -0,0 +1,5 @@
+require 'spec_helper.rb'
+
+describe Shout do
+
+end
View
5 Gemfile
@@ -23,6 +23,11 @@ end
gem 'jquery-rails'
+group :test do
+ gem 'rspec-rails'
+ gem 'factory_girl_rails'
+end
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
21 Gemfile.lock
@@ -42,9 +42,15 @@ GEM
coffee-script-source (1.2.0)
diesel (0.1.5)
railties
+ diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ factory_girl (2.6.3)
+ activesupport (>= 2.3.9)
+ factory_girl_rails (1.7.0)
+ factory_girl (~> 2.6.0)
+ railties (>= 3.0.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -84,6 +90,19 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
sass (3.1.15)
sass-rails (3.2.4)
railties (~> 3.2.0)
@@ -110,8 +129,10 @@ PLATFORMS
DEPENDENCIES
clearance
coffee-rails (~> 3.2.1)
+ factory_girl_rails
jquery-rails
rails (= 3.2.2)
+ rspec-rails
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
View
3  app/assets/javascripts/shouts.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/shouts.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the shouts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
4 app/controllers/dashboards_controller.rb
@@ -1,2 +1,6 @@
class DashboardsController < ApplicationController
+ def show
+ @shout = Shout.new
+ @shouts = current_user.shouts.current
+ end
end
View
6 app/controllers/shouts_controller.rb
@@ -0,0 +1,6 @@
+class ShoutsController < ApplicationController
+ def create
+ @shout = current_user.shouts.create!(params[:shout])
+ redirect_to dashboard_path, notice: "Shouted!"
+ end
+end
View
7 app/controllers/welcome_controller.rb
@@ -1,2 +1,9 @@
class WelcomeController < ApplicationController
+ before_filter :redirect_to_dashboard_if_signed_in
+
+
+ private
+ def redirect_to_dashboard_if_signed_in
+ redirect_to dashboard_path if signed_in?
+ end
end
View
2  app/helpers/shouts_helper.rb
@@ -0,0 +1,2 @@
+module ShoutsHelper
+end
View
7 app/models/shout.rb
@@ -0,0 +1,7 @@
+class Shout < ActiveRecord::Base
+ belongs_to :user
+
+ def self.current
+ order("created_at DESC")
+ end
+end
View
1  app/models/user.rb
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
include Clearance::User
+ has_many :shouts
end
View
9 app/views/dashboards/show.html.erb
@@ -0,0 +1,9 @@
+<h1>Dashboard</h1>
+Welcome <%= current_user.email %>! <%= link_to "Sign Out", sign_out_path, method: :delete %>
+<%= form_for @shout do |f| %>
+ <%= f.text_field :body, placeholder: "Shout here" %>
+ <%= f.submit "Shout!" %>
+<% end %>
+<div id="shouts">
+ <%= render @shouts %>
+</div>
View
11 app/views/layouts/application.html.erb
@@ -7,11 +7,14 @@
<%= csrf_meta_tags %>
</head>
<body>
- <% flash.each do |key, value| -%>
- <div class="flash <%= key %>"><%= value %></div>
- <% end -%>
+ <div class="content">
- <%= yield %>
+ <% flash.each do |key, value| -%>
+ <div class="flash <%= key %>"><%= value %></div>
+ <% end -%>
+
+ <%= yield %>
+ </div>
</body>
</html>
View
3  app/views/shouts/_shout.html.erb
@@ -0,0 +1,3 @@
+<%= content_tag_for(:div, shout) do %>
+ <%= shout.body %> - <%= time_ago_in_words(shout.created_at) %> ago
+<% end %>
View
4 app/views/welcome/index.html.erb
@@ -0,0 +1,4 @@
+<h1 id="heading">Shouter</h1>
+
+
+
View
3  config/routes.rb
@@ -1,4 +1,5 @@
Shouter::Application.routes.draw do
- resource :dashboard
+ resource :dashboard, only: [:show]
+ resources :shouts, only: [:create]
root to: "welcome#index"
end
View
11 db/migrate/20120312143245_create_shouts.rb
@@ -0,0 +1,11 @@
+class CreateShouts < ActiveRecord::Migration
+ def change
+ create_table :shouts do |t|
+ t.belongs_to :user
+ t.text :body
+
+ t.timestamps
+ end
+ add_index :shouts, :user_id
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120312134901) do
+ActiveRecord::Schema.define(:version => 20120312143245) do
+
+ create_table "shouts", :force => true do |t|
+ t.integer "user_id"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "shouts", ["user_id"], :name => "index_shouts_on_user_id"
create_table "users", :force => true do |t|
t.string "email"
View
8 spec/factories.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+
+ factory :shout do
+ body "some text"
+ user
+ end
+
+end
View
9 spec/models/shout_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper.rb'
+
+describe Shout do
+ it "returns .current shouts in reverse chronological order" do
+ older_shout = create(:shout)
+ newer_shout = create(:shout)
+ Shout.current.should == [newer_shout, older_shout]
+ end
+end
View
28 spec/spec_helper.rb
@@ -0,0 +1,28 @@
+# 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'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+ config.include FactoryGirl::Syntax::Methods
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+end
View
9 test/fixtures/shouts.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ user:
+ body: MyText
+
+two:
+ user:
+ body: MyText
View
7 test/functional/shouts_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ShoutsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/shouts_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ShoutsHelperTest < ActionView::TestCase
+end
View
7 test/unit/shout_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ShoutTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.