sferik-merb-admin 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/app/controllers/application.rb +1 -0
- data/app/controllers/main.rb +1 -0
- data/app/views/main/_belongs_to.html.erb +7 -5
- data/app/views/main/_has_one.html.erb +25 -0
- data/app/views/main/_properties.html.erb +17 -0
- data/app/views/main/edit.html.erb +4 -17
- data/app/views/main/new.html.erb +4 -17
- data/lib/abstract_model.rb +1 -1
- data/lib/datamapper_support.rb +8 -13
- data/lib/merb-admin.rb +1 -1
- data/spec/fixtures/division_fixture.rb +1 -1
- data/spec/fixtures/draft_fixture.rb +29 -0
- data/spec/fixtures/league_fixture.rb +1 -1
- data/spec/fixtures/player_fixture.rb +2 -1
- data/spec/fixtures/team_fixture.rb +3 -3
- data/spec/requests/main_spec.rb +133 -17
- data/spec/spec_helper.rb +2 -4
- metadata +5 -2
    
        data/README.markdown
    CHANGED
    
    | @@ -14,7 +14,7 @@ At the command prompt, type: | |
| 14 14 |  | 
| 15 15 | 
             
            In your app, add the following dependency to `config/dependencies.rb`:
         | 
| 16 16 |  | 
| 17 | 
            -
                dependency "sferik-merb-admin", "0.3. | 
| 17 | 
            +
                dependency "sferik-merb-admin", "0.3.2", :require_as => "merb-admin"
         | 
| 18 18 | 
             
                dependency "dm-is-paginated", "0.0.1" # if you want pagination support
         | 
| 19 19 |  | 
| 20 20 | 
             
            Add the following route to `config/router.rb`:
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -12,7 +12,7 @@ AUTHOR = "Erik Michaels-Ober" | |
| 12 12 | 
             
            EMAIL = "sferik@gmail.com"
         | 
| 13 13 | 
             
            HOMEPAGE = "http://twitter.com/sferik"
         | 
| 14 14 | 
             
            SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
         | 
| 15 | 
            -
            GEM_VERSION = "0.3. | 
| 15 | 
            +
            GEM_VERSION = "0.3.2"
         | 
| 16 16 |  | 
| 17 17 | 
             
            spec = Gem::Specification.new do |s|
         | 
| 18 18 | 
             
              s.rubyforge_project = "merb"
         | 
    
        data/app/controllers/main.rb
    CHANGED
    
    | @@ -2,6 +2,7 @@ require File.join( File.dirname(__FILE__), '..', '..', 'lib', 'abstract_model' ) | |
| 2 2 | 
             
            require File.join( File.dirname(__FILE__), '..', '..', 'lib', 'metaid' )
         | 
| 3 3 |  | 
| 4 4 | 
             
            class MerbAdmin::Main < MerbAdmin::Application
         | 
| 5 | 
            +
              include Merb::MerbAdmin::MainHelper
         | 
| 5 6 |  | 
| 6 7 | 
             
              before :find_models, :only => ['index']
         | 
| 7 8 | 
             
              before :find_model, :exclude => ['index']
         | 
| @@ -1,3 +1,10 @@ | |
| 1 | 
            +
            <%
         | 
| 2 | 
            +
            required = false
         | 
| 3 | 
            +
            @properties.each do |property|
         | 
| 4 | 
            +
              next unless property[:name] == association[:child_key].first
         | 
| 5 | 
            +
              required = true unless property[:nullable?]
         | 
| 6 | 
            +
            end
         | 
| 7 | 
            +
            %>
         | 
| 1 8 | 
             
                        <fieldset class="module aligned">
         | 
| 2 9 | 
             
                          <h2><%= association[:pretty_name].capitalize %></h2>
         | 
| 3 10 | 
             
                          <div class="<%= @object.errors[association[:child_key].first] ? "form-row errors" : "form-row"%>">
         | 
| @@ -11,11 +18,6 @@ | |
| 11 18 | 
             
                            <div>
         | 
| 12 19 | 
             
                              <%= select(association[:child_key].first, :collection => MerbAdmin::AbstractModel.new(association[:parent_model]).find_all.map{|o| [o.id, object_title(o)]}.sort_by{|o| o[1]}, :include_blank => true, :selected => @object.send(association[:child_key].first).to_s, :label => association[:pretty_name].capitalize) %>
         | 
| 13 20 | 
             
                              <p class="help">
         | 
| 14 | 
            -
                                <% required = false %>
         | 
| 15 | 
            -
                                <% @properties.each do |property| %>
         | 
| 16 | 
            -
                                <% next unless property[:name] == association[:child_key].first %>
         | 
| 17 | 
            -
                                <% required = true unless property[:nullable?] %>
         | 
| 18 | 
            -
                                <% end %>
         | 
| 19 21 | 
             
                                <%= required ? "Required." : "Optional." %>
         | 
| 20 22 | 
             
                              </p>
         | 
| 21 23 | 
             
                            </div>
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            <%
         | 
| 2 | 
            +
            required = false
         | 
| 3 | 
            +
            @properties.each do |property|
         | 
| 4 | 
            +
              next unless property[:name] == association[:child_key].first
         | 
| 5 | 
            +
              required = true unless property[:nullable?]
         | 
| 6 | 
            +
            end
         | 
| 7 | 
            +
            %>
         | 
| 8 | 
            +
                        <fieldset class="module aligned">
         | 
| 9 | 
            +
                          <h2><%= association[:pretty_name].capitalize %></h2>
         | 
| 10 | 
            +
                          <div class="<%= @object.errors[association[:child_key].first] ? "form-row errors" : "form-row"%>">
         | 
| 11 | 
            +
                            <% if @object.errors[association[:child_key].first] %>
         | 
| 12 | 
            +
                            <ul class="errorlist">
         | 
| 13 | 
            +
                              <% @object.errors[association[:child_key].first].each do |error| %>
         | 
| 14 | 
            +
                              <li><%= error %></li>
         | 
| 15 | 
            +
                              <% end %>
         | 
| 16 | 
            +
                            </ul>
         | 
| 17 | 
            +
                            <% end %>
         | 
| 18 | 
            +
                            <div>
         | 
| 19 | 
            +
                              <%= select(:name => "associations[#{association[:name]}][]", :id => association[:name], :collection => MerbAdmin::AbstractModel.new(association[:child_model]).find_all.map{|o| [o.id, object_title(o)]}.sort_by{|o| o[1]}, :include_blank => true, :selected => @object.send(association[:parent_key].first).to_s, :label => association[:pretty_name].capitalize) %>
         | 
| 20 | 
            +
                              <p class="help">
         | 
| 21 | 
            +
                                <%= required ? "Required." : "Optional." %>
         | 
| 22 | 
            +
                              </p>
         | 
| 23 | 
            +
                            </div>
         | 
| 24 | 
            +
                          </div>
         | 
| 25 | 
            +
                        </fieldset>
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
                        <fieldset class="module aligned">
         | 
| 2 | 
            +
                          <% belongs_to_keys = @abstract_model.belongs_to_associations.map{|b| b[:child_key].first} %>
         | 
| 3 | 
            +
                          <% properties.each do |property| %>
         | 
| 4 | 
            +
                          <% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property[:name]) %>
         | 
| 5 | 
            +
                          <% next if belongs_to_keys.include?(property[:name]) %>
         | 
| 6 | 
            +
                          <div class="<%= @object.errors[property[:name]] ? "form-row errors" : "form-row" %>">
         | 
| 7 | 
            +
                            <% if @object.errors[property[:name]] %>
         | 
| 8 | 
            +
                            <ul class="errorlist">
         | 
| 9 | 
            +
                              <% @object.errors[property[:name]].each do |error| %>
         | 
| 10 | 
            +
                              <li><%= error %></li>
         | 
| 11 | 
            +
                              <% end %>
         | 
| 12 | 
            +
                            </ul>
         | 
| 13 | 
            +
                            <% end %>
         | 
| 14 | 
            +
            <%= partial(property[:type].to_s, :property => property) -%>
         | 
| 15 | 
            +
                          </div>
         | 
| 16 | 
            +
                          <% end %>
         | 
| 17 | 
            +
                        </fieldset> 
         | 
| @@ -6,25 +6,12 @@ | |
| 6 6 | 
             
                    </ul>
         | 
| 7 7 | 
             
                    <%= form_for(@object, :action => slice_url(:admin_update, :model_name => @abstract_model.singular_name, :id => @object.id)) do %>
         | 
| 8 8 | 
             
                      <div>
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                          <% belongs_to_keys = @abstract_model.belongs_to_associations.map{|b| b[:child_key].first} %>
         | 
| 11 | 
            -
                          <% @properties.each do |property| %>
         | 
| 12 | 
            -
                          <% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property[:name]) %>
         | 
| 13 | 
            -
                          <% next if belongs_to_keys.include?(property[:name]) %>
         | 
| 14 | 
            -
                          <div class="<%= @object.errors[property[:name]] ? "form-row errors" : "form-row"%>">
         | 
| 15 | 
            -
                            <% if @object.errors[property[:name]] %>
         | 
| 16 | 
            -
                            <ul class="errorlist">
         | 
| 17 | 
            -
                              <% @object.errors[property[:name]].each do |error| %>
         | 
| 18 | 
            -
                              <li><%= error %></li>
         | 
| 19 | 
            -
                              <% end %>
         | 
| 20 | 
            -
                            </ul>
         | 
| 21 | 
            -
                            <% end %>
         | 
| 22 | 
            -
            <%= partial(property[:type].to_s, :property => property) -%>
         | 
| 23 | 
            -
                          </div>
         | 
| 24 | 
            -
                          <% end %>
         | 
| 25 | 
            -
                        </fieldset>
         | 
| 9 | 
            +
            <%= partial('properties', :properties => @properties) -%>
         | 
| 26 10 | 
             
                        <% @abstract_model.belongs_to_associations.each do |association| %>
         | 
| 27 11 | 
             
            <%= partial('belongs_to', :association => association) -%>
         | 
| 12 | 
            +
                        <% end %>
         | 
| 13 | 
            +
                        <% @abstract_model.has_one_associations.each do |association| %>
         | 
| 14 | 
            +
            <%= partial('has_one', :association => association) -%>
         | 
| 28 15 | 
             
                        <% end %>
         | 
| 29 16 | 
             
                        <% @abstract_model.has_many_associations.each do |association| %>
         | 
| 30 17 | 
             
            <%= partial('has_many', :association => association) -%>
         | 
    
        data/app/views/main/new.html.erb
    CHANGED
    
    | @@ -1,25 +1,12 @@ | |
| 1 1 | 
             
                    <div id="content-main">
         | 
| 2 2 | 
             
                    <%= form_for(@object, :action => slice_url(:admin_create, :model_name => @abstract_model.singular_name)) do %>
         | 
| 3 3 | 
             
                      <div>
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                          <% belongs_to_keys = @abstract_model.belongs_to_associations.map{|b| b[:child_key].first} %>
         | 
| 6 | 
            -
                          <% @properties.each do |property| %>
         | 
| 7 | 
            -
                          <% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property[:name]) %>
         | 
| 8 | 
            -
                          <% next if belongs_to_keys.include?(property[:name]) %>
         | 
| 9 | 
            -
                          <div class="<%= @object.errors[property[:name]] ? "form-row errors" : "form-row"%>">
         | 
| 10 | 
            -
                            <% if @object.errors[property[:name]] %>
         | 
| 11 | 
            -
                            <ul class="errorlist">
         | 
| 12 | 
            -
                              <% @object.errors[property[:name]].each do |error| %>
         | 
| 13 | 
            -
                              <li><%= error %></li>
         | 
| 14 | 
            -
                              <% end %>
         | 
| 15 | 
            -
                            </ul>
         | 
| 16 | 
            -
                            <% end %>
         | 
| 17 | 
            -
            <%= partial(property[:type].to_s, :property => property) -%>
         | 
| 18 | 
            -
                          </div>
         | 
| 19 | 
            -
                          <% end %>
         | 
| 20 | 
            -
                        </fieldset>
         | 
| 4 | 
            +
            <%= partial('properties', :properties => @properties) -%>
         | 
| 21 5 | 
             
                        <% @abstract_model.belongs_to_associations.each do |association| %>
         | 
| 22 6 | 
             
            <%= partial('belongs_to', :association => association) -%>
         | 
| 7 | 
            +
                        <% end %>
         | 
| 8 | 
            +
                        <% @abstract_model.has_one_associations.each do |association| %>
         | 
| 9 | 
            +
            <%= partial('has_one', :association => association) -%>
         | 
| 23 10 | 
             
                        <% end %>
         | 
| 24 11 | 
             
                        <% @abstract_model.has_many_associations.each do |association| %>
         | 
| 25 12 | 
             
            <%= partial('has_many', :association => association) -%>
         | 
    
        data/lib/abstract_model.rb
    CHANGED
    
    | @@ -15,7 +15,7 @@ module MerbAdmin | |
| 15 15 | 
             
                      model = lookup(m.to_s.to_sym)
         | 
| 16 16 | 
             
                      @models << new(model) if model
         | 
| 17 17 | 
             
                    end
         | 
| 18 | 
            -
                    @models.sort{|a, b| a.to_s <=> b.to_s}
         | 
| 18 | 
            +
                    @models.sort!{|a, b| a.model.to_s <=> b.model.to_s}
         | 
| 19 19 | 
             
                  else
         | 
| 20 20 | 
             
                    raise "MerbAdmin does not currently support the #{Merb.orm} ORM"
         | 
| 21 21 | 
             
                  end
         | 
    
        data/lib/datamapper_support.rb
    CHANGED
    
    | @@ -51,12 +51,6 @@ module MerbAdmin | |
| 51 51 | 
             
                    end
         | 
| 52 52 | 
             
                  end
         | 
| 53 53 |  | 
| 54 | 
            -
                  def association_names
         | 
| 55 | 
            -
                    associations.map do |association|
         | 
| 56 | 
            -
                      association[:type] == :belongs_to ? association[:parent_name] : association[:child_name]
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
                  end
         | 
| 59 | 
            -
             | 
| 60 54 | 
             
                  def properties
         | 
| 61 55 | 
             
                    model.properties.map do |property|
         | 
| 62 56 | 
             
                      {
         | 
| @@ -86,19 +80,20 @@ module MerbAdmin | |
| 86 80 |  | 
| 87 81 | 
             
                  def type_lookup(property)
         | 
| 88 82 | 
             
                    type = {
         | 
| 89 | 
            -
                       | 
| 83 | 
            +
                      BigDecimal => :big_decimal,
         | 
| 90 84 | 
             
                      DataMapper::Types::Boolean => :boolean,
         | 
| 91 | 
            -
                      DataMapper::Types:: | 
| 85 | 
            +
                      DataMapper::Types::ParanoidBoolean => :boolean,
         | 
| 92 86 | 
             
                      DataMapper::Types::ParanoidDateTime => :date_time,
         | 
| 93 | 
            -
                       | 
| 87 | 
            +
                      DataMapper::Types::Serial => :integer,
         | 
| 88 | 
            +
                      DataMapper::Types::Text => :text,
         | 
| 89 | 
            +
                      Date => :date,
         | 
| 90 | 
            +
                      DateTime => :date_time,
         | 
| 94 91 | 
             
                      Fixnum => :integer,
         | 
| 95 92 | 
             
                      Float => :float,
         | 
| 96 | 
            -
                       | 
| 97 | 
            -
                      TrueClass => :boolean,
         | 
| 93 | 
            +
                      Integer => :integer,
         | 
| 98 94 | 
             
                      String => :string,
         | 
| 99 | 
            -
                      DateTime => :date_time,
         | 
| 100 | 
            -
                      Date => :date,
         | 
| 101 95 | 
             
                      Time => :time,
         | 
| 96 | 
            +
                      TrueClass => :boolean,
         | 
| 102 97 | 
             
                    }
         | 
| 103 98 | 
             
                    type[property.type] || type[property.primitive]
         | 
| 104 99 | 
             
                  end
         | 
    
        data/lib/merb-admin.rb
    CHANGED
    
    | @@ -23,7 +23,7 @@ if defined?(Merb::Plugins) | |
| 23 23 |  | 
| 24 24 | 
             
                # Slice metadata
         | 
| 25 25 | 
             
                self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
         | 
| 26 | 
            -
                self.version = "0.3. | 
| 26 | 
            +
                self.version = "0.3.2"
         | 
| 27 27 | 
             
                self.author = "Erik Michaels-Ober"
         | 
| 28 28 |  | 
| 29 29 | 
             
                # Stub classes loaded hook - runs before LoadClasses BootLoader
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            class Draft
         | 
| 2 | 
            +
              include DataMapper::Resource
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              property :id, Serial
         | 
| 5 | 
            +
              property :created_at, DateTime
         | 
| 6 | 
            +
              property :updated_at, DateTime
         | 
| 7 | 
            +
              property :player_id, Integer, :nullable => false, :index => true
         | 
| 8 | 
            +
              property :team_id, Integer, :nullable => false, :index => true
         | 
| 9 | 
            +
              property :date, Date, :nullable => false
         | 
| 10 | 
            +
              property :round, Integer, :nullable => false
         | 
| 11 | 
            +
              property :pick, Integer, :nullable => false
         | 
| 12 | 
            +
              property :overall, Integer, :nullable => false
         | 
| 13 | 
            +
              property :college, String, :length => 100
         | 
| 14 | 
            +
              property :notes, Text
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              belongs_to :team
         | 
| 17 | 
            +
              belongs_to :player
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            Draft.fixture {{
         | 
| 21 | 
            +
              :player_id => /\d{1,5}/.gen,
         | 
| 22 | 
            +
              :team_id => /\d{1,5}/.gen,
         | 
| 23 | 
            +
              :date => Date.today,
         | 
| 24 | 
            +
              :round => /\d/.gen,
         | 
| 25 | 
            +
              :pick => /\d{1,2}/.gen,
         | 
| 26 | 
            +
              :overall => /\d{1,3}/.gen,
         | 
| 27 | 
            +
              :college => "#{/\w{5,10}/.gen.capitalize} University",
         | 
| 28 | 
            +
              :notes => /[:sentence:]/.gen,
         | 
| 29 | 
            +
            }}
         | 
| @@ -18,10 +18,11 @@ class Player | |
| 18 18 | 
             
              property :notes, Text
         | 
| 19 19 |  | 
| 20 20 | 
             
              belongs_to :team
         | 
| 21 | 
            +
              has 1, :draft
         | 
| 21 22 | 
             
            end
         | 
| 22 23 |  | 
| 23 24 | 
             
            Player.fixture {{
         | 
| 24 | 
            -
              :team_id => /\d{1, | 
| 25 | 
            +
              :team_id => /\d{1,5}/.gen,
         | 
| 25 26 | 
             
              :number => /\d{1,2}/.gen,
         | 
| 26 27 | 
             
              :name => "#{/\w{3,10}/.gen.capitalize} #{/\w{5,10}/.gen.capitalize}",
         | 
| 27 28 | 
             
              :position => Player.properties[:position].type.flag_map.values[rand(Player.properties[:position].type.flag_map.length)],
         | 
| @@ -14,7 +14,7 @@ class Team | |
| 14 14 | 
             
            end
         | 
| 15 15 |  | 
| 16 16 | 
             
            Team.fixture {{
         | 
| 17 | 
            -
              :league_id => /\d{1, | 
| 18 | 
            -
              :division_id => /\d{1, | 
| 19 | 
            -
              :name => /\w{5,10}/.gen.capitalize,
         | 
| 17 | 
            +
              :league_id => /\d{1,5}/.gen,
         | 
| 18 | 
            +
              :division_id => /\d{1,5}/.gen,
         | 
| 19 | 
            +
              :name => "The #{/\w{5,10}/.gen.pluralize.capitalize}",
         | 
| 20 20 | 
             
            }}
         | 
    
        data/spec/requests/main_spec.rb
    CHANGED
    
    | @@ -1,22 +1,54 @@ | |
| 1 1 | 
             
            require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
         | 
| 2 2 |  | 
| 3 | 
            -
            given " | 
| 3 | 
            +
            given "a player exists" do
         | 
| 4 4 | 
             
              @player = Player.gen
         | 
| 5 5 | 
             
            end
         | 
| 6 6 |  | 
| 7 7 | 
             
            given "two players exist" do
         | 
| 8 | 
            -
              @players =  | 
| 8 | 
            +
              @players = []
         | 
| 9 | 
            +
              2.times do
         | 
| 10 | 
            +
                @players << Player.gen
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            given "three teams exists" do
         | 
| 15 | 
            +
              @teams = []
         | 
| 16 | 
            +
              3.times do
         | 
| 17 | 
            +
                @teams << Team.gen
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            given "a player exists and three teams exist" do
         | 
| 22 | 
            +
              @player = Player.gen
         | 
| 23 | 
            +
              @teams = []
         | 
| 24 | 
            +
              3.times do
         | 
| 25 | 
            +
                @teams << Team.gen
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            given "a league exists and three teams exist" do
         | 
| 30 | 
            +
              @league = League.gen
         | 
| 31 | 
            +
              @teams = []
         | 
| 32 | 
            +
              3.times do
         | 
| 33 | 
            +
                @teams << Team.gen
         | 
| 34 | 
            +
              end
         | 
| 9 35 | 
             
            end
         | 
| 10 36 |  | 
| 11 37 | 
             
            given "twenty players exist" do
         | 
| 12 | 
            -
              @players =  | 
| 38 | 
            +
              @players = []
         | 
| 39 | 
            +
              20.times do
         | 
| 40 | 
            +
                @players << Player.gen
         | 
| 41 | 
            +
              end
         | 
| 13 42 | 
             
            end
         | 
| 14 43 |  | 
| 15 44 | 
             
            describe "MerbAdmin" do
         | 
| 16 45 |  | 
| 17 46 | 
             
              before(:each) do
         | 
| 18 47 | 
             
                mount_slice
         | 
| 48 | 
            +
                Division.all.destroy!
         | 
| 49 | 
            +
                League.all.destroy!
         | 
| 19 50 | 
             
                Player.all.destroy!
         | 
| 51 | 
            +
                Team.all.destroy!
         | 
| 20 52 | 
             
              end
         | 
| 21 53 |  | 
| 22 54 | 
             
              describe "dashboard" do
         | 
| @@ -31,6 +63,10 @@ describe "MerbAdmin" do | |
| 31 63 | 
             
                it "should contain \"Site administration\"" do
         | 
| 32 64 | 
             
                  @response.body.should contain("Site administration")
         | 
| 33 65 | 
             
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                it "should be ordered correctly" do
         | 
| 68 | 
            +
                  @response.body.should contain(/Division.*League.*Player.*Team/m)
         | 
| 69 | 
            +
                end
         | 
| 34 70 | 
             
              end
         | 
| 35 71 |  | 
| 36 72 | 
             
              describe "list" do
         | 
| @@ -58,11 +94,11 @@ describe "MerbAdmin" do | |
| 58 94 | 
             
                  @response.should be_successful
         | 
| 59 95 | 
             
                end
         | 
| 60 96 |  | 
| 61 | 
            -
                it "should contain  | 
| 97 | 
            +
                it "should contain correct results" do
         | 
| 62 98 | 
             
                  @response.body.should contain("Jackie Robinson")
         | 
| 63 99 | 
             
                end
         | 
| 64 100 |  | 
| 65 | 
            -
                it "should not contain  | 
| 101 | 
            +
                it "should not contain incorrect results" do
         | 
| 66 102 | 
             
                  @response.body.should_not contain("Sandy Koufax")
         | 
| 67 103 | 
             
                end
         | 
| 68 104 | 
             
              end
         | 
| @@ -110,15 +146,35 @@ describe "MerbAdmin" do | |
| 110 146 | 
             
                  @response.should be_successful
         | 
| 111 147 | 
             
                end
         | 
| 112 148 |  | 
| 113 | 
            -
                it "should contain  | 
| 149 | 
            +
                it "should contain correct results" do
         | 
| 114 150 | 
             
                  @response.body.should contain("Jackie Robinson")
         | 
| 115 151 | 
             
                end
         | 
| 116 152 |  | 
| 117 | 
            -
                it "should not contain  | 
| 153 | 
            +
                it "should not contain incorrect results" do
         | 
| 118 154 | 
             
                  @response.body.should_not contain("David Wright")
         | 
| 119 155 | 
             
                end
         | 
| 120 156 | 
             
              end
         | 
| 121 157 |  | 
| 158 | 
            +
              describe "list with enum filter" do
         | 
| 159 | 
            +
                before(:each) do
         | 
| 160 | 
            +
                  Player.gen(:name => "Jackie Robinson", :sex => :male)
         | 
| 161 | 
            +
                  Player.gen(:name => "Dottie Hinson", :sex => :female)
         | 
| 162 | 
            +
                  @response = request(url(:admin_list, :model_name => "player"), :params => {:filter => {:sex => :male}})
         | 
| 163 | 
            +
                end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                it "should respond sucessfully" do
         | 
| 166 | 
            +
                  @response.should be_successful
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                it "should contain correct results" do
         | 
| 170 | 
            +
                  @response.body.should contain("Jackie Robinson")
         | 
| 171 | 
            +
                end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                it "should not contain incorrect results" do
         | 
| 174 | 
            +
                  @response.body.should_not contain("Dottie Hinson")
         | 
| 175 | 
            +
                end
         | 
| 176 | 
            +
              end
         | 
| 177 | 
            +
             | 
| 122 178 | 
             
              describe "list with 2 objects", :given => "two players exist" do
         | 
| 123 179 | 
             
                before(:each) do
         | 
| 124 180 | 
             
                  MerbAdmin[:paginate] = true
         | 
| @@ -209,7 +265,18 @@ describe "MerbAdmin" do | |
| 209 265 | 
             
                end
         | 
| 210 266 | 
             
              end
         | 
| 211 267 |  | 
| 212 | 
            -
              describe " | 
| 268 | 
            +
              describe "new with has-many association", :given => "three teams exists" do
         | 
| 269 | 
            +
                before(:each) do
         | 
| 270 | 
            +
                  @response = request(url(:admin_new, :model_name => "player"))
         | 
| 271 | 
            +
                end
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                it "should respond sucessfully" do
         | 
| 274 | 
            +
                  @response.should be_successful
         | 
| 275 | 
            +
                end
         | 
| 276 | 
            +
              end
         | 
| 277 | 
            +
             | 
| 278 | 
            +
             | 
| 279 | 
            +
              describe "edit", :given => "a player exists" do
         | 
| 213 280 | 
             
                before(:each) do
         | 
| 214 281 | 
             
                  @response = request(url(:admin_edit, :model_name => "player", :id => @player.id))
         | 
| 215 282 | 
             
                end
         | 
| @@ -223,6 +290,17 @@ describe "MerbAdmin" do | |
| 223 290 | 
             
                end
         | 
| 224 291 | 
             
              end
         | 
| 225 292 |  | 
| 293 | 
            +
              describe "edit with has-many association", :given => "a player exists and three teams exist" do
         | 
| 294 | 
            +
                before(:each) do
         | 
| 295 | 
            +
                  @response = request(url(:admin_edit, :model_name => "player", :id => @player.id))
         | 
| 296 | 
            +
                end
         | 
| 297 | 
            +
             | 
| 298 | 
            +
                it "should respond sucessfully" do
         | 
| 299 | 
            +
                  @response.should be_successful
         | 
| 300 | 
            +
                end
         | 
| 301 | 
            +
              end
         | 
| 302 | 
            +
             | 
| 303 | 
            +
             | 
| 226 304 | 
             
              describe "edit with missing object" do
         | 
| 227 305 | 
             
                before(:each) do
         | 
| 228 306 | 
             
                  @response = request(url(:admin_edit, :model_name => "player", :id => 1))
         | 
| @@ -242,7 +320,7 @@ describe "MerbAdmin" do | |
| 242 320 | 
             
                  @response.should redirect_to(url(:admin_list, :model_name => "player"))
         | 
| 243 321 | 
             
                end
         | 
| 244 322 |  | 
| 245 | 
            -
                it "should create a new  | 
| 323 | 
            +
                it "should create a new object" do
         | 
| 246 324 | 
             
                  Player.first.should_not be_nil
         | 
| 247 325 | 
             
                end
         | 
| 248 326 | 
             
              end
         | 
| @@ -256,7 +334,7 @@ describe "MerbAdmin" do | |
| 256 334 | 
             
                  @response.should redirect_to(url(:admin_edit, :model_name => "player", :id => Player.first.id))
         | 
| 257 335 | 
             
                end
         | 
| 258 336 |  | 
| 259 | 
            -
                it "should create a new  | 
| 337 | 
            +
                it "should create a new object" do
         | 
| 260 338 | 
             
                  Player.first.should_not be_nil
         | 
| 261 339 | 
             
                end
         | 
| 262 340 | 
             
              end
         | 
| @@ -270,11 +348,30 @@ describe "MerbAdmin" do | |
| 270 348 | 
             
                  @response.should redirect_to(url(:admin_new, :model_name => "player"))
         | 
| 271 349 | 
             
                end
         | 
| 272 350 |  | 
| 273 | 
            -
                it "should create a new  | 
| 351 | 
            +
                it "should create a new object" do
         | 
| 274 352 | 
             
                  Player.first.should_not be_nil
         | 
| 275 353 | 
             
                end
         | 
| 276 354 | 
             
              end
         | 
| 277 355 |  | 
| 356 | 
            +
              describe "create with has-many association", :given => "three teams exists" do
         | 
| 357 | 
            +
                before(:each) do
         | 
| 358 | 
            +
                  @response = request(url(:admin_create, :model_name => "league"), :method => "post", :params => {:league => {:name => "National League"}, :associations => {:teams => [@teams[0].id, @teams[1].id]}})
         | 
| 359 | 
            +
                end
         | 
| 360 | 
            +
             | 
| 361 | 
            +
                it "should create a new object" do
         | 
| 362 | 
            +
                  League.first.should_not be_nil
         | 
| 363 | 
            +
                end
         | 
| 364 | 
            +
             | 
| 365 | 
            +
                it "should include correct associations" do
         | 
| 366 | 
            +
                  League.first.teams.should include(@teams[0])
         | 
| 367 | 
            +
                  League.first.teams.should include(@teams[1])
         | 
| 368 | 
            +
                end
         | 
| 369 | 
            +
             | 
| 370 | 
            +
                it "should not include incorrect associations" do
         | 
| 371 | 
            +
                  League.first.teams.should_not include(@teams[2])
         | 
| 372 | 
            +
                end
         | 
| 373 | 
            +
              end
         | 
| 374 | 
            +
             | 
| 278 375 | 
             
              describe "create with invalid object" do
         | 
| 279 376 | 
             
                before(:each) do
         | 
| 280 377 | 
             
                  @response = request(url(:admin_create, :model_name => "player"), :method => "post", :params => {:player => {}})
         | 
| @@ -285,7 +382,7 @@ describe "MerbAdmin" do | |
| 285 382 | 
             
                end
         | 
| 286 383 | 
             
              end
         | 
| 287 384 |  | 
| 288 | 
            -
              describe "update", :given => " | 
| 385 | 
            +
              describe "update", :given => "a player exists" do
         | 
| 289 386 | 
             
                before(:each) do
         | 
| 290 387 | 
             
                  @response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}})
         | 
| 291 388 | 
             
                end
         | 
| @@ -299,7 +396,7 @@ describe "MerbAdmin" do | |
| 299 396 | 
             
                end
         | 
| 300 397 | 
             
              end
         | 
| 301 398 |  | 
| 302 | 
            -
              describe "update and edit", :given => " | 
| 399 | 
            +
              describe "update and edit", :given => "a player exists" do
         | 
| 303 400 | 
             
                before(:each) do
         | 
| 304 401 | 
             
                  @response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_continue => true})
         | 
| 305 402 | 
             
                end
         | 
| @@ -313,7 +410,7 @@ describe "MerbAdmin" do | |
| 313 410 | 
             
                end
         | 
| 314 411 | 
             
              end
         | 
| 315 412 |  | 
| 316 | 
            -
              describe "update and add another", :given => " | 
| 413 | 
            +
              describe "update and add another", :given => "a player exists" do
         | 
| 317 414 | 
             
                before(:each) do
         | 
| 318 415 | 
             
                  @response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}, :_add_another => true})
         | 
| 319 416 | 
             
                end
         | 
| @@ -327,6 +424,25 @@ describe "MerbAdmin" do | |
| 327 424 | 
             
                end
         | 
| 328 425 | 
             
              end
         | 
| 329 426 |  | 
| 427 | 
            +
              describe "update with has-many association", :given => "a league exists and three teams exist" do
         | 
| 428 | 
            +
                before(:each) do
         | 
| 429 | 
            +
                  @response = request(url(:admin_update, :model_name => "league", :id => @league.id), :method => "put", :params => {:league => {:name => "National League"}, :associations => {:teams => [@teams[0].id, @teams[1].id]}})
         | 
| 430 | 
            +
                end
         | 
| 431 | 
            +
             | 
| 432 | 
            +
                it "should update an object that already exists" do
         | 
| 433 | 
            +
                  League.first(:id => @league.id).name.should eql("National League")
         | 
| 434 | 
            +
                end
         | 
| 435 | 
            +
             | 
| 436 | 
            +
                it "should include correct associations" do
         | 
| 437 | 
            +
                  League.first.teams.should include(@teams[0])
         | 
| 438 | 
            +
                  League.first.teams.should include(@teams[1])
         | 
| 439 | 
            +
                end
         | 
| 440 | 
            +
             | 
| 441 | 
            +
                it "should not include incorrect associations" do
         | 
| 442 | 
            +
                  League.first.teams.should_not include(@teams[2])
         | 
| 443 | 
            +
                end
         | 
| 444 | 
            +
              end
         | 
| 445 | 
            +
             | 
| 330 446 | 
             
              describe "update with missing object" do
         | 
| 331 447 | 
             
                before(:each) do
         | 
| 332 448 | 
             
                  @response = request(url(:admin_update, :model_name => "player", :id => 1), :method => "put", :params => {:player => {:name => "Jackie Robinson", :number => 42, :team_id => 1, :sex => :male}})
         | 
| @@ -337,7 +453,7 @@ describe "MerbAdmin" do | |
| 337 453 | 
             
                end
         | 
| 338 454 | 
             
              end
         | 
| 339 455 |  | 
| 340 | 
            -
              describe "update with invalid object", :given => " | 
| 456 | 
            +
              describe "update with invalid object", :given => "a player exists" do
         | 
| 341 457 | 
             
                before(:each) do
         | 
| 342 458 | 
             
                  @response = request(url(:admin_update, :model_name => "player", :id => @player.id), :method => "put", :params => {:player => {:number => "a"}})
         | 
| 343 459 | 
             
                end
         | 
| @@ -347,7 +463,7 @@ describe "MerbAdmin" do | |
| 347 463 | 
             
                end
         | 
| 348 464 | 
             
              end
         | 
| 349 465 |  | 
| 350 | 
            -
              describe "delete", :given => " | 
| 466 | 
            +
              describe "delete", :given => "a player exists" do
         | 
| 351 467 | 
             
                before(:each) do
         | 
| 352 468 | 
             
                  @response = request(url(:admin_delete, :model_name => "player", :id => @player.id))
         | 
| 353 469 | 
             
                end
         | 
| @@ -371,7 +487,7 @@ describe "MerbAdmin" do | |
| 371 487 | 
             
                end
         | 
| 372 488 | 
             
              end
         | 
| 373 489 |  | 
| 374 | 
            -
              describe "destroy", :given => " | 
| 490 | 
            +
              describe "destroy", :given => "a player exists" do
         | 
| 375 491 | 
             
                before(:each) do
         | 
| 376 492 | 
             
                  @response = request(url(:admin_destroy, :model_name => "player", :id => @player.id), :method => "delete")
         | 
| 377 493 | 
             
                end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -24,8 +24,7 @@ Merb.start_environment( | |
| 24 24 | 
             
              :session_store => 'memory'
         | 
| 25 25 | 
             
            )
         | 
| 26 26 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
            DataMapper.setup(:default, 'sqlite3:test.db')
         | 
| 27 | 
            +
            DataMapper.setup(:default, 'sqlite3::memory:') && DataMapper.auto_migrate!
         | 
| 29 28 |  | 
| 30 29 | 
             
            module Merb
         | 
| 31 30 | 
             
              module Test
         | 
| @@ -58,8 +57,7 @@ Merb::Test.add_helpers do | |
| 58 57 | 
             
              def mount_slice
         | 
| 59 58 | 
             
                if standalone?
         | 
| 60 59 | 
             
                  Merb::Router.reset!
         | 
| 61 | 
            -
                  Merb::Router.prepare | 
| 60 | 
            +
                  Merb::Router.prepare{add_slice(:MerbAdmin, :name_prefix => nil, :path_prefix => "admin", :default_routes => false)}
         | 
| 62 61 | 
             
                end
         | 
| 63 62 | 
             
              end
         | 
| 64 | 
            -
             | 
| 65 63 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: sferik-merb-admin
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Erik Michaels-Ober
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2009-08- | 
| 12 | 
            +
            date: 2009-08-31 00:00:00 -07:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -68,6 +68,7 @@ files: | |
| 68 68 | 
             
            - spec/controllers/main_spec.rb
         | 
| 69 69 | 
             
            - spec/fixtures
         | 
| 70 70 | 
             
            - spec/fixtures/division_fixture.rb
         | 
| 71 | 
            +
            - spec/fixtures/draft_fixture.rb
         | 
| 71 72 | 
             
            - spec/fixtures/league_fixture.rb
         | 
| 72 73 | 
             
            - spec/fixtures/player_fixture.rb
         | 
| 73 74 | 
             
            - spec/fixtures/team_fixture.rb
         | 
| @@ -95,7 +96,9 @@ files: | |
| 95 96 | 
             
            - app/views/main/_date_time.html.erb
         | 
| 96 97 | 
             
            - app/views/main/_float.html.erb
         | 
| 97 98 | 
             
            - app/views/main/_has_many.html.erb
         | 
| 99 | 
            +
            - app/views/main/_has_one.html.erb
         | 
| 98 100 | 
             
            - app/views/main/_integer.html.erb
         | 
| 101 | 
            +
            - app/views/main/_properties.html.erb
         | 
| 99 102 | 
             
            - app/views/main/_string.html.erb
         | 
| 100 103 | 
             
            - app/views/main/_text.html.erb
         | 
| 101 104 | 
             
            - app/views/main/_time.html.erb
         |