spec/gravtastic_spec.rb in gravtastic-1.5.2 vs spec/gravtastic_spec.rb in gravtastic-1.6.0
- old
+ new
@@ -11,31 +11,70 @@
describe ".gravatar_source" do
it "is nil if unset" do
@klass.gravatar_source.should be_nil
end
+
+ it "returns the value of @gravatar_source" do
+ @klass.instance_variable_set('@gravatar_source', :foo)
+ @klass.gravatar_source.should == :foo
+ end
end
+ describe ".gravatar_defaults" do
+
+ it "it nil if unset" do
+ @klass.gravatar_defaults.should be_nil
+ end
+
+ it "returns the value of @gravatar_defaults" do
+ @klass.instance_variable_set('@gravatar_defaults', :foo)
+ @klass.gravatar_source.should == :foo
+ end
+
+ end
+
describe ".has_gravatar" do
- it "sets .gravatar_source to email by default" do
+ it "sets .gravatar_source to :email by default" do
@klass.has_gravatar
@klass.gravatar_source.should == :email
end
+ it "sets .gravatar_defaults to { :rating => 'PG', :secure => false } by default" do
+ @klass.has_gravatar
+ @klass.gravatar_defaults.should == { :rating => 'PG', :secure => false }
+ end
+
+ it "keeps either :rating or :secure if only the other is passed as a default" do
+ @klass.has_gravatar :defaults => { :secure => true }
+ @klass.gravatar_defaults.should == { :rating => 'PG', :secure => true }
+ end
+
it "changes .gravatar_source" do
lambda {
@klass.has_gravatar :on => :other_method
}.should change(@klass, :gravatar_source)
end
+ it "changes .gravatar_defaults" do
+ lambda {
+ @klass.has_gravatar :defaults => { :rating => 'R18' }
+ }.should change(@klass, :gravatar_defaults)
+ end
+
it "sets .gravatar_source to the value of :on" do
@klass.has_gravatar :on => :other_method
@klass.gravatar_source.should == :other_method
end
+ it "sets .gravatar_defaults to the value of :defaults" do
+ @klass.has_gravatar :defaults => { :rating => 'R18'}
+ @klass.gravatar_defaults.should == { :rating => 'R18', :secure => false }
+ end
+
end
describe ".has_gravatar?" do
it "is true when .gravatar_source is not nil" do
@@ -88,10 +127,11 @@
before(:each) do
@user.stub!(:email).and_return('joe@example.com')
@user.stub!(:name).and_return('Joe Bloggs')
@user.class.stub!(:gravatar_source).and_return(:email)
+ @user.class.stub!(:gravatar_defaults).and_return({:rating => 'PG'})
end
it "is not nil when .gravatar_source is not nil" do
@user.gravatar_url.should_not be_nil
end
@@ -145,9 +185,14 @@
@user.gravatar_url(:size => 20, :rating => 'R18', :default => :monsterid).should == valid_gravatar_url + '?d=monsterid&r=R18&s=20'
end
it "defaults to a 'PG' rating" do
@user.gravatar_url(:rating => 'PG').should == @user.gravatar_url
+ end
+
+ it "uses the defaults from .gravatar_defaults" do
+ @user.class.stub!(:gravatar_defaults).and_return({ :size => 20, :rating => 'R18'})
+ @user.gravatar_url.should == valid_gravatar_url + '?r=R18&s=20'
end
def valid_gravatar_url # :nodoc:
'http://gravatar.com/avatar/f5b8fb60c6116331da07c65b96a8a1d1.png'
end
\ No newline at end of file