Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 60 lines (54 sloc) 1.972 kB
3a274e7 @philc Include a StubHelper to make writing unit tests easier. Fix the app_t…
philc authored
1 # A set of methods for stubbing out objects from our database. Some objects have lots of dependencies. These
2 # methods make creating those stubbed objects less work and less repetitive.
3 module StubHelper
4
5 # Creates a Commit.
6 # - user: a User who is the author of this commit.
181b096 @philc When determining the commits composing a saved search, exclude those …
philc authored
7 def stub_commit(sha, user)
8 commit = Commit.new(:sha => sha)
3a274e7 @philc Include a StubHelper to make writing unit tests easier. Fix the app_t…
philc authored
9 stub(commit).git_repo { GitRepo.new(:name => "my_repo") }
10 stub(commit).user { user }
11
12 commit_author = user.name.dup
13 stub(commit_author).user { user }
14 grit_commit = OpenStruct.new(
181b096 @philc When determining the commits composing a saved search, exclude those …
philc authored
15 :id => sha, :sha => sha, :id_abbrev => sha,
16 :repo_name => "my_repo",
ad2d92f @philc In comment emails include the author's email in addition to their dis…
philc authored
17 :short_message => "message", :author => Grit::Actor.new(user.name, user.email),
18 :date => Time.now, :diffs => [])
3a274e7 @philc Include a StubHelper to make writing unit tests easier. Fix the app_t…
philc authored
19 stub(commit).grit_commit { grit_commit }
20 commit
21 end
181b096 @philc When determining the commits composing a saved search, exclude those …
philc authored
22 end
23
b42122e @cespare Implement authenticated API routes.
cespare authored
24 class StubPinion
25 def css_url(_) "" end
26 def js_url(_) "" end
27 end
28
181b096 @philc When determining the commits composing a saved search, exclude those …
philc authored
29 # This dataset stub can be used to spy on the parameters being sent through our datasets. Use it like this:
30 # @dataset = DatasetStub.new([movie1, movie2])
31 # Movie.stubs(:dataset).returns(@dataset)
32 class DatasetStub < Array
33 attr_accessor :params
34 def initialize(array = [])
35 @array = array
36 @params = {}
37 super
38 end
39
40 def all(*args) self end
41 def order(*args) params[:order] = args; self end
42 def filter(*args) params[:filter] = args; self end
43 def limit(*args) params[:limit] = args; self end
44 def and(*args) params[:and] = args; self end
45 def or(*args) params[:or] = args; self end
46 def select(*args) params[:select] = args; self; end
47 def update(*args) params[:update] = args; self end
48 def first(*args) params[:first] = args; @array.first end
49 def server(server) params[:server] = server; self end
50 def delete(*args) self end
51 def eager(*args) self end
52 def eager_graph(*args) self end
53 def qualify() self end
54 def distinct() self end
55 def with_sql(sql) self end
56 def model() Class end
57 def sql() "" end
58 def first_source_alias() "" end
59 end
Something went wrong with that request. Please try again.