mongoid/mongoid — Issue #1597: Reversing Arrays in 2.4.1.
Author: yfeldblum
Created: 2012-01-15 21:14:21+00:00
State: open

A failing spec:

require "spec_helper"

class Account
include Mongoid::Document

field :names, type: Array
attr_accessible :names
end

describe Account do
describe "an array field" do
context "when there are two elements" do
let(:names) { %w(Bob Sally) }
let!(:account) { Account.create!(:names => names) }

describe "reversing the elements" do
before do
account.names = names.reverse
account.save!
account.reload
end

it "should roundtrip the reversed elements" do
account.names.should == names.reverse
end
end
end
end
end

The failure:

$ rspec spec/models/widget_spec.rb
F

Failures:

1) Account an array field when there are two elements reversing the elements should roundtrip the reversed elements
Failure/Error: account.names.should == names.reverse
expected: ["Sally", "Bob"]
got: ["Bob", "Sally"] (using ==)
Diff:
@@ -1,2 +1,2 @@
-["Sally", "Bob"]
+["Bob", "Sally"]
# ./spec/models/widget_spec.rb:24:in `block (5 levels) in '

Finished in 1.36 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/models/widget_spec.rb:23 # Account an array field when there are two elements reversing the elements should roundtrip the reversed elements

Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'mongoid', '2.4.1'
gem 'bson_ext'
gem 'rspec-rails'
gem 'database_cleaner'

With `ruby-1.9.3-p0`.