public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Photo specs
Michael Hartl (author)
Thu Feb 21 13:18:15 -0800 2008
commit  26772b4ac48d2670fbd5eb6f8e03c0632dc33d0c
tree    22cdceb6d59145aa7e65f5891f70d0e727fc6860
parent  52afde02ab5f67f40cf26a3a1dbc9a1b62cfe422
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
0
@@ -1 +1,35 @@
0
+require File.dirname(__FILE__) + '/../spec_helper'
0
+
0
+describe Photo do
0
+
0
+ before(:each) do
0
+ @filename = "rails.png"
0
+ @person = people(:quentin)
0
+ @image = uploaded_file(@filename, "image/png")
0
+ end
0
+
0
+ it "should upload successfully" do
0
+ new_photo.should be_valid
0
+ end
0
+
0
+ it "should be able to make a primary photo" do
0
+ new_photo(:primary => true).should be_primary
0
+ end
0
+
0
+ it "should be able to make a non-primary photo" do
0
+ new_photo(:primary => false).should_not be_primary
0
+ end
0
+
0
+
0
+ it "should have an associated person" do
0
+ new_photo.person.should == @person
0
+ end
0
+
0
+ private
0
+
0
+ def new_photo(options = {})
0
+ Photo.new({ :uploaded_data => @image,
0
+ :person => @person }.merge(options))
0
+ end
0
+end
...
31
32
33
34
 
35
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
...
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
0
@@ -31,11 +31,25 @@
0
   #
0
   # == Mock Framework
0
   #
0
- # RSpec uses it's own mocking framework by default. If you prefer to
0
+ # RSpec uses its own mocking framework by default. If you prefer to
0
   # use mocha, flexmock or RR, uncomment the appropriate line:
0
   #
0
   # config.mock_with :mocha
0
   # config.mock_with :flexmock
0
   # config.mock_with :rr
0
+
0
+ # Simulate an uploaded file.
0
+ def uploaded_file(filename, content_type)
0
+ t = Tempfile.new(filename)
0
+ t.binmode
0
+ path = File.join(RAILS_ROOT, "spec", "images", filename)
0
+ FileUtils.copy_file(path, t.path)
0
+ (class << t; self; end).class_eval do
0
+ alias local_path path
0
+ define_method(:original_filename) {filename}
0
+ define_method(:content_type) {content_type}
0
+ end
0
+ return t
0
+ end
0
 end

Comments

    No one has commented yet.