diff --git a/spec/database.rb b/spec/database.rb index 7593d13..482754b 100644 --- a/spec/database.rb +++ b/spec/database.rb @@ -5,17 +5,10 @@ ActiveRecord::Migration.suppress_messages do end end - ActiveRecord::Migration.create_table "simple_new_dsls", :force => true do |t| - t.string "status" - end - ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t| - t.string "status" - end - ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t| - t.string "status" - end - ActiveRecord::Migration.create_table "users", :force => true do |t| - t.string "status" + %w(simple_new_dsls multiple_simple_new_dsls implemented_abstract_class_dsls users multiple_namespaceds).each do |table_name| + ActiveRecord::Migration.create_table table_name, :force => true do |t| + t.string "status" + end end ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t| diff --git a/spec/models/active_record/namespaced.rb b/spec/models/active_record/namespaced.rb new file mode 100644 index 0000000..2e3c145 --- /dev/null +++ b/spec/models/active_record/namespaced.rb @@ -0,0 +1,16 @@ +class MultipleNamespaced < ActiveRecord::Base + include AASM + + aasm(:status, namespace: :car) do + state :unsold, initial: true + state :sold + + event :sell do + transitions from: :unsold, to: :sold + end + + event :return do + transitions from: :sold, to: :unsold + end + end +end diff --git a/spec/unit/persistence/active_record_persistence_multiple_spec.rb b/spec/unit/persistence/active_record_persistence_multiple_spec.rb index 33e856a..dff3658 100644 --- a/spec/unit/persistence/active_record_persistence_multiple_spec.rb +++ b/spec/unit/persistence/active_record_persistence_multiple_spec.rb @@ -331,6 +331,23 @@ if defined?(ActiveRecord) expect(MultipleSimpleNewDsl.unknown_scope).to contain_exactly(dsl2) end end + + context "when namespeced" do + it "add namespaced scopes" do + expect(MultipleNamespaced).to respond_to(:car_unsold) + expect(MultipleNamespaced).to respond_to(:car_sold) + + expect(MultipleNamespaced.car_unsold.is_a?(ActiveRecord::Relation)).to be_truthy + expect(MultipleNamespaced.car_sold.is_a?(ActiveRecord::Relation)).to be_truthy + end + it "add unnamespaced scopes" do + expect(MultipleNamespaced).to respond_to(:unsold) + expect(MultipleNamespaced).to respond_to(:sold) + + expect(MultipleNamespaced.unsold.is_a?(ActiveRecord::Relation)).to be_truthy + expect(MultipleNamespaced.sold.is_a?(ActiveRecord::Relation)).to be_truthy + end + end end # scopes describe "direct assignment" do