diff --git a/spec/factories/member.rb b/spec/factories/member.rb index 23a3d7fa6..7c7c08ed0 100644 --- a/spec/factories/member.rb +++ b/spec/factories/member.rb @@ -1,8 +1,9 @@ FactoryGirl.define do sequence(:email) { |n| "member#{n}@example.com" } + sequence(:login_name) { |n| "member#{n}" } factory :member, aliases: [:author, :owner] do - login_name 'member1' + login_name { generate(:login_name) } password 'password1' email { generate(:email) } tos_agreement true diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 58dc4a591..4a01f43d3 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -7,7 +7,7 @@ describe Garden do end it "should have a slug" do - @garden.slug.should == "member1-springfield-community-garden" + @garden.slug.should match(/member\d+-springfield-community-garden/) end it "should have a description" do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 130a6006e..0a4570ac2 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -15,13 +15,13 @@ describe 'member' do @member.save @member2 = Member.find(@member.id) @member2.should be_an_instance_of Member - @member2.login_name.should == "member1" + @member2.login_name.should match(/member\d+/) @member2.encrypted_password.should_not be_nil end it 'should have a friendly slug' do @member.save - @member.slug.should == "member1" + @member.slug.should match(/member\d+/) end it 'should have a default garden' do @@ -35,8 +35,9 @@ describe 'member' do end it 'should stringify as the login_name' do - @member.to_s.should == 'member1' - "#{@member}".should == 'member1' + @member.save + @member.to_s.should match(/member\d+/) + "#{@member}".should match(/member\d+/) end it 'should be able to fetch posts' do @@ -67,4 +68,13 @@ describe 'member' do end end + context 'same :login_name' do + it "should not allow two members with the same login_name" do + FactoryGirl.create(:member, :login_name => "login-name") + member = FactoryGirl.build(:member, :login_name => "login-name") + member.should_not be_valid + member.errors[:login_name].should include("has already been taken") + end + end + end diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 60b22d3df..573847564 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -12,15 +12,15 @@ describe Planting do it "generates an owner" do @planting.owner.should be_an_instance_of Member - @planting.owner.login_name.should match /^member1$/ + @planting.owner.login_name.should match /^member\d+$/ end it "generates a location" do - @planting.location.should match /^member1's Springfield Community Garden$/ + @planting.location.should match /^member\d+'s Springfield Community Garden$/ end it "should have a slug" do - @planting.slug.should == "member1-springfield-community-garden-tomato" + @planting.slug.should match /^member\d+-springfield-community-garden-tomato$/ end end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 86ee3bb58..7b95d76cb 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -40,7 +40,7 @@ describe "crops/show" do it "links to people who are growing this crop" do render - rendered.should contain "member1" + rendered.should contain /member\d+/ rendered.should contain "Springfield Community Garden" end diff --git a/spec/views/layouts/application_spec.rb b/spec/views/layouts/application_spec.rb index a29e668c5..426579e9b 100644 --- a/spec/views/layouts/application_spec.rb +++ b/spec/views/layouts/application_spec.rb @@ -30,7 +30,7 @@ describe 'layouts/application.html.haml', :type => "view" do end it 'should show login name' do - rendered.should contain 'member1' + rendered.should contain /member\d+/ end it 'should have a "Post" link' do diff --git a/spec/views/members/index.html.haml_spec.rb b/spec/views/members/index.html.haml_spec.rb index 4a4c52951..24a8d6845 100644 --- a/spec/views/members/index.html.haml_spec.rb +++ b/spec/views/members/index.html.haml_spec.rb @@ -14,8 +14,8 @@ describe "members/index" do end it "does not truncate short names" do - rendered.should contain "member1" - rendered.should_not contain "member1..." + rendered.should contain /member\d+/ + rendered.should_not contain /member\d+\.\.\./ end it "counts the number of members" do diff --git a/spec/views/members/show.rss.builder_spec.rb b/spec/views/members/show.rss.builder_spec.rb index a4be8cb48..320229e3a 100644 --- a/spec/views/members/show.rss.builder_spec.rb +++ b/spec/views/members/show.rss.builder_spec.rb @@ -11,7 +11,7 @@ describe 'members/show.rss.builder', :type => "view" do end it 'shows RSS feed title' do - rendered.should contain "member1's recent posts" + rendered.should contain /member\d+'s recent posts/ end it 'shows content of posts' do diff --git a/spec/views/plantings/index.html.haml_spec.rb b/spec/views/plantings/index.html.haml_spec.rb index 1b026ac6d..85f53771a 100644 --- a/spec/views/plantings/index.html.haml_spec.rb +++ b/spec/views/plantings/index.html.haml_spec.rb @@ -25,7 +25,7 @@ describe "plantings/index" do it "renders a list of plantings" do rendered.should contain 'Tomato' rendered.should contain 'Maize' - rendered.should contain "member1's Springfield Community Garden" + rendered.should contain /member\d+'s Springfield Community Garden/ end it "shows descriptions where they exist" do diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 845fb47d4..703d50347 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -11,7 +11,7 @@ describe "posts/show" do FactoryGirl.create(:post, :author => @author)) render # show the name of the member who posted the post - rendered.should match(/member1/) + rendered.should match(/member\d+/) # Subject goes in title rendered.should match(/This is some text./) # shouldn't show the subject on a single post page