Skip to content

Commit

Permalink
Logic around showing support
Browse files Browse the repository at this point in the history
  • Loading branch information
GIT_AUTHOR_NAME authored and veezus committed Mar 3, 2009
1 parent e48bfef commit bf15c16
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/organization.rb
Expand Up @@ -70,5 +70,13 @@ def do_after_approved_actions
def set_status
needs_to_be_approved! if inactive?
end

def show_support_for(pitch)
pitch.supporting_organizations << self
end

def shown_support_for?(pitch)
pitch.supporting_organizations.include? self
end
end

4 changes: 4 additions & 0 deletions app/models/pitch.rb
Expand Up @@ -151,6 +151,10 @@ def featured?
self.feature
end

def show_support!(organization)
supporting_organizations << organization unless supporting_organizations.include?(organization)
end

def feature!
self.update_attribute(:feature, true)
end
Expand Down
25 changes: 25 additions & 0 deletions spec/models/organization_spec.rb
Expand Up @@ -56,4 +56,29 @@
end
end
end

describe "#show_support" do
before do
@organization = Factory(:organization)
@pitch = Factory(:pitch)
end

it "adds the organization to the pitch's supporters" do
lambda{@organization.show_support_for(@pitch)}.should change(@pitch.supporting_organizations, :size).by(1)
end
end

describe "shown_support_for?" do
before do
@organization = Factory(:organization)
@pitch = Factory(:pitch)
end
it "should return true if the organization is in the pitches supporting_organizations" do
@pitch.supporting_organizations.stub!(:include?).and_return(true)
@organization.shown_support_for?(@pitch).should be_true
end
it "should return false otherwise" do
@organization.shown_support_for?(@pitch).should be_false
end
end
end
17 changes: 17 additions & 0 deletions spec/models/pitch_spec.rb
Expand Up @@ -441,6 +441,23 @@
end
end

describe "show_support!" do
before do
@pitch = Factory(:pitch)
@organization = Factory(:organization)
end
it "add the organization to the pitch's supporting organizations" do
@pitch.show_support!(@organization)
@pitch.supporting_organizations.should include(@organization)
end

it "doesn't add the same organization to the pitch's supporting organizations twice" do
@pitch.show_support!(@organization)
lambda{@pitch.show_support!(@organization)}.should change(@pitch.supporting_organizations, :size).by(0)
end

end

describe "featuring" do

describe "feature!" do
Expand Down

0 comments on commit bf15c16

Please sign in to comment.