Skip to content
Browse files

Added some tests

  • Loading branch information...
1 parent 1a0b6c0 commit ef2dabc6492846b50bca08f109e88bde8da4822f @marcgg committed Sep 22, 2011
View
2 .rspec
@@ -0,0 +1,2 @@
+--colour
+--format documentation
View
7 Gemfile
@@ -15,11 +15,14 @@ gem 'koala', '=1.1.0rc2'
gem 'instagram', '=0.7'
gem 'rake', '=0.9.2'
-group :test, :test do
- gem 'rspec'
+group :test do
gem 'rr'
end
+group :development, :test do
+ gem 'rspec-rails'
+end
+
group :development do
gem 'ruby-debug'
gem 'mongrel'
View
23 Gemfile.lock
@@ -42,7 +42,7 @@ GEM
sass (~> 3.1)
curb (0.7.12)
daemons (1.1.0)
- diff-lcs (1.1.2)
+ diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.5.7)
@@ -101,14 +101,19 @@ GEM
thor (~> 0.14.4)
rake (0.9.2)
rr (1.0.2)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
@@ -136,6 +141,6 @@ DEPENDENCIES
rails (= 3.0.6)
rake (= 0.9.2)
rr
- rspec
+ rspec-rails
ruby-debug
sqlite3
View
1 app/models/beta_code.rb
@@ -1,3 +1,2 @@
class BetaCode < ActiveRecord::Base
-
end
View
8 app/models/category.rb
@@ -10,11 +10,17 @@ class Category < ActiveRecord::Base
validates_presence_of :slug, :if => Proc.new { |category| !category.new_record? }
def set_slug
- self.update_attribute(:slug, "#{self.id}-#{self.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')}")
+ unless self.slug
+ self.update_attribute :slug, generated_slug
+ end
end
def reset
photos.destroy_all
refresh
end
+
+ def generated_slug
+ "#{self.id}-#{self.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')}"
+ end
end
View
4 app/models/category/instagram.rb
@@ -1,10 +1,10 @@
class Category::Instagram < Category
after_create :set_photos_from_instagram
-
+
def refresh
set_photos_from_instagram
end
-
+
def set_photos_from_instagram
remote_account.photos.each_with_index do |photo, i|
Photo.create(
View
6 app/models/photo.rb
@@ -4,9 +4,9 @@ class Photo < ActiveRecord::Base
validates_uniqueness_of :flickr_id, :scope => :category_id, :if => Proc.new{|p| !p.flickr_id.blank?}
validates_uniqueness_of :facebook_photo_id, :scope => :category_id, :if => Proc.new{|p| !p.facebook_photo_id.blank?}
- named_scope :activated, :conditions => {:deleted => false}
- named_scope :limited, :limit => 15
- named_scope :ordered, :order => "position DESC"
+ scope :activated, :conditions => {:deleted => false}
+ scope :limited, :limit => 15
+ scope :ordered, :order => "position DESC"
def mark_as_destroyed
update_attribute(:deleted, true)
View
4 app/models/remote_account.rb
@@ -1,10 +1,10 @@
class RemoteAccount < ActiveRecord::Base
belongs_to :portfolio
has_many :categories, :dependent => :destroy
-
+
AVAILABLE_ACCOUNTS = ["flickr", "facebook", "instagram"]
AVAILABLE_SUBCLASSES = ["RemoteAccount::Flickr", "RemoteAccount::Facebook", "RemoteAccount::InstagramAccount"]
-
+
def class_name
self.class.to_s.demodulize.downcase
end
View
4 app/models/user_session.rb
@@ -3,8 +3,8 @@ class UserSession < Authlogic::Session::Base
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
-
+
def persisted?
false
end
-end
+end
View
0 spec/controllers/portfolios_controller_spec.rb
No changes.
View
4 spec/models/beta_code_spec.rb
@@ -0,0 +1,4 @@
+require "spec_helper"
+
+describe BetaCode do
+end
View
30 spec/models/category_spec.rb
@@ -0,0 +1,30 @@
+require "spec_helper"
+
+describe Category do
+ before(:each) do
+ @category = Category.create :title => "Yeah"
+ end
+
+ it "should be able to reset" do
+ @category.photos << Photo.new
+ @category.photos << Photo.new
+ Photo.count.should == 2
+ mock(@category).refresh
+ @category.reset
+ end
+
+ it "should create a slug on creation" do
+ @category.slug.should == @category.generated_slug
+ end
+
+ it "should generate a slug" do
+ @category.generated_slug.should == "#{@category.id}-yeah"
+ end
+
+ it "should not set a slug on creation if one is given" do
+ category = Category.create :title => "Bonjour", :slug => "hello"
+ category.slug.should == "hello"
+ end
+
+end
+
View
4 spec/models/future_user_spec.rb
@@ -0,0 +1,4 @@
+require "spec_helper"
+
+describe FutureUser do
+end
View
10 spec/models/photo_spec.rb
@@ -0,0 +1,10 @@
+require "spec_helper"
+
+describe Photo do
+ it "should mark photos as destroyed and then scope it" do
+ photo = Photo.create
+ Photo.activated.should == [photo]
+ photo.mark_as_destroyed
+ Photo.activated.should be_empty
+ end
+end
View
21 spec/models/portfolio_spec.rb
@@ -0,0 +1,21 @@
+require "spec_helper"
+
+describe Portfolio do
+ before(:each) do
+ @user = Object.new
+ stub(@user).login{"marcgg"}
+ @portfolio = Portfolio.new
+ stub(@portfolio).user{@user}
+ @portfolio.save
+ end
+
+ it "should set a default css theme" do
+ @portfolio.theme_id.should == 1
+ end
+
+ it "should set a default slug based on the user's login" do
+ @portfolio.slug.should == "marcgg"
+ end
+
+
+end
View
12 spec/models/remote_account_spec.rb
@@ -0,0 +1,12 @@
+require "spec_helper"
+
+describe RemoteAccount do
+ it "should have 3 available accounts" do
+ RemoteAccount::AVAILABLE_ACCOUNTS.size.should == 3
+ RemoteAccount::AVAILABLE_SUBCLASSES.size.should == 3
+ end
+
+ it "should have a class_name based on its class" do
+ RemoteAccount.new.class_name.should == "remoteaccount"
+ end
+end
View
41 spec/models/user_spec.rb
@@ -0,0 +1,41 @@
+describe "spec_helper"
+
+describe User do
+ before(:each) do
+ @user = User.new(:login => "marcgg", :email => "marc@ffocused.com", :password => "abcde", :password_confirmation => "abcde")
+ end
+
+ it "should not be created without a beta code" do
+ @user.should_not be_valid
+ @user.beta_code = BetaCode.create(:code => "kdo").code
+ @user.should be_valid
+ end
+
+ it "should burn the beta code each time" do
+ betacode = BetaCode.create(:code => "kdo")
+ betacode.used.should be_false
+ @user.beta_code = betacode.code
+ @user.save!
+ betacode.reload
+ betacode.used.should be_true
+ end
+
+ context "with a setup user" do
+ before(:each) do
+ @user.beta_code = BetaCode.create(:code => "kdo").code
+ end
+
+ it "should setup a portfolio" do
+ @user.portfolio.should be_nil
+ @user.save!
+ @user.reload
+ @user.portfolio.should_not be_nil
+ end
+
+ it "should be findable by email or login" do
+ @user.save
+ User.find_by_login_or_email("marcgg").should == @user
+ User.find_by_login_or_email("marc@ffocused.com").should == @user
+ end
+ end
+end
View
26 spec/spec_helper.rb
@@ -0,0 +1,26 @@
+# 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
+
+ # 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

0 comments on commit ef2dabc

Please sign in to comment.
Something went wrong with that request. Please try again.