Skip to content

Commit

Permalink
Merge pull request railsadminteam#1032 from mshibuya/fix-ci-failures
Browse files Browse the repository at this point in the history
Fixed CI failures
  • Loading branch information
bbenezech committed Mar 12, 2012
2 parents 3a87bc5 + a04ceca commit 439517f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Gemfile31
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ group :development, :test do
end
end

gem 'bson_ext'
gem 'mongoid'
gem 'cancan'
end

Expand Down
5 changes: 5 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
sequence(:name) { |n| "League #{n}" }
end

factory :division do
sequence(:custom_league_id)
sequence(:name) { |n| "Division #{n}" }
end

factory :fan do
sequence(:name) { |n| "Fan #{n}" }
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'factory_girl'
require 'factories'
require 'database_helpers'
require 'support/tableless'

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
Expand Down
27 changes: 27 additions & 0 deletions spec/support/tableless.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end

def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end

def self.columns_hash
@columns_hash ||= Hash[columns.map { |column| [column.name, column] }]
end

def self.column_names
@column_names ||= columns.map { |column| column.name }
end

def self.column_defaults
@column_defaults ||= columns.map { |column| [column.name, nil] }.inject({}) { |m, e| m[e[0]] = e[1]; m }
end

# Override the save method to prevent exceptions.
def save(validate = true)
validate ? valid? : true
end
end
23 changes: 14 additions & 9 deletions spec/unit/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,30 @@ class ARComment < ActiveRecord::Base

describe "#query_conditions" do
before do
@abstract_model = RailsAdmin::AbstractModel.new('Ball')
@abstract_model = RailsAdmin::AbstractModel.new('Team')
@teams = [{}, {:name=>'somewhere foos'}, {:manager=>'foo junior'}].
map{|h| FactoryGirl.create :team, h}
end

it "returns query statement" do
@abstract_model.send(:query_conditions, "word").should == ["(balls.color #{@like} ?) OR (balls.type #{@like} ?)", "%word%", "%word%"]
it "makes conrrect query" do
@abstract_model.all(:query => "foo").sort.should == @teams[1..2]
end
end

describe "#filter_conditions" do
before do
@abstract_model = RailsAdmin::AbstractModel.new('Team')
@division = FactoryGirl.create :division, :name => 'bar division'
@teams = [{}, {:division=>@division}, {:name=>'somewhere foos', :division=>@division}, {:name=>'nowhere foos'}].
map{|h| FactoryGirl.create :team, h}
end

it "returns filter statement" do
@abstract_model.send(
:filter_conditions,
{"name" => {"0000" => {:o=>"is", :v=>"Jets"}},
"division" => {"0001" => {:o=>"like", :v=>"1"}}}
).should == ["((teams.name #{@like} ?)) AND ((divisions.name #{@like} ?) OR (teams.division_id = ?))", "Jets", "%1%", 1]
it "makes conrrect query" do
@abstract_model.all(
:filters => {"name" => {"0000" => {:o=>"like", :v=>"foo"}},
"division" => {"0001" => {:o=>"like", :v=>"bar"}}},
:include => :division
).should == [@teams[2]]
end
end

Expand Down
30 changes: 16 additions & 14 deletions spec/unit/adapters/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class MongoComment
end

it 'lists associations' do
@post.associations.map{|a|a[:name]}.should == [:mongo_blog, :mongo_categories, :mongo_comments]
@post.associations.map{|a|a[:name].to_s}.sort.should == ['mongo_blog', 'mongo_categories', 'mongo_comments']
end

it 'reads correct and know types in [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do
(@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.sort.should == [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]
(@post.associations + @blog.associations + @user.associations).map{|a|a[:type].to_s}.uniq.sort.should == ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
end

it "has correct parameter of belongs_to association" do
Expand Down Expand Up @@ -164,7 +164,7 @@ class MongoComment
end

it "maps Mongoid column types to RA types" do
@abstract_model.properties.sort{|a,b| a[:name] <=> b[:name] }.should == [
@abstract_model.properties.sort{|a,b| a[:name].to_s <=> b[:name].to_s }.should == [
{ :name => :_id,
:pretty_name => "Id",
:nullable? => true,
Expand Down Expand Up @@ -427,26 +427,28 @@ class MongoComment
describe "#query_conditions" do
before do
@abstract_model = RailsAdmin::AbstractModel.new('Article')
@articles = [{}, {:title=>'Many foos'}, {:body=>'foo shortage'}].
map{|h| FactoryGirl.create :article, h}
end

it "returns query statement" do
@abstract_model.send(:query_conditions, "word").should ==
{"$or"=>[{"title"=>/word/}, {"body"=>/word/}]}
it "makes conrrect query" do
@abstract_model.all(:query => "foo").sort.should == @articles[1..2]
end
end

describe "#filter_conditions" do
before do
@abstract_model = RailsAdmin::AbstractModel.new('Article')
@author = FactoryGirl.create :author, :name => 'king of bar'
@articles = [{}, {:author=>@author}, {:title=>'Many foos', :author=>@author}, {:title=>'Great foo'}].
map{|h| FactoryGirl.create :article, h}
end

it "returns filter statement" do
@author = FactoryGirl.create :author, :name => 'Author 1'
@abstract_model.send(
:filter_conditions,
{"title" => {"0000" => {:o=>"is", :v=>"foo"}},
"author" => {"0001" => {:o=>"like", :v=>"1"}}}
).should == {"$and"=>[{"title"=>"foo"}, {"author_id"=>{"$in"=>[@author.id]}}]}
it "makes conrrect query" do
@abstract_model.all(:filters =>
{"title" => {"0000" => {:o=>"like", :v=>"foo"}},
"author" => {"0001" => {:o=>"like", :v=>"bar"}}}
).should == [@articles[2]]
end
end

Expand Down Expand Up @@ -565,7 +567,7 @@ class MongoComment
end

it "accepts array value" do
params = {:array_field => '[1,3]'}
params = {:array_field => '[1, 3]'}
@controller.send(:sanitize_params_for!, 'create', @abstract_model.config, params)
params[:array_field].should == [1, 3]
end
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/config/fields/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
end

it "should have correct fields when polymorphic_type column comes ahead of polymorphic foreign_key column" do
class CommentReversed < ActiveRecord::Base
@columns = [ActiveRecord::ConnectionAdapters::Column.new('commentable_type', nil, 'string'),
ActiveRecord::ConnectionAdapters::Column.new('commentable_id', nil, 'integer')]
class CommentReversed < Tableless
column :commentable_type, :string
column :commentable_id, :integer
belongs_to :commentable, :polymorphic => true
end
RailsAdmin.config(CommentReversed).fields.map(&:name).sort.should == [:commentable, :commentable_id, :commentable_type]
RailsAdmin.config(CommentReversed).fields.map{|f| f.name.to_s}.sort.should == ['commentable', 'commentable_id', 'commentable_type']
end

context 'of a Paperclip installation' do
Expand Down

0 comments on commit 439517f

Please sign in to comment.