Skip to content

Commit e044ecc

Browse files
author
Rhys Powell
committed
Added specs back in
1 parent 31f728c commit e044ecc

9 files changed

Lines changed: 121 additions & 0 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fabricator(:answer) do
2+
description "MyString"
3+
user ""
4+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fabricator(:program) do
2+
author_username "MyString"
3+
slug "MyString"
4+
title "MyString"
5+
source_code "MyString"
6+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fabricator(:question) do
2+
title "Title"
3+
description "Description"
4+
user
5+
end

spec/fabricators/rel_fabricator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fabricator(:rel) do
2+
slug { "some_slug" }
3+
description { "Some description" }
4+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fabricator(:user) do
2+
email { sequence(:email) { |i| "user#{i}@example.com"} }
3+
password "password"
4+
password_confirmation "password"
5+
username { sequence(:username) { |i| "user#{i}" } }
6+
end

spec/following_policy_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require_relative '../app/models/following_policy'
2+
3+
describe FollowingPolicy do
4+
before(:each) do
5+
@followee = stub()
6+
@follower = stub()
7+
end
8+
9+
it 'can follow another' do
10+
@follower.should_receive(:following?).with(@followee).and_return(false)
11+
policy = FollowingPolicy.new(@follower)
12+
policy.can_follow?(@followee).should be_true
13+
end
14+
15+
it "cannot follow self" do
16+
policy = FollowingPolicy.new(@follower)
17+
policy.following_self?(@follower).should be_true
18+
policy.can_follow?(@follower).should be_false
19+
end
20+
21+
it "cannot follow twice" do
22+
@follower.should_receive(:following?).twice.with(@followee).and_return(true)
23+
policy = FollowingPolicy.new(@follower)
24+
policy.already_following?(@followee).should be_true
25+
policy.can_follow?(@followee).should be_false
26+
end
27+
28+
end

spec/spec_helper.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ENV["RAILS_ENV"] ||= 'test'
2+
require File.expand_path("../../config/environment", __FILE__)
3+
require 'rspec/rails'
4+
require 'database_cleaner'
5+
6+
# Requires supporting ruby files with custom matchers and macros, etc,
7+
# in spec/support/ and its subdirectories.
8+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
9+
10+
RSpec.configure do |config|
11+
# == Mock Framework
12+
#
13+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14+
#
15+
# config.mock_with :mocha
16+
# config.mock_with :flexmock
17+
# config.mock_with :rr
18+
config.mock_with :rspec
19+
20+
DatabaseCleaner.orm = "mongo_mapper"
21+
DatabaseCleaner[:mongo_mapper].strategy = :truncation
22+
23+
config.before(:each) do
24+
DatabaseCleaner[:mongo_mapper].clean
25+
end
26+
end

spec/unit/program_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe Program do
4+
let(:prog) { Program.create(author_username: 'tester', title: 'test title')}
5+
it "sets the slug" do
6+
prog.slug.should == 'test-title'
7+
end
8+
9+
it "makes unique slugs" do
10+
first_prog = Program.create(author_username: 'tester',
11+
title: 'test title #2',
12+
slug: 'test-title')
13+
prog.slug.should_not == first_prog.slug
14+
end
15+
end

spec/unit/sluggifier_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# encoding: utf-8
2+
3+
require 'active_support/all'
4+
require_relative '../../lib/sluggifier'
5+
6+
describe Sluggifier do
7+
describe '.generate' do
8+
it "makes a slug from a title" do
9+
Sluggifier.generate('test a slug').should == 'test-a-slug'
10+
end
11+
12+
context "doesn't allow multiple slugs to be the same" do
13+
let(:all_slugs) { ['test'] }
14+
15+
it "appends a one if there is one repeated slug" do
16+
Sluggifier.generate('test',all_slugs).should == 'test-2'
17+
end
18+
19+
it "appends the next sequential number for repeats" do
20+
all_slugs << 'test-2'
21+
Sluggifier.generate('test',all_slugs).should == 'test-3'
22+
end
23+
end
24+
end
25+
26+
27+
end

0 commit comments

Comments
 (0)