Radio, Web and Free Software

Changeset e67e28d59604c3c34a634ea37824b23bc828b268

Show
Ignore:
Timestamp:
07/28/10 11:43:16 (6 weeks ago)
Author:
Alban Peignier <alban.peignier@…>
Parents:
b71a93afaa069e73dee680b0a22e95f77a1cd660, 1b611f11cff8150feef05ffeef67461d875d87fc
git-committer:
Alban Peignier <alban.peignier@free.fr> / 2010-07-28T11:43:16Z+0200
Message:

Merge branch 'master' of www.dbx.tryphon.priv:/srv/git/boxcontrol

Files:
10 modified

Legend:

Unmodified
Added
Removed
  • app/views/save_points/_save_point_warning.fr.html.erb

    rb034d2a r1b611f1  
    11<p> 
    2   Si la configuration de votre LinkBox vous convient, vous pouvez  
     2  Si la configuration de votre Box vous convient, vous pouvez  
    33  la sauvegarder pour qu'elle soit utilisée au prochain redémarrage. 
    44</p> 
     
    66<p> 
    77  <strong>Attention</strong> : si vous sauvegardez une configuration 
    8   incorrecte, votre LinkBox pourrait ne pas redémarrer correctement ! 
     8  incorrecte, votre Box pourrait ne pas redémarrer correctement ! 
    99</p> 
  • app/views/save_points/_save_point_warning.html.erb

    rb034d2a r1b611f1  
    11<p> 
    2   If the settings of your LinkBox seem fine, you can save it 
     2  If the settings of your Box seem fine, you can save it 
    33  to use these settings at the next boot. 
    44</p> 
     
    66<p> 
    77  <strong>Warning</strong> : if you save a wrong configuration, 
    8   your LinkBox may not reboot correctly ! 
     8  your Box may not reboot correctly ! 
    99</p> 
  • config/locales/application_en.yml

    r9c57242 r79d3977  
    3737    new: 
    3838      submit: Save 
    39   or: or 
    40   actions: 
    41     edit: Edit 
  • config/locales/application_fr.yml

    r9c57242 r79d3977  
    3737    new: 
    3838      submit: Sauvegarder 
    39   or: ou 
    40   actions: 
    41     edit: Modifier 
  • lib/acts_as_ip_port.rb

    rd4a3873 rb71a93a  
    99    def acts_as_ip_port(*names) 
    1010      options = names.extract_options! 
     11       
     12      options = { :allow_blank => false }.update(options) 
    1113 
    1214      minimum_value, message =  
     
    2527        end 
    2628 
    27         validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message 
     29        validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message, :allow_blank => options[:allow_blank] 
    2830      end 
    2931    end 
  • lib/puppet_configurable.rb

    re5e4d56 r278d3c3  
    33  def self.included(base) 
    44    base.extend ClassMethods 
     5    base.class_eval do 
     6      alias_method_chain :update_attributes, :save 
     7    end 
    58  end 
    69 
     
    2124  end 
    2225 
     26  def update_attributes_with_save(attributes) 
     27    update_attributes_without_save attributes 
     28    save 
     29  end 
     30 
    2331  def save 
    2432    return false if respond_to?(:valid?) and not valid? 
     33    logger.debug "Save #{puppet_configuration_prefix} attributes: #{attributes.inspect}" if respond_to?(:logger) 
    2534    PuppetConfiguration.load.update_attributes(self.attributes, puppet_configuration_prefix).save 
    2635  end 
  • lib/puppet_configuration.rb

    r4b8aa76 ree2829e  
    4747    self 
    4848  end 
     49 
     50  def clear(prefix = "") 
     51    prefix = prefix.to_s 
     52    @attributes.each_key do |key| 
     53      @attributes.delete(key) if key.start_with?(prefix) 
     54    end 
     55    self 
     56  end 
    4957   
    5058  def normalize_prefix(prefix) 
     
    6674 
    6775  def self.load 
    68     self.new.tap(&:load) 
     76    unless pending_transaction? 
     77      self.new.tap(&:load) 
     78    else 
     79      Thread.current[:puppet_configuration] 
     80    end 
     81  end 
     82 
     83  def self.transaction(&block) 
     84    configuration = PuppetConfiguration.load 
     85    Thread.current[:puppet_configuration] = configuration 
     86    begin 
     87      yield configuration 
     88    ensure 
     89      Thread.current[:puppet_configuration] = nil 
     90    end 
     91    configuration.save 
     92  end 
     93 
     94  def self.pending_transaction? 
     95    not Thread.current[:puppet_configuration].nil? 
    6996  end 
    7097 
    7198  def save 
     99    return true if PuppetConfiguration.pending_transaction? 
     100 
     101    Rails.logger.debug "write puppet configuration into #{configuration_file}" 
    72102    File.open(configuration_file, "w") do |f| 
    73103      @attributes.each_pair do |key, value| 
     
    84114    false 
    85115  end 
     116   
     117  def self.destroy 
     118    File.delete(PuppetConfiguration.configuration_file) if File.exists?(PuppetConfiguration.configuration_file) 
     119  end 
    86120 
    87121end 
  • spec/lib/acts_as_ip_port_spec.rb

    rd4a3873 rb71a93a  
    1010    acts_as_ip_port :port 
    1111    acts_as_ip_port :user_port, :user_port => true 
     12    acts_as_ip_port :optionnal_port, :allow_blank => true 
    1213  end 
    1314 
     
    4142  end 
    4243 
     44  it "should not accept value blank value by default" do 
     45    @model.should_not allow_values_for(:port, "") 
     46  end 
     47 
     48  context "when allow_blank is true" do 
     49 
     50    it "should accept value blank value" do 
     51      @model.should allow_values_for(:optionnal_port, "") 
     52    end 
     53     
     54  end 
     55 
    4356  describe "user port" do 
    4457 
  • spec/lib/puppet_configurable_spec.rb

    re5e4d56 r89da180  
    55 
    66  class TestConfigurable 
     7    attr_accessor :attributes 
     8    alias_method :update_attributes, :attributes= 
     9 
    710    include PuppetConfigurable 
    8  
    9     attr_accessor :attributes 
    1011 
    1112    def initialize(attributes = {}) 
    1213      @attributes = attributes 
    1314    end 
    14  
    15     alias_method :update_attributes, :attributes= 
    1615  end 
    1716 
     
    8786  describe "class method load" do 
    8887     
    89     it "should create a new Network instance and load it" do 
     88    it "should create a new instance and load it" do 
    9089      TestConfigurable.should_receive(:new).and_return(@configurable) 
    9190      @configurable.should_receive(:load) 
     
    9594  end 
    9695 
     96  describe "update_attributes" do 
     97     
     98    it "should save the instance" do 
     99      @configurable.should_receive(:save) 
     100      @configurable.update_attributes(:dummy => true) 
     101    end 
     102 
     103  end 
     104 
    97105end 
  • spec/lib/puppet_configuration_spec.rb

    r4b8aa76 ree2829e  
    1414  def delete_configuration_file 
    1515    File.delete(PuppetConfiguration.configuration_file) if File.exists?(PuppetConfiguration.configuration_file) 
    16   end 
    17  
    18   it "should use tmp/config.pp as default configuration file" do 
    19     PuppetConfiguration.configuration_file.should == "tmp/config.pp" 
    2016  end 
    2117 
     
    8076      @puppet_configuration.save.should be_false 
    8177    end 
     78 
     79    it "should not store configuration if transaction is pending" do 
     80      PuppetConfiguration.stub!(:pending_transaction?).and_return(true) 
     81      File.should_not_receive(:open) 
     82      @puppet_configuration.save.should be_true 
     83    end 
    8284    
    8385  end 
     
    119121  end 
    120122 
     123  describe "clear" do 
     124     
     125    it "should remove keys with given prefix" do 
     126      @puppet_configuration[:prefix_key] = "value" 
     127      @puppet_configuration.clear(:prefix) 
     128      @puppet_configuration[:prefix_key].should be_nil 
     129    end 
     130 
     131    it "should keep keys with doesn't match the prefix" do 
     132      @puppet_configuration[:key] = "value" 
     133      @puppet_configuration.clear(:prefix) 
     134      @puppet_configuration[:key].should == "value" 
     135    end 
     136 
     137    it "should clear all keys without prefix" do 
     138      @puppet_configuration[:key] = "value" 
     139      @puppet_configuration.clear 
     140      @puppet_configuration.should be_empty 
     141    end 
     142 
     143    it "should return the PuppetConfiguration instance" do 
     144      @puppet_configuration.clear.should == @puppet_configuration 
     145    end 
     146 
     147  end 
     148 
     149  describe "transaction" do 
     150 
     151    it "should instance a single PuppetConfiguration" do 
     152      PuppetConfiguration.should_receive(:new).and_return(@puppet_configuration) 
     153      PuppetConfiguration.transaction do 
     154        3.times do  
     155          PuppetConfiguration.load.should == @puppet_configuration 
     156        end 
     157      end 
     158    end 
     159 
     160    it "should save once PuppetConfiguration after transaction" do 
     161      PuppetConfiguration.stub!(:new).and_return(@puppet_configuration) 
     162      @puppet_configuration.should_receive(:save) 
     163      PuppetConfiguration.transaction do 
     164      end 
     165    end 
     166     
     167  end 
     168 
    121169end