Skip to content

Commit

Permalink
Updated specs to use 'name' instead of 'filename'.
Browse files Browse the repository at this point in the history
Running specs: 521 examples, 246 failures. (As expected!)
  • Loading branch information
nelstrom committed Nov 9, 2008
1 parent d83cb7d commit 42852ec
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 80 deletions.
14 changes: 7 additions & 7 deletions spec/controllers/admin/text_asset_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
post :new,
current_asset[:symbol] => send("#{current_asset[:name]}_params"),
:asset_type => current_asset[:name]
@text_asset = current_asset[:class].find_by_filename('Test')
@text_asset = current_asset[:class].find_by_name('Test')
end


Expand Down Expand Up @@ -188,9 +188,9 @@
before :each do
post :new,
current_asset[:symbol] => send("#{current_asset[:name]}_params",
:filename => nil),
:name => nil),
:asset_type => current_asset[:name]
@text_asset = current_asset[:class].find_by_filename('Test')
@text_asset = current_asset[:class].find_by_name('Test')
end


Expand Down Expand Up @@ -219,10 +219,10 @@
before :each do
post :new,
current_asset[:symbol] => send("#{current_asset[:name]}_params",
:filename => 'Test'),
:name => 'Test'),
:continue => 'Save and Continue Editing',
:asset_type => current_asset[:name]
@text_asset = current_asset[:class].find_by_filename('Test')
@text_asset = current_asset[:class].find_by_name('Test')
end


Expand Down Expand Up @@ -314,7 +314,7 @@
post :edit,
:id => text_asset_id('main'),
current_asset[:symbol] => send("#{current_asset[:name]}_params",
:filename => nil),
:name => nil),
:asset_type => current_asset[:name]
end

Expand Down Expand Up @@ -415,7 +415,7 @@


it "should destroy the #{current_asset[:name]}" do
current_asset[:class].find_by_filename('main').should be_nil
current_asset[:class].find_by_name('main').should be_nil
end


Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/text_asset_controller_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@


it "should create a new #{current_asset[:name]} based on the uploaded file" do
# filename should be hypenated (where appropriate)
current_asset[:class].find_by_filename('hello-world.txt').content.
# name should be hypenated (where appropriate)
current_asset[:class].find_by_name('hello-world.txt').content.
should eql("Hello World! (text file)")
end

Expand All @@ -269,9 +269,9 @@
private

def mock_uploader(file, type = 'text/plain', file_class = ActionController::UploadedStringIO)
filename = "%s/%s" % [ File.dirname(__FILE__) + '/../../fixtures', file ]
name = "%s/%s" % [ File.dirname(__FILE__) + '/../../fixtures', file ]
uploader = file_class.new
uploader.original_path = filename
uploader.original_path = name
uploader.content_type = type

def uploader.read
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/site_controller_mixins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@
describe "with regard to Last-Modified date" do

before :each do
@dependant = current_asset[:class].new(:filename => 'dependant')
@dependency = current_asset[:class].new(:filename => 'dependency')
@dependant = current_asset[:class].new(:name => 'dependant')
@dependency = current_asset[:class].new(:name => 'dependency')
save_asset_at(@dependant, 1990)
end

Expand Down
20 changes: 10 additions & 10 deletions spec/models/stylesheet_and_javascript_dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
describe "During save, #{current_tag[:name].pluralize} containing <r:#{current_tag[:name]}> tags" do

before :each do
@text_asset = current_tag[:class].new(:filename => 'dependant')
@text_asset = current_tag[:class].new(:name => 'dependant')
@text_asset.content = %{<r:#{current_tag[:name]} name="main" />}
end

Expand Down Expand Up @@ -67,7 +67,7 @@

describe "A saved #{current_tag[:name]}'s effectively_updated_at method" do
before :each do
@dependant = current_tag[:class].new(:filename => 'dependant')
@dependant = current_tag[:class].new(:name => 'dependant')
save_asset_at(@dependant, 1990)
end

Expand All @@ -94,10 +94,10 @@
@dependant.content = %{<r:#{current_tag[:name]} name="dependency" />}
save_asset_at(@dependant, 1994)

@dependency = current_tag[:class].new(:filename => 'dependency')
@dependency = current_tag[:class].new(:name => 'dependency')
save_asset_at(@dependency, 1995)

@dependant = current_tag[:class].find_by_filename('dependant')
@dependant = current_tag[:class].find_by_name('dependant')
@dependant.dependencies.effectively_updated_at.should == Time.gm(1995)
end

Expand All @@ -106,32 +106,32 @@
@dependant.content = %{<r:#{current_tag[:name]} name="dependency" />}
save_asset_at(@dependant, 1991)

@dependency = current_tag[:class].new(:filename => 'dependency')
@dependency = current_tag[:class].new(:name => 'dependency')
save_asset_at(@dependency, 1995)

save_asset_at(@dependant, 1999)

@dependant = current_tag[:class].find_by_filename('dependant')
@dependant = current_tag[:class].find_by_name('dependant')
@dependant.dependencies.effectively_updated_at.should == Time.gm(1999)
end


it "should reflect a dependency's change date/time once that dependency is updated" do
@dependency = current_tag[:class].new(:filename => 'dependency')
@dependency = current_tag[:class].new(:name => 'dependency')
save_asset_at(@dependency, 1990)

@dependant.content = %{<r:#{current_tag[:name]} name="dependency" />}
save_asset_at(@dependant, 1992)

save_asset_at(@dependency, 1993)

@dependant = current_tag[:class].find_by_filename('dependant')
@dependant = current_tag[:class].find_by_name('dependant')
@dependant.dependencies.effectively_updated_at.should == Time.gm(1993)
end


it "should reflect a dependency's deletion date/time when that dependency file is removed" do
@dependency = current_tag[:class].new(:filename => 'dependency')
@dependency = current_tag[:class].new(:name => 'dependency')
save_asset_at(@dependency, 1996)

@dependant.content = %{<r:#{current_tag[:name]} name="dependency" />}
Expand All @@ -140,7 +140,7 @@
Time.stub!(:now).and_return(Time.gm(1998))
@dependency.destroy

@dependant = current_tag[:class].find_by_filename('dependant')
@dependant = current_tag[:class].find_by_name('dependant')
@dependant.dependencies.effectively_updated_at.should == Time.gm(1998)
end

Expand Down
62 changes: 31 additions & 31 deletions spec/models/stylesheet_and_javascript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,65 @@
end


it 'should limit the filename to 100 characters' do
@record.filename = 'a' * 100
it 'should limit the name to 100 characters' do
@record.name = 'a' * 100
@record.should be_valid

@record.filename = 'a' * 101
@record.name = 'a' * 101
@record.should_not be_valid
end


it 'should not allow an empty filename' do
@record.filename = ''
it 'should not allow an empty name' do
@record.name = ''
@record.should_not be_valid
end


it 'should require unique filenames (within same subclass)' do
@record.filename = 'abc.123'
it 'should require unique names (within same subclass)' do
@record.name = 'abc.123'
@record.save!

@invalid_record = current_asset.new(:filename => 'abc.123')
@invalid_record = current_asset.new(:name => 'abc.123')
@invalid_record.should_not be_valid
@invalid_record.should have(1).error_on(:filename)
@invalid_record.errors.on(:filename).should == 'filename already in use'
@invalid_record.should have(1).error_on(:name)
@invalid_record.errors.on(:name).should == 'name already in use'
end


it 'should permit the same filename as a stylesheet and javascript' do
@record.filename = 'abc.123'
it 'should permit the same name as a stylesheet and javascript' do
@record.name = 'abc.123'
@record.save!

if current_asset == Stylesheet
@record_of_other_subclass = Javascript.new(:filename => 'abc.123')
@record_of_other_subclass = Javascript.new(:name => 'abc.123')
elsif current_asset == Javascript
@record_of_other_subclass = Stylesheet.new(:filename => 'abc.123')
@record_of_other_subclass = Stylesheet.new(:name => 'abc.123')
end
@record_of_other_subclass.should be_valid
end


it 'should allow filenames with alphanumeric chars, underscores, periods, & hyphens' do
@record.filename = 'abc'
it 'should allow names with alphanumeric chars, underscores, periods, & hyphens' do
@record.name = 'abc'
@record.should be_valid

@record.filename = 'ABC'
@record.name = 'ABC'
@record.should be_valid

@record.filename = 'Abc123'
@record.name = 'Abc123'
@record.should be_valid

@record.filename = 'aBc.123'
@record.name = 'aBc.123'
@record.should be_valid

@record.filename = 'aBc_123'
@record.name = 'aBc_123'
@record.should be_valid

@record.filename = 'aBc-123'
@record.name = 'aBc-123'
@record.should be_valid

@record.filename = 'a.B-c.1_2-3'
@record.name = 'a.B-c.1_2-3'
@record.should be_valid
end

Expand All @@ -84,28 +84,28 @@
%w[! @ # $ % ^ & * ( ) { } \ / < > + = ? , : ; ' "] +
[' ', "\t", "\n", "\r", '[', ']']
).each do |invalid_char|
it "should not allow filenames with invalid characters (#{invalid_char.inspect})" do
@record.filename = "abc#{invalid_char}123"
it "should not allow names with invalid characters (#{invalid_char.inspect})" do
@record.name = "abc#{invalid_char}123"
@record.should_not be_valid
@record.should have(1).error_on(:filename)
@record.errors.on(:filename).should == 'invalid format'
@record.should have(1).error_on(:name)
@record.errors.on(:name).should == 'invalid format'
end
end


it 'should automatically sort by filename' do
@record.filename = 'a_is_for_apple'
it 'should automatically sort by name' do
@record.name = 'a_is_for_apple'
@record.save!

@record = current_asset.new
@record.filename = 'j_is_for_jacks'
@record.name = 'j_is_for_jacks'
@record.save!

@record = current_asset.new
@record.filename = 'c_is_for_chocolate_frosted_sugar_bombs'
@record.name = 'c_is_for_chocolate_frosted_sugar_bombs'
@record.save!

current_asset.find(:all).should == current_asset.find(:all).sort_by { |item| item[:filename] }
current_asset.find(:all).should == current_asset.find(:all).sort_by { |item| item[:name] }
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/stylesheet_and_javascript_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end


it "should render an error when the 'name' attribute calls out an invalid filename" do
it "should render an error when the 'name' attribute calls out an invalid name" do
@page.should render(%{<r:#{current_tag[:name]} name="bogus asset name" />}).with_error(
"#{current_tag[:name]} not found")
end
Expand Down Expand Up @@ -201,7 +201,7 @@
end


it "should render an error when the 'name' attribute calls out an invalid filename" do
it "should render an error when the 'name' attribute calls out an invalid name" do
@text_asset.content = %{<r:#{current_tag[:name]} name="bogus asset name" />}
lambda{@text_asset.render}.should raise_error(
current_tag[:asset_class]::TagError,
Expand Down
4 changes: 2 additions & 2 deletions spec/models/text_asset_response_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def initialize(body = '', headers = {})

private

def file(filename)
open(filename) { |f| f.read } rescue ''
def file(name)
open(name) { |f| f.read } rescue ''
end


Expand Down
4 changes: 2 additions & 2 deletions spec/models/user_action_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@


it 'should observe stylesheet update' do
model = Stylesheet.find_by_filename('main')
model = Stylesheet.find_by_name('main')
model.attributes = model.attributes.dup
model.save.should == true
model.updated_by.should == @user
end


it 'should observe javascript update' do
model = Javascript.find_by_filename('main')
model = Javascript.find_by_name('main')
model.attributes = model.attributes.dup
model.save.should == true
model.updated_by.should == @user
Expand Down
20 changes: 10 additions & 10 deletions spec/scenarios/javascripts_scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ def load

helpers do

def create_javascript(filename, attributes={})
def create_javascript(name, attributes={})
create_model :javascript,
filename.symbolize,
name.symbolize,
javascript_params(
attributes.reverse_merge(:filename => filename) )
attributes.reverse_merge(:name => name) )
end


def javascript_params(attributes={})
filename = attributes[:filename] || unique_javascript_filename
name = attributes[:name] || unique_javascript_name
{
:filename => filename,
:content => "javascript content for #{filename}"
:name => name,
:content => "javascript content for #{name}"
}.merge(attributes)
end

Expand All @@ -42,11 +42,11 @@ def javascript_id(symbolic_name)

private

@@unique_javascript_filename_call_count = 0
@@unique_javascript_name_call_count = 0

def unique_javascript_filename
@@unique_javascript_filename_call_count += 1
"javascript-#{@@unique_javascript_filename_call_count}.js"
def unique_javascript_name
@@unique_javascript_name_call_count += 1
"javascript-#{@@unique_javascript_name_call_count}.js"
end

end
Expand Down
Loading

0 comments on commit 42852ec

Please sign in to comment.