Sha256: 0b755e0d568fee0661d334dd36c826713eb5cd9a2840e4b5e011fc261a58cc4c

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8
require File.join(File.dirname(__FILE__), "../spec_helper.rb")

describe "Her::Model and ActiveModel::Dirty" do
  context "checking dirty attributes" do
    before do
      Her::API.setup :url => "https://api.example.com" do |builder|
        builder.use Her::Middleware::FirstLevelParseJSON
        builder.use Faraday::Request::UrlEncoded
        builder.adapter :test do |stub|
          stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
          stub.put("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
          stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
        end
      end

      spawn_model "Foo::User" do
        attributes :fullname, :email
      end
    end

    context "for existing resource" do
      it "tracks dirty attributes" do
        user = Foo::User.find(1)
        user.fullname = "Tobias Fünke"
        user.fullname_changed?.should be_true
        user.email_changed?.should be_false
        user.should be_changed
        user.save
        user.should_not be_changed
      end
    end

    context "for new resource" do
      it "tracks dirty attributes" do
        user = Foo::User.new
        user.fullname = "Tobias Fünke"
        user.fullname_changed?.should be_true
        user.should be_changed
        user.save
        user.should_not be_changed
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
her-0.6.4 spec/model/dirty_spec.rb
her-0.6.3 spec/model/dirty_spec.rb
her-0.6.2 spec/model/dirty_spec.rb
her-0.6.1 spec/model/dirty_spec.rb
her-0.6 spec/model/dirty_spec.rb
her-0.5.5 spec/model/dirty_spec.rb
her-0.5.4 spec/model/dirty_spec.rb