Skip to content

Instantly share code, notes, and snippets.

View damianesteban's full-sized avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
@damianesteban
damianesteban / product_test_issues.rb
Created July 11, 2014 11:38
testing, testing...
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
fixtures :products
# Let's test our product model attributes!
test "product attributes must not be empty" do
product = Product.new
assert product.invalid?
assert product.errors[:title].any?
assert product.errors[:description].any?
# The pages of the web application correspond to actions in this controller.
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
# GET /users.json
# This action asks the User model to rerieve a list of all the users from the
# database, and then place them in the variable @users.
# (see app/models/user.rb)
def index
# The user model (though it looks plain), comes equipped with
# a large amount of functionality because of inheritance. Specifically,
# via Active Record, the code arranges for User.all to return all the users.
# Once the @users variable is defined, the controller calls the view -
# (See app/views/users/index.html.erb for further explanation)
class User < ActiveRecord::Base
end
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
source 'https://rubygems.org'
ruby '2.1.2'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
group :development do
gem 'sqlite3', '1.3.8'
gem 'better_errors'
gem 'quiet_assets'
afinn = dict(map(lambda (k,v): (k,int(v)),
[line.split('\t') for line in open("AFINN-111.txt") ]))
afinn["Good".lower()]
sum(map(lambda word: afinn.get(word, 0), "Rainy day but still in a good mood".lower().split()))
afinn = IO.readlines('AFINN-111.txt').map {|line| line.split("\t")}.to_h
==> default: [2014-09-18T15:49:39-04:00] INFO: *** Chef 11.16.2 ***
==> default: [2014-09-18T15:49:39-04:00] INFO: Chef-client pid: 1905
==> default: [2014-09-18T15:49:41-04:00] INFO: Setting the run_list to ["role[majestic-chaos-ubuntu14.04x64]"] from CLI options
==> default: [2014-09-18T15:49:41-04:00] ERROR: Role majestic-chaos-ubuntu14.04x64 (included by 'top level') is in the runlist but does not exist. Skipping expand.
#!/usr/bin/env bash echo "Installing Apache and setting it up..." apt-get install -y libglibmm-2.4-dev >/dev/null 2>&1 apt-get install -y libnotify4 >/dev/null 2>&1 rm -rf /var/www ln -fs /vagrant /var/www

I was thinking last night about the MVC Framework and the Single Responsibility Principle (yes, those are the kinds of things I think about as I'm falling asleep). Now I'm aware that some programmers feel that the way Rails employs the Controller as a "two-way street" violates the SRP, and that ties into this.

I've been thinking these past few days about how we are going to organize this application, i.e. working with three or more models (which I haven't done before) And then it hit me like a truck...

HOLY SHITBALLS, The Controller in the Rails Model-View-Controller Framework DOES VIOLATE THE SRP...AND THIS VIOLATION IS THE SOLUTION

Anyway, I got rid of the custom.css.scss file, and I made a change to the application layout so that it now renders controller.controller_name in the body (before the yield statement). What this means is that now each stylesheet corresponds to a view/controller, whereas in Hartl's book he dumps it into one.

I still have to finish the CSS and add some images, but I'