Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Migrated tests

  • Loading branch information...
commit 63e1344b67e3f57d7606d964e5a450bddecd554e 1 parent 9e881c5
Corey Ehmke authored
View
1  .rspec
@@ -0,0 +1 @@
+--color
View
4 Gemfile
@@ -1,13 +1,15 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
-# gem "activesupport", ">= 2.3.5"
+gem "activesupport", ">= 2.3.5"
+gem "activemodel"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "rdoc", "~> 3.12"
+ gem "rspec"
gem "bundler"
gem "jeweler", "~> 1.8.4"
gem "simplecov"
View
16 Gemfile.lock
@@ -1,9 +1,14 @@
GEM
remote: http://rubygems.org/
specs:
+ activemodel (3.2.8)
+ activesupport (= 3.2.8)
+ builder (~> 3.0.0)
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
+ builder (3.0.3)
+ diff-lcs (1.1.3)
git (1.2.5)
i18n (0.6.1)
jeweler (1.8.4)
@@ -16,6 +21,14 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.2)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.2)
shoulda (3.1.1)
shoulda-context (~> 1.0)
shoulda-matchers (~> 1.2)
@@ -31,8 +44,11 @@ PLATFORMS
ruby
DEPENDENCIES
+ activemodel
+ activesupport (>= 2.3.5)
bundler
jeweler (~> 1.8.4)
rdoc (~> 3.12)
+ rspec
shoulda
simplecov
View
1  lib/faceted/presenter.rb
@@ -3,6 +3,7 @@ module Faceted
module Presenter
require 'json'
+ require 'active_support/core_ext/hash'
# Class methods ==========================================================
View
87 spec/presenter_spec.rb
@@ -0,0 +1,87 @@
+require 'spec_helper'
+
+class Musician # pretend that this is an AR model
+ attr_accessor :id, :name, :rating, :errors
+ def initialize(params={}); params.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}; end
+ def attributes; {:id => self.id, :name => self.name, :rating => self.rating}; end
+end
+
+class Birthplace # another make-believe AR model
+ attr_accessor :id, :city, :state
+ def initialize(params={}); params.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}; end
+ def attributes; {:id => self.id, :city => self.city, :state => self.state}; end
+end
+
+module MyApi
+
+ class Birthplace
+ include Faceted::Presenter
+ presents :birthplace
+ field :city
+ field :state
+ end
+
+ class Musician
+ include Faceted::Presenter
+ presents :musician
+ field :name
+ field :rating
+ field :birthplace_id
+ end
+
+ describe Musician do
+
+ before do
+
+ @ar_musician = ::Musician.new(:id => 1, :name => 'Johnny Cash', :rating => 'Good')
+ ::Musician.stub(:find) { @ar_musician }
+
+ @ar_birthplace = ::Birthplace.new(:id => 1, :city => 'Kingsland', :state => 'Arkansas')
+ ::Birthplace.stub(:find) { @ar_birthplace }
+
+ end
+
+ describe 'initialized with a presented object' do
+
+ it 'inherits values from its AR counterpart' do
+ musician = MyApi::Musician.new(:id => 1)
+ musician.name.should == 'Johnny Cash'
+ end
+
+ it 'overwrites values from its AR counterpart' do
+ musician = MyApi::Musician.new(:id => 1, :rating => 'Great')
+ musician.rating.should == 'Great'
+ end
+
+ describe 'saves its counterpart' do
+
+ it 'successfully' do
+ musician = MyApi::Musician.new(:id => 1)
+ @ar_musician.should_receive(:save!) { true }
+ musician.save.should be_true
+ end
+
+ it 'handling failure' do
+ musician = MyApi::Musician.new(:id => 1)
+ @ar_musician.should_receive(:save!) { false }
+ musician.save.should be_false
+ end
+
+ it 'failing and populating its errors'
+
+ end
+
+ end
+
+ describe 'with an associated object' do
+
+ it 'initializes the associated object in the correct namespace' do
+ musician = MyApi::Musician.new(:id => 1, :birthplace_id => 1)
+ musician.birthplace.city.should == 'Kingsland'
+ end
+
+ end
+
+ end
+
+end
View
5 spec/spec_helper.rb
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'active_model'
+require 'active_support'
+require 'bundler/setup'
+require 'faceted'
Please sign in to comment.
Something went wrong with that request. Please try again.