Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of git@github.com:railsrumble/teamwnn
Browse files Browse the repository at this point in the history
  • Loading branch information
kellishaver committed Oct 19, 2008
2 parents 3ef4760 + c05ca4d commit 9dbe398
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 67 deletions.
4 changes: 1 addition & 3 deletions app/models/code_snippet.rb
Expand Up @@ -3,7 +3,5 @@ class CodeSnippet < ActiveRecord::Base

belongs_to :project

def to_s
name
end
validates_presence_of :name, :content, :language
end
2 changes: 2 additions & 0 deletions app/models/color_swatch.rb
@@ -1,3 +1,5 @@
class ColorSwatch < ActiveRecord::Base
belongs_to :palette

validates_presence_of :hex
end
4 changes: 1 addition & 3 deletions app/models/link.rb
Expand Up @@ -3,7 +3,5 @@ class Link < ActiveRecord::Base

belongs_to :project

def to_s
name
end
validates_presence_of :name, :url
end
4 changes: 1 addition & 3 deletions app/models/note.rb
Expand Up @@ -3,7 +3,5 @@ class Note < ActiveRecord::Base

belongs_to :project

def to_s
name
end
validates_presence_of :name, :content
end
4 changes: 1 addition & 3 deletions app/models/palette.rb
Expand Up @@ -6,9 +6,7 @@ class Palette < ActiveRecord::Base

after_save :save_color_swatches

def to_s
name
end
validates_presence_of :name

private

Expand Down
8 changes: 3 additions & 5 deletions app/models/photo.rb
Expand Up @@ -3,13 +3,11 @@ class Photo < ActiveRecord::Base

belongs_to :project

validates_presence_of :name

has_attached_file :image, :styles => { :small => "150x150>", :tiny => "64x64>" },
:url => "/assets/photos/:id/:style/:basename.:extension",
:path => "#{RAILS_ROOT}/public/assets/photos/:id/:style/:basename.:extension"

def to_s
name
end
:path => "#{RAILS_ROOT}/public/assets/photos/:id/:style/:basename.:extension"

def image_width(style = nil)
image_jpeg(style).width
Expand Down
4 changes: 1 addition & 3 deletions app/models/project.rb
Expand Up @@ -10,9 +10,7 @@ class Project < ActiveRecord::Base

generate_unique :token

def to_s
name
end
validates_presence_of :name

def self.fetch(user, id_or_token)
Project.find_by_token(id_or_token) || (user || User.new).projects.find(id_or_token)
Expand Down
4 changes: 1 addition & 3 deletions app/models/screenshot.rb
Expand Up @@ -3,9 +3,7 @@ class Screenshot < ActiveRecord::Base

belongs_to :project

def to_s
name
end
validates_presence_of :name

def image_url(width)
"http://api.thumbalizr.com?api_key=#{APP_CONFIG['thumbalizr_key']}&url=#{source_url}&width=#{width}"
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Expand Up @@ -9,9 +9,12 @@ class User < ActiveRecord::Base
before_save :prepare_password

validates_presence_of :username
validates_uniqueness_of :username, :email, :openid_url, :allow_blank => true
validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
validates_presence_of :password, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_length_of :password, :minimum => 4, :allow_blank => true, :if => :password_required?

# login can be either username or email address
def self.authenticate(login, pass)
Expand Down
20 changes: 11 additions & 9 deletions app/views/users/new.html.erb
Expand Up @@ -30,16 +30,18 @@

<p class="align_right"><%= f.submit "Sign Up" %></p>
<% end %>
<div id="login">
<% form_tag sessions_path do %>
<h3>Or use OpenID:</h3><br />
<fieldset>
<%= label_tag :openid_url, "OpenID URL" %>
<%= text_field_tag :openid_url, params[:openid_url] %>
</fieldset>
<p class="align_right"><%= submit_tag "Sign Up" %></p>
<% if @user.openid_url.blank? %>
<div id="login">
<% form_tag sessions_path do %>
<h3>Or use OpenID:</h3><br />
<fieldset>
<%= label_tag :openid_url, "OpenID URL" %>
<%= text_field_tag :openid_url, params[:openid_url] %>
</fieldset>
<p class="align_right"><%= submit_tag "Sign Up" %></p>
<% end %>
</div>
<% end %>
</div>
</div>
<div id="sidebar">
<%= image_tag "ad.png" %>
Expand Down
58 changes: 56 additions & 2 deletions spec/factories.rb
@@ -1,12 +1,66 @@
Factory.sequence :email do |n|
"foo#{n}@example.com"
end

Factory.sequence :username do |n|
"foobar#{n}"
end

Factory.define :user do |f|
f.username 'foobar'
f.email 'foo@example.com'
f.username { Factory.next(:username) }
f.email { Factory.next(:email) }
f.password 'secret'
f.password_confirmation 'secret'
end

Factory.define :project do |f|
f.user { |c| c.association(:user) }
f.name 'Foo Bar'
f.description 'Lorem'
f.last_activity_at Time.now
end

Factory.define :code_snippet do |f|
f.project { |c| c.association(:project) }
f.name 'Hello, World'
f.content 'puts "Hello, World"'
f.language 'Ruby'
end

Factory.define :palette do |f|
f.project { |c| c.association(:project) }
f.name 'Color Theme'
end

Factory.define :color_swatch do |f|
f.palette { |c| c.association(:palette) }
f.hex '#FFF'
end

Factory.define :link do |f|
f.project { |c| c.association(:project) }
f.name 'Railscasts'
f.url 'http://railscasts.com'
f.description 'Free Ruby on Rails Screencasts'
end

Factory.define :note do |f|
f.project { |c| c.association(:project) }
f.name 'Foo'
f.content 'This is a note'
end

Factory.define :photo do |f|
f.project { |c| c.association(:project) }
f.name 'Me!'
f.image_file_name 'me.jpg'
f.image_content_type 'image/jpeg'
f.image_file_size '986123'
f.image_updated_at Time.now
end

Factory.define :screenshot do |f|
f.project { |c| c.association(:project) }
f.name 'Railscasts Home'
f.source_url 'http://railscasts.com'
end
16 changes: 14 additions & 2 deletions spec/models/code_snippet_spec.rb
@@ -1,7 +1,19 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe CodeSnippet do
it "should be valid" do
CodeSnippet.new.should be_valid
it "should be valid from factory" do
Factory.build(:code_snippet).should be_valid
end

it "should require name" do
Factory.build(:code_snippet, :name => '').should have(1).error_on(:name)
end

it "should require content" do
Factory.build(:code_snippet, :content => '').should have(1).error_on(:content)
end

it "should require language" do
Factory.build(:code_snippet, :language => '').should have(1).error_on(:language)
end
end
8 changes: 6 additions & 2 deletions spec/models/color_swatch_spec.rb
@@ -1,7 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe ColorSwatch do
it "should be valid" do
ColorSwatch.new.should be_valid
it "should be valid from factory" do
Factory.build(:color_swatch).should be_valid
end

it "should require hex" do
Factory.build(:color_swatch, :hex => '').should have(1).error_on(:hex)
end
end
12 changes: 10 additions & 2 deletions spec/models/link_spec.rb
@@ -1,7 +1,15 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Link do
it "should be valid" do
Link.new.should be_valid
it "should be valid from factory" do
Factory.build(:link).should be_valid
end

it "should require name" do
Factory.build(:link, :name => '').should have(1).error_on(:name)
end

it "should require url" do
Factory.build(:link, :url => '').should have(1).error_on(:url)
end
end
12 changes: 10 additions & 2 deletions spec/models/note_spec.rb
@@ -1,7 +1,15 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Note do
it "should be valid" do
Note.new.should be_valid
it "should be valid from factory" do
Factory.build(:note).should be_valid
end

it "should require name" do
Factory.build(:note, :name => '').should have(1).error_on(:name)
end

it "should require content" do
Factory.build(:note, :content => '').should have(1).error_on(:content)
end
end
20 changes: 12 additions & 8 deletions spec/models/palette_spec.rb
@@ -1,23 +1,27 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Palette do
it "should be valid" do
Palette.new.should be_valid
it "should be valid from factory" do
Factory.build(:palette).should be_valid
end

it "should require name" do
Factory.build(:palette, :name => '').should have(1).error_on(:name)
end

it "should have color hex getter/seter method" do
palette = Palette.new(:color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette = Factory.build(:palette, :color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette.color_hex_1.should == 'foo'
palette.color_hex_5.should == 'bar'
end

it "should save color swatch on create" do
palette = Palette.create!(:color_hex_2 => 'foo', :color_hex_4 => 'bar')
palette = Factory(:palette, :color_hex_2 => 'foo', :color_hex_4 => 'bar')
palette.color_swatches(true).should have(2).records
end

it "should update or create existing color swatches" do
palette = Palette.create!(:color_hex_2 => 'foo', :color_hex_4 => 'bar')
palette = Factory(:palette, :color_hex_2 => 'foo', :color_hex_4 => 'bar')
palette.color_hex_1 = 'red'
palette.color_hex_2 = 'green'
palette.color_hex_3 = 'blue'
Expand All @@ -26,21 +30,21 @@
end

it "should destroy color hexes which aren't mentioned" do
palette = Palette.create!(:color_hex_1 => 'foo', :color_hex_3 => 'bar')
palette = Factory(:palette, :color_hex_1 => 'foo', :color_hex_3 => 'bar')
palette.color_hex_1 = 'red'
palette.save
palette.color_swatches(true).map(&:hex).should == %w[red]
end

it "should remember color hexes across reload (get from color swatch)" do
palette = Palette.create!(:color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette = Factory(:palette, :color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette.reload
palette.color_hex_1.should == 'foo'
palette.color_hex_2.should == 'bar'
end

it "should not clear color hexes when saving without updating colors" do
palette = Palette.create!(:color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette = Factory(:palette, :color_hex_1 => 'foo', :color_hex_5 => 'bar')
palette.save
palette.color_hex_1.should == 'foo'
palette.color_hex_2.should == 'bar'
Expand Down
8 changes: 6 additions & 2 deletions spec/models/photo_spec.rb
@@ -1,7 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Photo do
it "should be valid" do
Photo.new.should be_valid
it "should be valid from factory" do
Factory.build(:photo).should be_valid
end

it "should require name" do
Factory.build(:photo, :name => '').should have(1).error_on(:name)
end
end
12 changes: 8 additions & 4 deletions spec/models/project_spec.rb
@@ -1,13 +1,17 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Project do
it "should be valid" do
Project.new.should be_valid
it "should be valid from factory" do
Factory.build(:project).should be_valid
end

it "should require name" do
Factory.build(:project, :name => '').should have(1).error_on(:name)
end

it "should generate a unique token" do
p1 = Factory(:project)
p2 = Factory(:project)
p1 = Factory(:project, :user => nil)
p2 = Factory(:project, :user => nil)
p1.token.should_not == p2.token
end

Expand Down
8 changes: 6 additions & 2 deletions spec/models/screenshot_spec.rb
@@ -1,8 +1,12 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Screenshot do
it "should be valid" do
Screenshot.new.should be_valid
it "should be valid from factory" do
Factory.build(:screenshot).should be_valid
end

it "should require name" do
Factory.build(:screenshot, :name => '').should have(1).error_on(:name)
end

it "should use thumbalizr for image url" do
Expand Down

0 comments on commit 9dbe398

Please sign in to comment.